SignalWire AI Agents SDK Architecture
Overview
The SignalWire AI Agents SDK provides a Python framework for building, deploying, and managing AI agents as microservices. These agents are self-contained web applications that expose HTTP endpoints to interact with the SignalWire platform. The SDK simplifies the creation of custom AI agents by handling common functionality like HTTP routing, prompt management, and tool execution.
Core Components
Class Hierarchy
The SDK is built around a clear class hierarchy:
- SWMLService: The foundation class providing SWML document creation and HTTP service capabilities
- AgentBase: Extends SWMLService with AI agent-specific functionality
- Custom Agent Classes: User implementations like SimpleAgent
- Prefab Agents: Ready-to-use agent types for common scenarios
- AgentBase: Extends SWMLService with AI agent-specific functionality
Key Components
-
SWML Document Management
- Schema validation for SWML documents
- Dynamic SWML verb creation and validation
- Document rendering and serving
-
Prompt Object Model (POM)
- Structured format for defining AI prompts
- Section-based organization (Personality, Goal, Instructions, etc.)
- Programmatic prompt construction and manipulation
-
SWAIG Function Framework
- Tool definition and registration system
- Parameter validation using JSON schema
- Security tokens for function execution
- Handler registry for function execution
-
HTTP Routing
- FastAPI-based web service
- Endpoint routing for SWML, SWAIG, and other services
- Custom routing callbacks for dynamic endpoint handling
- SIP request routing for voice applications
- Basic authentication
-
State Management
- Session-based state tracking
- Persistence options (file system, memory)
- State lifecycle hooks (startup, hangup)
-
Prefab Agents
- Ready-to-use agent implementations
- Customizable configurations
- Extensible designs for common use cases
-
Skills System
- Modular skill architecture for extending agent capabilities
- Automatic skill discovery from directory structure
- Parameter-configurable skills for customization
- Dependency validation (packages and environment variables)
- Built-in skills (web_search, datetime, math)
DataMap Tools
The DataMap system provides a declarative approach to creating SWAIG tools that integrate with REST APIs without requiring custom webhook infrastructure. DataMap tools execute on SignalWire's server infrastructure, simplifying deployment and eliminating the need to expose webhook endpoints.
Architecture Overview
DataMap tools follow a pipeline execution model on the SignalWire server:
Core Components
-
Builder Pattern: Fluent interface for constructing data_map configurations
tool = (DataMap('function_name')
.description('Function purpose')
.parameter('param', 'string', 'Description', required=True)
.webhook('GET', 'https://api.example.com/endpoint')
.output(SwaigFunctionResult('Response template'))
) -
Processing Pipeline: Ordered execution with early termination
- Expressions: Pattern matching against arguments
- Webhooks: HTTP API calls with variable substitution
- Foreach: Array iteration for response processing
- Output: Final response generation using SwaigFunctionResult
-
Variable Expansion: Dynamic substitution using
${variable}
syntax- Function arguments:
${args.parameter_name}
- API responses:
${response.field.nested_field}
- Array elements:
${foreach.item_field}
- Global data:
${global_data.key}
- Metadata:
${meta_data.call_id}
- Function arguments:
Tool Types
The system supports different tool patterns:
-
API Integration Tools: Direct REST API calls
weather_tool = (DataMap('get_weather')
.webhook('GET', 'https://api.weather.com/v1/current?q=${location}')
.output(SwaigFunctionResult('Weather: ${response.current.condition}'))
) -
Expression-Based Tools: Pattern matching without API calls
control_tool = (DataMap('file_control')
.expression(r'start.*', SwaigFunctionResult().add_action('start', True))
.expression(r'stop.*', SwaigFunctionResult().add_action('stop', True))
) -
Array Processing Tools: Handle list responses
search_tool = (DataMap('search_docs')
.webhook('GET', 'https://api.docs.com/search')
.foreach('${response.results}')
.output(SwaigFunctionResult('Found: ${foreach.title}'))
)
Integration with Agent Architecture
DataMap tools integrate seamlessly with the existing agent architecture:
- Registration: DataMap tools are registered as SWAIG functions
- Execution: Tools run on SignalWire infrastructure, not agent servers
- Response: Results are returned to the agent as function responses
Configuration Architecture
DataMap configurations use a hierarchical structure:
{
"function": "tool_name",
"description": "Tool description",
"parameters": {
"type": "object",
"properties": {},
"required": []
},
"data_map": {
"expressions": [],
"webhooks": [],
"foreach": "path",
"output": {},
"error_keys": []
}
}
This structure separates:
- Function Metadata: Name, description, parameters
- Processing Logic: Expressions, webhooks, array handling
- Output Definition: Response templates and actions
Benefits and Trade-offs
Benefits:
- No webhook infrastructure required
- Simplified deployment model
- Built-in authentication and error handling
- Server-side execution (no agent load)
- Automatic variable expansion
Trade-offs:
- Limited to REST API patterns
- No complex processing logic