In this lesson, you'll learn how to create a simple AI-powered voice agent using the SignalWire Agents SDK. We'll build Morgan, a friendly sales specialist who can help customers with PC building recommendations.
SignalWire Agents are Python classes that inherit from AgentBase
. Every agent has:
Core Components:
/
, /sales
)Key Concepts:
Let's create our first agent. We'll build Morgan, a sales specialist for PC Builder Pro.
#!/usr/bin/env python3
"""
Simple Sales Agent - Morgan
A friendly PC building sales specialist
"""
from signalwire_agents 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.0
listens 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.
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."
)
)
SignalWire supports multiple text-to-speech voices. Let's configure Morgan's voice:
# 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 professionalHere's the complete sales_agent.py
:
#!/usr/bin/env python3
"""
Simple Sales Agent - Morgan
A friendly PC building sales specialist
"""
from signalwire_agents 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()
# Make sure you're in the signalwire-agents directory
cd /path/to/signalwire-agents
# Run the agent
python tutorial/sales_agent.py
You should see:
Starting PC Builder Sales Agent - Morgan
==================================================
Agent running at: http://localhost:3000/
Press Ctrl+C to stop
==================================================
# Get the SWML configuration
curl http://localhost:3000/
# With pretty printing
curl http://localhost:3000/ | python -m json.tool
# Install the SDK if not already done
pip install -e .
# Test the agent
swaig-test tutorial/sales_agent.py --dump-swml
The agent returns a JSON document that SignalWire uses to control the call:
{
"ai": {
"voice": "rime.marsh",
"language": {
"name": "English",
"code": "en-US",
"voice": "rime.marsh"
},
"prompt": {
"sections": [
{
"title": "AI Role",
"body": "You are Morgan..."
}
// ... other sections
]
}
}
}
For production deployments, you'll want to enable SSL/HTTPS:
# 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/sales_agent.py
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/sales_agent.py
For 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/sales_agent.py
Note: Self-signed certificates will show security warnings. Use proper certificates from a Certificate Authority (CA) for production.
Congratulations! You've created your first SignalWire agent. You've learned:
Key Concepts:
AgentBase
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:
rime.spore
or rime.cove
Common Issues:
pip install -e .
← Back to Tutorial Overview | Next: Lesson 2 - Adding Intelligence with Knowledge Bases →