This lesson builds Morgan, a friendly sales specialist who helps customers with PC building recommendations. Morgan is a simple AI-powered voice agent built with the SignalWire Agents SDK.
- Understanding Agent Architecture
- Creating a Basic Agent
- Configuring Agent Prompts
- Adding Voice and Language
- Running Your Agent
- Testing Your Agent
- Enabling SSL/HTTPS
- Summary
SignalWire Agents are Python classes that inherit from AgentBase. Every agent has:
Core Components:
- Name: A descriptive name for your agent
- Route: The HTTP endpoint where the agent listens (e.g.,
/,/sales) - Host/Port: Network configuration for the agent server
- Prompt: Instructions that define the agent's behavior
- Language/Voice: Text-to-speech configuration
Key Concepts:
- Agents handle voice conversations through the SignalWire platform
- Each agent exposes an HTTP endpoint that returns SWML (SignalWire Markup Language)
- The SWML document defines how the agent behaves during calls
This section creates the first agent: Morgan, a sales specialist for PC Builder Pro.
Create sales_agent.py and define an agent class that inherits from AgentBase:
#!/usr/bin/env python3
"""
Simple Sales Agent - Morgan
A friendly PC building sales specialist
"""
from signalwire import AgentBase
class SalesAgent(AgentBase):
def __init__(self):
super().__init__(
name="PC Builder Sales Agent - Morgan",
route="/",
host="0.0.0.0",
port=3000
)Constructor Parameters:
name: Identifies your agent in logs and debuggingroute: The URL path where the agent listens (use/for root)host: Network interface to bind to (0.0.0.0listens on all interfaces)port: TCP port for the HTTP server (default: 3000)
The Prompt Object Model (POM) provides a structured way to define agent behavior. Instead of one long prompt, you organize instructions into logical sections.
Add a prompt section that names Morgan and sets the character:
def __init__(self):
super().__init__(
name="PC Builder Sales Agent - Morgan",
route="/",
host="0.0.0.0",
port=3000
)
# Configure the agent's personality and role
self.prompt_add_section(
"AI Role",
body=(
"You are Morgan, a passionate PC building expert and sales specialist "
"at PC Builder Pro. You're known for your deep knowledge of components "
"and your ability to match customers with their perfect build. You get "
"excited about the latest hardware and love sharing that enthusiasm. "
"Always introduce yourself by name."
)
)Add a second section listing what Morgan specializes in:
# Add expertise section
self.prompt_add_section(
"Your Expertise",
body="Areas of specialization:",
bullets=[
"Custom PC builds for all budgets",
"Component compatibility and optimization",
"Performance recommendations",
"Price/performance analysis",
"Current market trends"
]
)Add the steps Morgan should follow during a sales call:
# Define the sales workflow
self.prompt_add_section(
"Your Tasks",
body="Complete sales process workflow with passion and expertise:",
bullets=[
"Greet customers warmly and introduce yourself",
"Understand their specific PC building requirements",
"Ask about budget, intended use, and preferences",
"Provide knowledgeable recommendations",
"Share your enthusiasm for PC building",
"Offer to explain technical details when helpful"
]
)Add a section that describes how Morgan should sound while speaking:
# Voice and tone instructions
self.prompt_add_section(
"Voice Instructions",
body=(
"Share your passion for PC building and get excited about "
"helping customers create their perfect system. Your enthusiasm "
"should be genuine and infectious."
)
)SignalWire supports multiple text-to-speech voices.
Configure Morgan's voice with add_language():
# Configure language and voice
self.add_language(
name="English",
code="en-US",
voice="rime.marsh" # A friendly, enthusiastic voice
)Available Voices:
rime.spore- Energetic and upbeatrime.marsh- Warm and friendlyrime.cove- Calm and professional- And many more...
Here's the complete sales_agent.py:
#!/usr/bin/env python3
"""
Simple Sales Agent - Morgan
A friendly PC building sales specialist
"""
from signalwire import AgentBase
class SalesAgent(AgentBase):
def __init__(self):
super().__init__(
name="PC Builder Sales Agent - Morgan",
route="/",
host="0.0.0.0",
port=3000
)
# Configure the agent's personality and role
self.prompt_add_section(
"AI Role",
body=(
"You are Morgan, a passionate PC building expert and sales specialist "
"at PC Builder Pro. You're known for your deep knowledge of components "
"and your ability to match customers with their perfect build. You get "
"excited about the latest hardware and love sharing that enthusiasm. "
"Always introduce yourself by name."
)
)
# Add expertise section
self.prompt_add_section(
"Your Expertise",
body="Areas of specialization:",
bullets=[
"Custom PC builds for all budgets",
"Component compatibility and optimization",
"Performance recommendations",
"Price/performance analysis",
"Current market trends"
]
)
# Define the sales workflow
self.prompt_add_section(
"Your Tasks",
body="Complete sales process workflow with passion and expertise:",
bullets=[
"Greet customers warmly and introduce yourself",
"Understand their specific PC building requirements",
"Ask about budget, intended use, and preferences",
"Provide knowledgeable recommendations",
"Share your enthusiasm for PC building",
"Offer to explain technical details when helpful"
]
)
# Voice and tone instructions
self.prompt_add_section(
"Voice Instructions",
body=(
"Share your passion for PC building and get excited about "
"helping customers create their perfect system. Your enthusiasm "
"should be genuine and infectious."
)
)
# Configure language and voice
self.add_language(
name="English",
code="en-US",
voice="rime.marsh" # A friendly, enthusiastic voice
)
def main():
"""Main function to run the agent"""
agent = SalesAgent()
print("Starting PC Builder Sales Agent - Morgan")
print("=" * 50)
print("Agent running at: http://localhost:3000/")
print("Press Ctrl+C to stop")
print("=" * 50)
try:
agent.run()
except KeyboardInterrupt:
print("\nShutting down agent...")
if __name__ == "__main__":
main()Run the script from the repository root:
# Make sure you're in the signalwire-python directory
cd /path/to/signalwire-python
# Run the agent
python tutorial/multi_agents/sales_agent.pyYou should see:
Starting PC Builder Sales Agent - Morgan
==================================================
Agent running at: http://localhost:3000/
Press Ctrl+C to stop
==================================================
Every request to the agent needs basic auth. Without SWML_BASIC_AUTH_USER and SWML_BASIC_AUTH_PASSWORD set, the SDK generates a password and keeps it out of the logs. Set both before running the agent, so you know what to pass to curl:
export SWML_BASIC_AUTH_USER=devuser
export SWML_BASIC_AUTH_PASSWORD=devpassword
python tutorial/multi_agents/sales_agent.pyRequest the SWML document directly with curl, while the agent is running:
# Get the SWML configuration
curl -u devuser:devpassword http://localhost:3000/
# With pretty printing
curl -u devuser:devpassword http://localhost:3000/ | python -m json.toolswaig-test builds the agent without starting a server, which is faster for quick checks:
# Install the SDK if not already done
pip install -e .
# Test the agent
swaig-test tutorial/multi_agents/sales_agent.py --dump-swmlThe agent returns a JSON document that SignalWire uses to control the call. answer picks up the call, and ai carries the prompt and the voice configuration:
{
"version": "1.0.0",
"sections": {
"main": [
{
"answer": {}
},
{
"ai": {
"prompt": {
"pom": [
{
"title": "AI Role",
"body": "You are Morgan..."
}
// ... other sections
]
},
"params": {},
"languages": [
{
"name": "English",
"code": "en-US",
"voice": "rime.marsh"
}
]
}
}
]
}
}For production deployments, you'll want to enable SSL/HTTPS:
Export the SSL variables in the shell, then run the agent:
# Set SSL environment variables
export SWML_SSL_ENABLED=true
export SWML_SSL_CERT_PATH=/path/to/your/certificate.pem
export SWML_SSL_KEY_PATH=/path/to/your/private-key.pem
export SWML_DOMAIN=yourdomain.com
# Run the agent with SSL
python tutorial/multi_agents/sales_agent.pySet the same variables inline, on the command that starts the agent:
SWML_SSL_ENABLED=true \
SWML_SSL_CERT_PATH=/path/to/cert.pem \
SWML_SSL_KEY_PATH=/path/to/key.pem \
SWML_DOMAIN=yourdomain.com \
python tutorial/multi_agents/sales_agent.pyFor testing, you can create a self-signed certificate:
# Generate a self-signed certificate
openssl req -x509 -newkey rsa:4096 -keyout key.pem -out cert.pem -days 365 -nodes \
-subj "/C=US/ST=State/L=City/O=Organization/CN=localhost"
# Run with the self-signed cert
SWML_SSL_ENABLED=true \
SWML_SSL_CERT_PATH=cert.pem \
SWML_SSL_KEY_PATH=key.pem \
python tutorial/multi_agents/sales_agent.pyNote: Self-signed certificates will show security warnings. Use proper certificates from a Certificate Authority (CA) for production.
This lesson built a working SignalWire agent. It covered:
Key Concepts:
- How to create an agent by inheriting from
AgentBase - Using the Prompt Object Model (POM) to structure agent behavior
- Configuring voice and language settings
- Running agents locally and with SSL/HTTPS
- Testing agents with curl and swaig-test
What's Next?
In the next lesson, you'll learn how to make Morgan smarter by adding a searchable knowledge base. This will allow the agent to look up product information, pricing, and technical specifications in real-time.
Before moving on, try these exercises:
- Change Morgan's Voice: Try different voices like
rime.sporeorrime.cove - Modify the Personality: Make Morgan more formal or casual
- Add New Sections: Add a section about return policies or warranties
- Change the Port: Run the agent on port 3001 instead of 3000
Common Issues:
- Port in use: Change the port in the constructor or kill the process using the port
- Import errors: Make sure you've installed the SDK with
pip install -e . - SSL errors: Check that your certificate and key paths are correct
Tutorial Overview | Next: Lesson 2 - Adding Intelligence with Knowledge Bases