Skip to content

Latest commit

 

History

History
266 lines (186 loc) · 7.26 KB

README.md

File metadata and controls

266 lines (186 loc) · 7.26 KB

SignalWire Agents SDK Tutorial

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.

Table of Contents

  1. What You'll Learn
  2. Prerequisites
  3. Tutorial Structure
  4. Getting Started
  5. Additional Resources

What You'll Learn

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

Prerequisites

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

Tutorial Structure

This tutorial is organized into progressive lessons, each building on the previous:

Lesson 1: Creating Your First Agent

Read Lesson 1

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

Lesson 2: Adding Intelligence with Knowledge Bases

Read Lesson 2

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

Lesson 3: Building Multi-Agent Systems

Read Lesson 3

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

Lesson 4: Advanced Features and Best Practices

Read Lesson 4

This lesson covers advanced concepts for production deployment:

  • Custom SWAIG functions
  • Error handling strategies
  • Production deployment patterns
  • Performance optimization

Lesson 5: Extending Your Agents

Read Lesson 5

Learn to add custom functionality and create sophisticated conversational flows:

  • Creating custom skills
  • State management
  • Complex conversation patterns
  • Integration with external services

Getting Started

Quick Installation

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]

Running Your First Agent

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/

Testing with SWML

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 '{}'

Additional Resources

Quick Reference

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.py

Environment 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

Code Examples

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 base
  • support_knowledge.md - Support knowledge base

Troubleshooting

Common Issues:

  1. Port already in use:

    # Change the port in your agent configuration
    port=3001  # or any available port
  2. Search module not found:

    # Install with search support
    pip install -e .[search]
  3. 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

Getting Help

Resources:

Debugging Tips:

  • Use --verbose flag for detailed logging
  • Check agent logs for error messages
  • Test SWAIG functions with swaig-test before deployment
  • Use curl to test SWML endpoints directly

Best Practices Checklist

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

Ready to Begin?

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.