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.
The SDK is built around a clear class hierarchy:
Document rendering and serving
Prompt Object Model (POM)
Programmatic prompt construction and manipulation
SWAIG Function Framework
Handler registry for function execution
HTTP Routing
Basic authentication
State Management
State lifecycle hooks (startup, hangup)
Prefab Agents
Extensible designs for common use cases
Skills System
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.
DataMap tools follow a pipeline execution model on the SignalWire server:
βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ
β Function Call β β Expression β β Webhook β β Response β
β (Arguments) βββββΆβ Processing βββββΆβ Execution βββββΆβ Generation β
βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ
β β β β
β β β β
ββββββΌβββββ ββββββΌβββββ ββββββΌβββββ ββββββΌβββββ
βVariable β βPattern β βHTTP β βTemplate β
βExpansionβ βMatching β βRequest β βRenderingβ
β β β β β β β β
βββββββββββ βββββββββββ βββββββββββ βββββββββββ
Builder Pattern: Fluent interface for constructing data_map configurations
python
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
Output: Final response generation using SwaigFunctionResult
Variable Expansion: Dynamic substitution using ${variable}
syntax
${args.parameter_name}
${response.field.nested_field}
${foreach.item_field}
${global_data.key}
${meta_data.call_id}
The system supports different tool patterns:
API Integration Tools: Direct REST API calls
python
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
python
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
python
search_tool = (DataMap('search_docs')
.webhook('GET', 'https://api.docs.com/search')
.foreach('${response.results}')
.output(SwaigFunctionResult('Found: ${foreach.title}'))
)
DataMap tools integrate seamlessly with the existing agent architecture:
βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ
β AgentBase β β SWAIG β β SignalWire β
β β β Function β β Server β
β .register_ βββββΆβ Registry βββββΆβ Execution β
β swaig_function β β β β Environment β
β β β data_map field β β β
βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ
β β β
β β β
ββββββΌβββββ ββββββΌβββββ ββββββΌβββββ
βDataMap β βFunction β βVariable β
βBuilder β βDefinitionβ βExpansionβ
β β β β β β
βββββββββββ βββββββββββ βββββββββββ
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:
Trade-offs:
When to Choose DataMap vs Skills vs Custom Tools:
The Skills System provides a modular architecture for extending agent capabilities through self-contained, reusable components. Skills are automatically discovered, validated, and can be configured with parameters.
The skills system follows a three-layer architecture:
βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ
β Agent Layer β β Management β β Skills Layer β
β β β Layer β β β
β AgentBase βββββΆβ SkillManager βββββΆβ SkillBase β
β .add_skill() β β .load_skill() β β .setup() β
β β β .unload_skill() β β .register_tools()β
βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ
β β β
β β β
ββββββΌβββββ ββββββΌβββββ ββββββΌβββββ
βRequest β βRegistry β βSkill β
βRouting β βDiscoveryβ βInstance β
β β β β β β
βββββββββββ βββββββββββ βββββββββββ
Lifecycle management (setup, cleanup)
SkillManager: Manages skill loading and lifecycle
Integration with agent prompt and tool systems
SkillRegistry: Automatic skill discovery system
βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ
β Discovery β β Loading β β Registration β
β β β β β β
β 1. Scan dirs βββββΆβ 1. Validate βββββΆβ 1. Add tools β
β 2. Import mods β β deps β β 2. Add prompts β
β 3. Find classes β β 2. Create β β 3. Add hints β
β 4. Register β β instance β β 4. Store ref β
β β β 3. Call setup() β β β
βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ
Skills support configurable parameters for customization:
# Default behavior
agent.add_skill("web_search")
# Custom configuration
agent.add_skill("web_search", {
"num_results": 3,
"delay": 0.5
})
Parameters are passed to the skill constructor and accessible via self.params
:
class WebSearchSkill(SkillBase):
def setup(self) -> bool:
self.num_results = self.params.get('num_results', 1)
self.delay = self.params.get('delay', 0)
# Configure behavior based on parameters
The system provides detailed error reporting for common issues:
Error messages are actionable and specific:
Failed to load skill 'web_search': Missing required environment variables: ['GOOGLE_SEARCH_API_KEY', 'GOOGLE_SEARCH_ENGINE_ID']
Skills integrate seamlessly with existing agent systems:
This architecture enables powerful one-liner integration while maintaining flexibility and extensibility.
The SDK implements a multi-layer security model:
SSL certificate configuration
Authentication
Configurable via environment variables or programmatically
Authorization
secure=True
option on tool definitions (default)
State Isolation
The SDK is designed to be highly extensible:
Custom Agents: Extend AgentBase to create specialized agents
python
class CustomAgent(AgentBase):
def __init__(self):
super().__init__(name="custom", route="/custom")
Tool Registration: Add new tools using the decorator pattern
python
@AgentBase.tool(
name="tool_name",
description="Tool description",
parameters={...},
secure=True
)
def my_tool(self, args, raw_data):
# Tool implementation
Prompt Customization: Add sections, hints, languages
python
agent.add_language(name="English", code="en-US", voice="elevenlabs.josh")
agent.add_hints(["SignalWire", "SWML", "SWAIG"])
State Management: Implement custom state persistence
python
class CustomStateManager(StateManager):
def get_state(self, call_id):
# Implementation
Request Handling: Override request handling methods
python
def on_swml_request(self, request_data):
# Custom request handling
Custom Prefabs: Create reusable agent patterns
python
class MyCustomPrefab(AgentBase):
def __init__(self, config_param1, config_param2, **kwargs):
super().__init__(**kwargs)
# Configure the agent based on parameters
self.prompt_add_section("Personality", body=f"Customized based on: {config_param1}")
Dynamic Configuration: Per-request agent configuration for flexible behavior ```python def configure_agent_dynamically(self, query_params, body_params, headers, agent): # Configure agent differently based on request data tier = query_params.get('tier', 'standard') agent.set_params({"end_of_speech_timeout": 300 if tier == 'premium' else 500})
self.set_dynamic_config_callback(self.configure_agent_dynamically) ```
# Configure skills with parameters agent.add_skill("web_search", { "num_results": 3, "delay": 0.5 }) ```
class MyCustomSkill(SkillBase): SKILL_NAME = "my_skill" SKILL_DESCRIPTION = "A custom skill" REQUIRED_PACKAGES = ["requests"] REQUIRED_ENV_VARS = ["API_KEY"]
def setup(self) -> bool:
# Initialize the skill
return True
def register_tools(self) -> None:
# Register tools with the agent
self.agent.define_tool(...)
```
The dynamic configuration system enables agents to adapt their behavior on a per-request basis by examining incoming HTTP request data. This architectural pattern supports complex use cases like multi-tenant applications, A/B testing, and personalization while maintaining a single agent deployment.
Dynamic configuration intercepts the SWML document generation process to apply request-specific configuration:
βββββββββββββββ ββββββββββββββββββββ βββββββββββββββββββββββ ββββββββββββββββ
β HTTP β β Dynamic Config β β EphemeralAgent β β SWML β
β Request βββββΆβ Callback βββββΆβ Config βββββΆβ Document β
βββββββββββββββ ββββββββββββββββββββ βββββββββββββββββββββββ ββββββββββββββββ
β β β β
β β β β
βββββΌβββββ ββββββΌββββββ βββββββΌβββββββ ββββββΌβββββ
βQuery β βRequest β βAgent β βRendered β
βParams β βData β βBuilder β βResponse β
βBody β βAnalysis β βMethods β β β
βHeaders β βLogic β βExecution β β β
ββββββββββ ββββββββββββ ββββββββββββββ βββββββββββ
EphemeralAgentConfig
object using familiar AgentBase methodsβββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Dynamic Configuration Request Flow β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β β
β 1. HTTP Request arrives (GET/POST /) β
β β β
β 2. Extract request data β β
β ββββββββββββββββββββββΌβββββββββββββββββββββ β
β β β’ Query Parameters (URL params) β β
β β β’ Body Parameters (POST JSON) β β
β β β’ Headers (HTTP headers) β β
β ββββββββββββββββββββββ¬βββββββββββββββββββββ β
β β β
β 3. Check for callback β β
β ββββββββββββββββββββββΌβββββββββββββββββββββ β
β β if dynamic_config_callback is set: β β
β β - Create EphemeralAgentConfig β β
β β - Call callback with request data β β
β β - Apply ephemeral configuration β β
β β else: β β
β β - Use static agent configuration β β
β ββββββββββββββββββββββ¬βββββββββββββββββββββ β
β β β
β 4. Generate SWML β β
β ββββββββββββββββββββββΌβββββββββββββββββββββ β
β β β’ Render AI verb with configuration β β
β β β’ Include languages, params, prompts β β
β β β’ Apply hints and global data β β
β β β’ Generate function URLs with tokens β β
β ββββββββββββββββββββββ¬βββββββββββββββββββββ β
β β β
β 5. Return SWML Document β β
β ββββββββββββββββββββββΌβββββββββββββββββββββ β
β β β’ Complete SWML with customizations β β
β β β’ Ready for SignalWire platform β β
β βββββββββββββββββββββββββββββββββββββββββββ β
β β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
The EphemeralAgentConfig
object provides the same familiar methods as AgentBase
but applies them temporarily for a single request:
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β EphemeralAgentConfig Structure β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β β
β βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ β
β β Prompt Sections β β Language Config β β AI Parameters β β
β β βββββββββββββββ β β βββββββββββββββ β β βββββββββββββββ β β
β β β’ add_section() β β β’ add_language()β β β’ set_params() β β
β β β’ set_prompt() β β β’ voice config β β β’ timeouts β β
β β β’ post_prompt β β β’ fillers β β β’ volumes β β
β βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ β
β β
β βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ β
β β Global Data β β Hints & Speech β β Functions β β
β β βββββββββββββββ β β βββββββββββββββ β β βββββββββββββββ β β
β β β’ set_global() β β β’ add_hints() β β β’ native_funcs()β β
β β β’ update_data() β β β’ pronunciation β β β’ recognition β β
β β β’ session data β β β’ recognition β β β’ external URLs β β
β βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ β
β β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
The dynamic configuration system is designed with performance in mind:
Request 1 βββββββββββββββ Request 2 βββββββββββββββ Request 3 βββββββββββββββ
Lifecycle β CREATE β Lifecycle β CREATE β Lifecycle β CREATE β
β EphemeralCfgβ β EphemeralCfgβ β EphemeralCfgβ
β β β β β β β β β
β CONFIGURE β β CONFIGURE β β CONFIGURE β
β β β β β β β β β
β RENDER SWML β β RENDER SWML β β RENDER SWML β
β β β β β β β β β
β DESTROY β β DESTROY β β DESTROY β
βββββββββββββββ βββββββββββββββ βββββββββββββββ
β β β
βΌ βΌ βΌ
Garbage Garbage Garbage
Collection Collection Collection
The dynamic configuration architecture supports several key patterns:
βββββββββββββββ ββββββββββββββββ βββββββββββββββ β Tenant B β β Same Agent β β Config B β β Request βββββΆβ Instance βββββΆβ Applied β βββββββββββββββ ββββββββββββββββ βββββββββββββββ ```
βββββββββββββββ ββββββββββββββββ βββββββββββββββ β Test β β Decision β β Version B β β Group βββββΆβ Logic βββββΆβ Config β βββββββββββββββ ββββββββββββββββ βββββββββββββββ ```
βββββββββββββββ ββββββββββββββββ βββββββββββββββ β MX Request β β Locale β β Spanish β β (es-MX) βββββΆβ Detection βββββΆβ Voice + MXN β βββββββββββββββ ββββββββββββββββ βββββββββββββββ ```
Dynamic configuration integrates with other SDK components:
The system includes robust error handling:
def configure_agent_dynamically(self, query_params, body_params, headers, agent):
try:
# Primary configuration logic
self.apply_custom_config(query_params, agent)
except ConfigurationError as e:
# Log error and apply safe defaults
self.log.error("dynamic_config_error", error=str(e))
self.apply_default_config(agent)
except Exception as e:
# Catch-all with minimal safe configuration
self.log.error("dynamic_config_critical", error=str(e))
agent.add_language("English", "en-US", "rime.spore:mistv2")
The architecture supports gradual migration from static to dynamic configuration:
This approach ensures zero downtime and allows for testing and validation at each phase.
The SDK includes a collection of prefab agents that provide ready-to-use implementations for common use cases. These prefabs can be used directly or serve as templates for custom implementations.
Use cases: Form filling, survey collection, intake processes
FAQBotAgent
Use cases: FAQ bots, documentation assistants, support agents
ConciergeAgent
Use cases: Front-desk services, triage systems, switchboard operators
SurveyAgent
Use cases: Customer satisfaction surveys, feedback collection, market research
ReceptionistAgent
Users can create their own prefab agents by extending AgentBase
or any existing prefab. Custom prefabs can be created within your project or packaged as reusable libraries.
Key steps for creating custom prefabs:
Extend the base class:
python
class MyCustomPrefab(AgentBase):
def __init__(self, custom_param, **kwargs):
super().__init__(**kwargs)
self._custom_param = custom_param
Configure defaults: ```python # Set standard prompt sections self.prompt_add_section("Personality", body="I am a specialized agent for...") self.prompt_add_section("Goal", body="Help users with...")
# Add default tools self.register_default_tools() ```
Add specialized tools:
python
@AgentBase.tool(
name="specialized_function",
description="Do something specialized",
parameters={...}
)
def specialized_function(self, args, raw_data):
# Implementation
return SwaigFunctionResult("Function result")
Create a factory method (optional):
python
@classmethod
def create(cls, config_dict, **kwargs):
"""Create an instance from a configuration dictionary"""
return cls(
custom_param=config_dict.get("custom_param", "default"),
name=config_dict.get("name", "custom_prefab"),
**kwargs
)
When designing prefabs, consider exposing these customization points:
The POM (Prompt Object Model) represents a structured approach to prompt construction:
βββββββββββββββββββββββββββββββββββββββββββββββββ
β Prompt β
βββββββββββββββββββββββββββββββββββββββββββββββββ€
β βββββββββββββββββββ βββββββββββββββββββββββ β
β β Personality β β Goal β β
β βββββββββββββββββββ βββββββββββββββββββββββ β
β βββββββββββββββββββ βββββββββββββββββββββββ β
β β Instructions β β Hints β β
β βββββββββββββββββββ βββββββββββββββββββββββ β
β βββββββββββββββββββ βββββββββββββββββββββββ β
β β Languages β β Custom Sections β β
β βββββββββββββββββββ βββββββββββββββββββββββ β
βββββββββββββββββββββββββββββββββββββββββββββββββ
The Contexts and Steps system provides an alternative to traditional POM prompts for building structured, workflow-driven AI interactions. This system represents a fundamental shift from unstructured conversation to guided workflow execution.
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β ContextBuilder β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββ β
β β Context A β β Context B β β Context C β β
β β βββββββββββββββ β β βββββββββββββββ β β βββββββββββ β β
β β β Step 1 β β β β Step 1 β β β β Step 1 β β β
β β β - Content β β β β - Content β β β β - Contentβ β β
β β β - Criteria β β β β - Criteria β β β β - Criteriaβ β β
β β β - Functions β β β β - Functions β β β β - Functionsβ β β
β β β - Navigationβ β β β - Navigationβ β β β - Navigationβ β β
β β βββββββββββββββ β β βββββββββββββββ β β βββββββββββ β β
β β βββββββββββββββ β β βββββββββββββββ β β β β β
β β β Step 2 β β β β Step 2 β β β β β β
β β βββββββββββββββ β β βββββββββββββββ β β β β β
β βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββ β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
The system implements sophisticated navigation control through two primary mechanisms:
Intra-Context Navigation (Steps within a Context):
Context: Customer Service
ββββββββββββββ valid_steps ββββββββββββββββ valid_steps ββββββββββββββββ
β greeting β βββββββββββββββββΆ β identify β βββββββββββββββββΆ β resolve β
ββββββββββββββ ββββββββββββββββ ββββββββββββββββ
β β β
β valid_steps = ["identify"] β valid_steps = ["resolve", "escalate"] β
βββββββββββββββββββββββββββββββββ β
β
ββββββββββββββββ ββββββββββββββββββββββ
β escalate β valid_steps = ["escalate"]
ββββββββββββββββ
Inter-Context Navigation (Switching between Contexts):
βββββββββββββββββββ valid_contexts βββββββββββββββββββ valid_contexts βββββββββββββββββββ
β Triage β ββββββββββββββββββΆ β Technical β ββββββββββββββββββΆ β Billing β
β β β Support β β β
βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ
β β β
β valid_contexts = ["technical", "billing", "general"] β β
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β
βββββββββββββββββββ ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β General β valid_contexts = ["triage"]
β Inquiries β
βββββββββββββββββββ
Each step can restrict available AI functions to enhance security and user experience:
βββββββββββββββββββββββββββββββββββββββββββββββββββ
β Function Access Control by Step β
βββββββββββββββββββββββββββββββββββββββββββββββββββ€
β β
β Public Context β
β βββββββββββββββββββ β
β β Initial Contact β Functions: ["datetime"] β
β βββββββββββββββββββ β
β β
β Authenticated Context β
β βββββββββββββββββββ β
β β User Verified β Functions: ["datetime", β
β βββββββββββββββββββ "web_search"] β
β β
β Sensitive Context β
β βββββββββββββββββββ β
β β Account Access β Functions: "none" β
β βββββββββββββββββββ β
βββββββββββββββββββββββββββββββββββββββββββββββββββ
The contexts system integrates with the existing SWML generation pipeline:
βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ
β ContextBuilder β ββββΆ β Context Data β ββββΆ β SWML AI Verb β
β β β Serialization β β Generation β
βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ
β β β
β β βΌ
β β βββββββββββββββββββ
β β β prompt: { β
β β β contexts: { β
β β β "context1": β
β β β steps: {} β
β β β } β
β β β } β
β β βββββββββββββββββββ
β β
βΌ βΌ
βββββββββββββββββββ βββββββββββββββββββ
β Step Content β β Navigation β
β - Text/POM β β - valid_steps β
β - Functions β β - valid_contextsβ
β - Criteria β β - Restrictions β
βββββββββββββββββββ βββββββββββββββββββ
Coexistence with Traditional Prompts:
βββββββββββββββββββββββββββββββββββββββββββββββββββ
β Agent Configuration β
βββββββββββββββββββββββββββββββββββββββββββββββββββ€
β βββββββββββββββββββ βββββββββββββββββββββββ β
β β Traditional β β Contexts and β β
β β POM Sections β β Steps Workflow β β
β β (from skills, β β β β
β β global config) β β β β
β βββββββββββββββββββ βββββββββββββββββββββββ β
β β β β
β βββββββββββββ¬ββββββββββββ β
β βΌ β
β βββββββββββββββββββ β
β β Combined SWML β β
β β Output β β
β βββββββββββββββββββ β
βββββββββββββββββββββββββββββββββββββββββββββββββββ
Skills and Function Integration:
Context Validation Rules:
Step Content Rules:
set_text()
with add_section()
in same stepNavigation Validation:
valid_steps
must exist in same contextvalid_contexts
must exist in agentFunction Security:
set_functions()
allows all functionsMemory Usage:
Execution Flow:
Scalability:
Use Contexts and Steps when:
Use DataMap when:
Use Skills when:
Use Custom Tools when:
The architecture supports using all these approaches together, allowing developers to choose the right tool for each specific requirement within a single agent.
Functions are defined with: - Name - Description - Parameters schema - Implementation - Security settings
Example:
@AgentBase.tool(
name="get_weather",
description="Get the current weather for a location",
parameters={
"location": {
"type": "string",
"description": "The city or location to get weather for"
}
}
)
def get_weather(self, args, raw_data):
location = args.get("location", "Unknown location")
return SwaigFunctionResult(f"It's sunny and 72Β°F in {location}.")
The SDK uses FastAPI for routing with these key endpoints:
The SDK also supports dynamic creation of custom routing endpoints:
/customer
, /product
)The SDK supports multiple deployment models:
Direct invocation via agent.run()
(auto-detects deployment mode)
Multi-Agent Mode
app.include_router(agent.as_router(), prefix=agent.route)
Reverse Proxy Integration
SWML_PROXY_URL_BASE
for proper webhook URL generationEnable SSL termination at proxy level
Direct HTTPS Mode
agent.serve(ssl_cert="cert.pem", ssl_key="key.pem")
Use specific instructions for behavior guidance
SWAIG Functions
Return structured responses
State Management
enable_state_tracking=True
Use secure state storage for sensitive data
Security
Enable security for sensitive operations with secure=True
Deployment
Monitor agent performance and usage
Prefab Usage
The SDK uses JSON Schema validation for: - SWML document structure - POM section validation - SWAIG function parameter validation
Schema definitions are loaded from the schema.json
file, which provides the complete specification for all supported SWML verbs and structures.
The SDK uses structlog for structured logging with JSON output format. Key events logged include: - Service initialization - Request handling - Function execution - Authentication events - Error conditions
Configuration options are available through: 1. Constructor Parameters: Direct configuration in code 2. Environment Variables: System-level configuration 3. Method Calls: Runtime configuration updates
Key environment variables:
- SWML_BASIC_AUTH_USER
: Username for basic auth
- SWML_BASIC_AUTH_PASSWORD
: Password for basic auth
- SWML_PROXY_URL_BASE
: Base URL when behind reverse proxy
- SWML_SSL_ENABLED
: Enable HTTPS
- SWML_SSL_CERT_PATH
: Path to SSL certificate
- SWML_SSL_KEY_PATH
: Path to SSL key
- SWML_DOMAIN
: Domain name for the service
- SWML_SCHEMA_PATH
: Optional path to override the schema.json location
on_swml_request()
is called to allow customizationon_summary()
is called to process the dataThe SDK provides a flexible state management system:
βββββββββββββββββ βββββββββββββββββββ βββββββββββββββββ
β Session β β State β β Persistence β
β Management ββββββΆβ Manager ββββββΆβ Layer β
βββββββββββββββββ βββββββββββββββββββ βββββββββββββββββ
Components: - SessionManager: Handles session creation, activation, and termination - StateManager: Interface for state operations - Implementation Options: FileStateManager, MemoryStateManager, etc.
State is indexed by call ID and can store arbitrary JSON data. When enable_state_tracking=True
is set, the system automatically registers lifecycle hooks:
- startup_hook: Called when a new call/session starts
- hangup_hook: Called when a call/session ends
Common state management methods:
- get_state(call_id)
: Retrieve state for a call
- update_state(call_id, data)
: Update state for a call
- set_state(call_id, data)
: Set state for a call (overriding existing)
- clear_state(call_id)
: Remove state for a call