Agent Base

View as Markdown

Reference

Complete API reference for all SignalWire Agents SDK classes, methods, CLI tools, and configuration options.

This chapter provides detailed reference documentation for the SignalWire Agents SDK.

Reference Overview

API Reference

  • AgentBase - Main agent class with all methods
  • SWMLService - Base service for SWML generation
  • SwaigFunctionResult - Function return values and actions
  • DataMap - Serverless REST API integration
  • SkillBase - Custom skill development
  • ContextBuilder - Multi-step workflows

CLI Tools

  • swaig-test - Test agents and functions locally
  • sw-search - Build and query search indexes
  • sw-agent-init - Create new agent projects

Configuration

  • Environment Variables - Runtime configuration
  • Config Files - YAML/JSON configuration
  • SWML Schema - Document structure reference

Quick Reference

Creating an Agent

1agent = AgentBase(name="my-agent", route="/agent")
2agent.add_language("English", "en-US", "rime.spore")
3agent.prompt_add_section("Role", "You are a helpful assistant.")
4agent.run()

Defining a Function

1@agent.tool(description="Search for information")
2def search(query: str) -> SwaigFunctionResult:
3 return SwaigFunctionResult(f"Found results for: {query}")

Returning Actions

1return SwaigFunctionResult("Transferring...").connect("+15551234567")
2return SwaigFunctionResult("Goodbye").hangup()
3return SwaigFunctionResult().update_global_data({"key": "value"})

Import Patterns

1# Main imports
2from signalwire_agents import AgentBase
3from signalwire_agents.core.function_result import SwaigFunctionResult
4from signalwire_agents.core.data_map import DataMap
5
6# Prefab agents
7from signalwire_agents.prefabs import (
8 InfoGathererAgent,
9 FAQBotAgent,
10 SurveyAgent,
11 ReceptionistAgent,
12 ConciergeAgent
13)
14
15# Context/workflow system
16from signalwire_agents.core.contexts import ContextBuilder
17
18# Skill development
19from signalwire_agents.core.skill_base import SkillBase

Chapter Contents

SectionDescription
AgentBase APIMain agent class reference
SWMLService APIBase service class reference
SWAIG Function APIFunction definition reference
SwaigFunctionResult APIReturn value and actions reference
DataMap APIServerless API integration reference
SkillBase APICustom skill development reference
ContextBuilder APIWorkflow system reference
swaig-test CLITesting tool reference
sw-search CLISearch tool reference
Environment VariablesEnvironment configuration
Config FilesFile-based configuration
SWML SchemaDocument structure reference

Class Definition

1from signalwire_agents import AgentBase
2
3class AgentBase(
4 AuthMixin,
5 WebMixin,
6 SWMLService,
7 PromptMixin,
8 ToolMixin,
9 SkillMixin,
10 AIConfigMixin,
11 ServerlessMixin,
12 StateMixin
13)

Constructor

1AgentBase(
2 name: str, # Agent name/identifier (required)
3 route: str = "/", # HTTP route path
4 host: str = "0.0.0.0", # Host to bind
5 port: int = 3000, # Port to bind
6 basic_auth: Optional[Tuple[str, str]] = None, # (username, password)
7 use_pom: bool = True, # Use POM for prompts
8 token_expiry_secs: int = 3600, # Token expiration time
9 auto_answer: bool = True, # Auto-answer calls
10 record_call: bool = False, # Enable recording
11 record_format: str = "mp4", # Recording format
12 record_stereo: bool = True, # Stereo recording
13 default_webhook_url: Optional[str] = None, # Default webhook URL
14 agent_id: Optional[str] = None, # Unique agent ID
15 native_functions: Optional[List[str]] = None, # Native function list
16 schema_path: Optional[str] = None, # SWML schema path
17 suppress_logs: bool = False, # Suppress structured logs
18 enable_post_prompt_override: bool = False, # Enable post-prompt override
19 check_for_input_override: bool = False, # Enable input override
20 config_file: Optional[str] = None # Path to config file
21)

Constructor Parameters

ParameterTypeDefaultDescription
namestrrequiredAgent identifier
routestr"/"HTTP endpoint path
hoststr"0.0.0.0"Bind address
portint3000Bind port
basic_authTuple[str, str]NoneAuth credentials
use_pomboolTrueUse POM prompts
token_expiry_secsint3600Token TTL
auto_answerboolTrueAuto-answer calls
record_callboolFalseRecord calls
record_formatstr"mp4"Recording format
record_stereoboolTrueStereo recording
native_functionsList[str]NoneNative functions

Prompt Methods

prompt_add_section

1def prompt_add_section(
2 self,
3 section: str, # Section title
4 body: str, # Section content
5 bullets: List[str] = None # Optional bullet points
6) -> 'AgentBase'

Add a section to the agent’s prompt.

prompt_add_text

1def prompt_add_text(
2 self,
3 text: str # Text to add
4) -> 'AgentBase'

Add raw text to the prompt.

get_prompt

1def get_prompt(self) -> Union[str, List[Dict]]

Get the complete prompt. Returns POM structure if use_pom=True, otherwise plain text.

Language and Voice Methods

add_language

1def add_language(
2 self,
3 name: str, # Language name (e.g., "English")
4 code: str, # Language code (e.g., "en-US")
5 voice: str, # Voice ID (e.g., "rime.spore")
6 speech_fillers: Optional[List[str]] = None, # Filler words
7 function_fillers: Optional[List[str]] = None, # Processing phrases
8 language_order: int = 0 # Priority order
9) -> 'AgentBase'

Add a supported language with voice configuration.

set_voice

1def set_voice(
2 self,
3 voice: str # Voice ID
4) -> 'AgentBase'

Set the default voice for the agent.

Tool Definition Methods

tool (decorator)

1@agent.tool(
2 name: str = None, # Function name (default: function name)
3 description: str = "", # Function description
4 secure: bool = False, # Require token authentication
5 fillers: List[str] = None, # Processing phrases
6 wait_file: str = None # Audio file URL for hold
7)
8def my_function(args...) -> SwaigFunctionResult:
9 ...

Decorator to register a SWAIG function.

define_tool

1def define_tool(
2 self,
3 name: str, # Function name
4 description: str, # Function description
5 handler: Callable, # Function handler
6 parameters: Dict[str, Any] = None, # Parameter schema
7 secure: bool = False, # Require authentication
8 fillers: List[str] = None, # Processing phrases
9 wait_file: str = None # Hold audio URL
10) -> 'AgentBase'

Programmatically define a SWAIG function.

Skill Methods

add_skill

1def add_skill(
2 self,
3 skill_name: str, # Skill identifier
4 params: Dict[str, Any] = None # Skill configuration
5) -> 'AgentBase'

Add a skill to the agent.

list_available_skills

1def list_available_skills(self) -> List[str]

List all available skills.

AI Configuration Methods

set_params

1def set_params(
2 self,
3 params: Dict[str, Any] # AI parameters
4) -> 'AgentBase'

Set AI model parameters (temperature, top_p, etc.).

add_hints

1def add_hints(
2 self,
3 hints: List[str] # Speech recognition hints
4) -> 'AgentBase'

Add speech recognition hints.

add_pronounce

1def add_pronounce(
2 self,
3 patterns: List[Dict[str, str]] # Pronunciation rules
4) -> 'AgentBase'

Add pronunciation rules.

State Methods

set_global_data

1def set_global_data(
2 self,
3 data: Dict[str, Any] # Data to store
4) -> 'AgentBase'

Set initial global data for the agent session.

URL Methods

get_full_url

1def get_full_url(
2 self,
3 include_auth: bool = False # Include credentials in URL
4) -> str

Get the full URL for the agent endpoint.

set_web_hook_url

1def set_web_hook_url(
2 self,
3 url: str # Webhook URL
4) -> 'AgentBase'

Override the default webhook URL.

set_post_prompt_url

1def set_post_prompt_url(
2 self,
3 url: str # Post-prompt URL
4) -> 'AgentBase'

Override the post-prompt summary URL.

Server Methods

run

1def run(
2 self,
3 host: str = None, # Override host
4 port: int = None # Override port
5) -> None

Start the development server.

get_app

1def get_app(self) -> FastAPI

Get the FastAPI application instance.

Serverless Methods

serverless_handler

1def serverless_handler(
2 self,
3 event: Dict[str, Any], # Lambda event
4 context: Any # Lambda context
5) -> Dict[str, Any]

Handle AWS Lambda invocations.

cloud_function_handler

1def cloud_function_handler(
2 self,
3 request # Flask request
4) -> Response

Handle Google Cloud Function invocations.

azure_function_handler

1def azure_function_handler(
2 self,
3 req # Azure HttpRequest
4) -> HttpResponse

Handle Azure Function invocations.

Callback Methods

on_summary

1def on_summary(
2 self,
3 summary: Optional[Dict[str, Any]], # Summary data
4 raw_data: Optional[Dict[str, Any]] = None # Raw POST data
5) -> None

Override to handle post-prompt summaries.

set_dynamic_config_callback

1def set_dynamic_config_callback(
2 self,
3 callback: Callable # Config callback
4) -> 'AgentBase'

Set a callback for dynamic configuration.

SIP Routing Methods

enable_sip_routing

1def enable_sip_routing(
2 self,
3 auto_map: bool = True, # Auto-map usernames
4 path: str = "/sip" # Routing endpoint path
5) -> 'AgentBase'

Enable SIP-based routing.

register_sip_username

1def register_sip_username(
2 self,
3 sip_username: str # SIP username
4) -> 'AgentBase'

Register a SIP username for routing.

Method Chaining

All setter methods return self for method chaining:

1from signalwire_agents import AgentBase
2from signalwire_agents.core.function_result import SwaigFunctionResult
3
4agent = (
5 AgentBase(name="assistant", route="/assistant")
6 .add_language("English", "en-US", "rime.spore")
7 .add_hints(["SignalWire", "SWML", "SWAIG"])
8 .set_params({"temperature": 0.7})
9 .set_global_data({"user_tier": "standard"})
10)
11
12@agent.tool(description="Get help")
13def get_help(topic: str) -> SwaigFunctionResult:
14 return SwaigFunctionResult(f"Help for {topic}")
15
16if __name__ == "__main__":
17 agent.run()

Class Attributes

AttributeTypeDescription
PROMPT_SECTIONSList[Dict]Declarative prompt sections
namestrAgent name
routestrHTTP route path
hoststrBind host
portintBind port
agent_idstrUnique agent identifier
pomPromptObjectPOM instance (if use_pom=True)
skill_managerSkillManagerSkill manager instance

See Also

TopicReference
Creating promptsPrompts & POM
Voice configurationVoice & Language
Function definitionsSWAIG Function API
Function resultsSwaigFunctionResult API
Multi-step workflowsContextBuilder API
Testing agentsswaig-test CLI

Common Usage Patterns

Minimal Production Setup

1agent = AgentBase(
2 name="support",
3 route="/support",
4 basic_auth=("user", "pass"), # Always use auth in production
5 record_call=True, # Enable for compliance
6 record_stereo=True # Separate channels for analysis
7)

High-Volume Configuration

1agent = AgentBase(
2 name="ivr",
3 route="/ivr",
4 suppress_logs=True, # Reduce logging overhead
5 token_expiry_secs=1800 # Shorter token lifetime
6)

Development Configuration

1agent = AgentBase(
2 name="dev-agent",
3 route="/",
4 host="127.0.0.1", # Localhost only
5 port=3000
6)
7# Test with: swaig-test agent.py --dump-swml