This tutorial builds AI-powered voice agents with the SignalWire Agents SDK. It starts with a single sales agent and ends with a multi-agent system that searches a knowledge base and hands off calls between specialists.
This tutorial covers what you need to build a production-ready AI voice agent:
Core Concepts:
- Creating agents that inherit from
AgentBase - Using the Prompt Object Model (POM) for structured prompts
- Configuring voice personas and languages
- Running agents locally and with SSL/HTTPS
Advanced Features:
- Integrating searchable knowledge bases with vector search
- Building multi-agent systems with intelligent routing
- Implementing custom SWAIG (SignalWire AI Gateway) functions
- Managing agent-to-agent context sharing
- Deploying to production environments
Real-World Skills:
- Best practices for prompt engineering
- Error handling and debugging techniques
- Performance optimization strategies
- Security considerations
Before starting this tutorial, ensure you have:
Required:
- Python 3.10 or higher
- pip package manager
- Basic Python programming knowledge
- A text editor or IDE
Recommended:
- SignalWire account (for testing with real calls)
- Basic understanding of REST APIs
- Familiarity with async/await in Python
This tutorial is organized into progressive lessons, each building on the previous:
Learn the fundamentals by building a simple sales agent named Morgan. You'll understand:
- Basic agent structure and configuration
- Prompt engineering with POM
- Running agents locally and with SSL
Enhance your agent with searchable knowledge using vector search. You'll learn:
- Installing search dependencies
- Converting documents to searchable format
- Integrating knowledge bases into agents
Create a complete multi-agent system with routing and context sharing. You'll master:
- AgentServer for hosting multiple agents
- Dynamic configuration callbacks
- Agent-to-agent transfers with context preservation
This lesson covers advanced concepts for production deployment:
- Custom SWAIG functions
- Error handling strategies
- Production deployment patterns
- Performance optimization
Learn to add custom functionality and create sophisticated conversational flows:
- Creating custom skills
- State management
- Complex conversation patterns
- Integration with external services
Clone the repository and install the SDK in editable mode:
# Clone the repository (if not already done)
git clone https://github.com/signalwire/signalwire-python.git
cd signalwire-python
# Install the base SDK
pip install -e .
# Or install with search capabilities
pip install -e .[search]After completing Lesson 1, you can run your first agent:
# Run the simple sales agent
python tutorial/multi_agents/sales_agent.py
# The agent will be available at http://localhost:3000/The endpoint requires basic auth. Set SWML_BASIC_AUTH_USER and SWML_BASIC_AUTH_PASSWORD before starting the agent, so you know the credentials to pass to curl with -u:
curl -X POST http://localhost:3000/ \
-u devuser:devpassword \
-H "Content-Type: application/json" \
-d '{}'Common Commands:
# Install with search support
pip install -e .[search]
# Build a search index
sw-search ./docs --output knowledge.swsearch
# Test SWAIG functions locally
swaig-test agent.py --list-tools
swaig-test agent.py --exec tool_name --param value
# Run with SSL enabled
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 agent.pyEnvironment Variables:
| Variable | Description | Default |
|---|---|---|
SWML_SSL_ENABLED |
Enable HTTPS | false |
SWML_SSL_CERT_PATH |
Path to SSL certificate | None |
SWML_SSL_KEY_PATH |
Path to SSL private key | None |
SWML_DOMAIN |
Domain for SSL | None |
SWML_BASIC_AUTH_USER |
Basic auth username | Auto-generated |
SWML_BASIC_AUTH_PASSWORD |
Basic auth password | Auto-generated |
All code examples from this tutorial are available in this directory:
sales_agent.py- Basic sales agent (Lesson 1)sales_agent_with_search.py- Agent with knowledge base (Lesson 2)pc_builder.py- Complete multi-agent system (Lesson 3)sales_knowledge.md- Sales knowledge basesupport_knowledge.md- Support knowledge base
Common Issues:
-
Port already in use:
# Change the port in your agent configuration port=3001 # or any available port
-
Search module not found:
# Install with search support pip install -e .[search] -
PyTorch crashes with an "illegal instruction" error: first force PyTorch's most basic CPU kernels. If it still crashes, install a PyTorch build that supports your CPU, as the search troubleshooting guide describes:
ATEN_CPU_CAPABILITY=default sw-search tutorial/multi_agents/sales_knowledge.md --output sales_knowledge.swsearch
Resources:
Debugging Tips:
- Use
--verboseflag for detailed logging - Check agent logs for error messages
- Test SWAIG functions with
swaig-testbefore deployment - Use
curlto test SWML endpoints directly
Agent Development:
- Always inherit from
AgentBase - Use POM for structured prompts
- Handle errors gracefully with
SwaigFunctionResult - Test locally before deployment
- Use meaningful function and parameter names
Production Deployment:
- Enable SSL/HTTPS in production
- Use environment variables for configuration
- Implement proper logging
- Set up health checks
- Monitor agent performance
Security:
- Use strong authentication
- Validate all inputs
- Don't expose sensitive data in prompts
- Use HTTPS for all communications
- Regularly update dependencies
Start with Lesson 1: Creating Your First Agent.
This tutorial is part of the SignalWire Agents SDK. For the latest updates and more information, visit the official repository.