AgentBase
AgentBase is the central class in the SignalWire AI Agents SDK. It provides a
complete framework for building AI-powered voice agents, combining prompt management,
tool definitions, skill loading, speech configuration, and web serving into a single
composable interface.
Extends SWMLService and composes
functionality from nine mixins: PromptMixin, ToolMixin, SkillMixin, AIConfigMixin,
WebMixin, AuthMixin, ServerlessMixin, StateMixin, and MCPServerMixin.
All setter methods return self for fluent method chaining.
AgentBase generates a SWML document with the ai verb.
See the SWML reference for the full specification of all
supported parameters and behaviors.
Properties
name
The agent’s display name. Set at construction time. Used in logging, SIP username mapping, and the default prompt fallback.
route
HTTP route path where this agent is served. Used by
AgentServer when hosting
multiple agents on one process.
host
Network interface the web server binds to.
port
Port the web server listens on. Defaults to the PORT environment variable, falling
back to 3000.
agent_id
Unique identifier for this agent instance. Auto-generated as a UUID if not provided.
pom
The Prompt Object Model instance used for structured prompt building. None when
use_pom=False.
skill_manager
Manager instance for loading and unloading skills. Access via
add_skill() and
list_skills() rather
than directly.
PROMPT_SECTIONS
Class-level attribute. Subclasses can set this to declaratively define prompt sections
instead of calling prompt_add_section() in the constructor.
basic_auth
Explicit (username, password) for HTTP Basic Auth on all endpoints. If not set,
credentials are read from SWML_BASIC_AUTH_USER / SWML_BASIC_AUTH_PASSWORD env vars,
or auto-generated on startup.
use_pom
Enable Prompt Object Model for structured prompt building. Set to False to use
plain text prompts only.
token_expiry_secs
Expiration time in seconds for SWAIG function authentication tokens.
auto_answer
Automatically add an answer verb before the AI verb in the SWML document.
record_call
Enable call recording. When True, a record_call verb is added to the SWML document.
record_format
Recording file format. Common values: "mp4", "wav".
record_stereo
Record in stereo (separate channels for each party) when True.
default_webhook_url
Base URL for SWAIG function webhooks. If not set, the SDK auto-detects from the
incoming request or uses SWML_PROXY_URL_BASE.
suppress_logs
Suppress SDK log output. Useful in testing or when integrating with external logging.
enable_post_prompt_override
Allow dynamic per-request override of the post-prompt configuration.
check_for_input_override
Allow dynamic per-request override of input checking behavior.
config_file
Path to a JSON config file. If not provided, the SDK searches default paths.
See ConfigLoader.
native_functions
List of native SWAIG function names to enable at construction time (e.g.,
["check_time", "wait_for_user"]). Can also be set later via
set_native_functions().
schema_path
Path to a custom SWML schema file for validation. If not provided, the SDK searches default paths automatically.
schema_validation
Enable SWML schema validation. Disable with False or SWML_SKIP_SCHEMA_VALIDATION=1
env var.
Decorators
tool
The @tool decorator is the recommended way to define SWAIG functions. Use
@agent.tool() on a standalone function, or @AgentBase.tool() on a method
inside a subclass. Both forms accept the same parameters.
When parameters are not explicitly provided, the decorator automatically infers the JSON Schema from Python type hints on the function signature.
Parameters
name
Function name exposed to the AI. Defaults to the decorated function’s __name__.
description
What the function does. The AI reads this to decide when to call it. Defaults to the
function’s docstring, or "Function {name}" as a fallback.
parameters
Explicit JSON Schema for function parameters. If omitted, the schema is automatically inferred from Python type hints on the decorated function.
secure
Require token validation on tool calls.
fillers
Filler phrases by language code, spoken while the function runs.
webhook_url
External webhook URL. If set, SignalWire calls this URL instead of executing locally.
required
Required parameter names. Auto-inferred from type hints when not specified.
**swaig_fields
Additional SWAIG fields (e.g., wait_file, meta_data).
Examples
Instance decorator with type inference
With explicit parameters
Class decorator (subclass)
Typed parameters (auto-inferred schema)
Basic agent with a tool
Methods
Configure the answer verb that connects the call.
Add a remote function include to the SWAIG configuration.
Add a single speech recognition hint to improve transcription accuracy.
Add multiple speech recognition hints at once.
Add filler phrases for a specific native function and language.
Add a language configuration with voice settings for multilingual conversations.
Add an external MCP server for tool discovery and invocation.
Add a speech recognition hint with pattern matching and replacement.
Add a SWML verb to run after the AI conversation ends.
Add a SWML verb to run after the call is answered but before the AI starts.
Add a SWML verb to run before the call is answered.
Add a pronunciation rule to correct how the AI speaks a specific word or phrase.
Load and activate a skill on the agent.
Append query parameters to all SWAIG webhook URLs.
Get the agent’s endpoints as a FastAPI APIRouter for mounting in larger applications.
Automatically register SIP usernames derived from the agent’s name and route.
Remove all post-AI verbs from the call flow.
Remove all post-answer verbs from the call flow.
Remove all pre-answer verbs from the call flow.
Remove all SWAIG query parameters from the agent.
Define multi-step conversation contexts and workflows for complex agent interactions.
Programmatically define a SWAIG tool that the AI can invoke during conversations.
Override hook that returns the list of SWAIG tools available to the AI.
Enable real-time debug event webhooks from the AI module during calls.
Enable debug and testing routes on the agent’s HTTP server.
Expose the agent’s tools as an MCP server endpoint.
Enable SIP-based call routing for this agent.
Get the FastAPI application instance for use with deployment adapters.
Retrieve the agent’s Basic Auth credentials and their origin.
Get the full URL for this agent’s endpoint, including host, port, and route.
Get the agent’s display name.
Retrieve the current post-prompt text.
Retrieve the current prompt configured on the agent.
Check whether a specific skill is currently loaded on the agent.
List the names of all currently loaded skills on the agent.
Manually set the proxy URL base for webhook callbacks.
Enable built-in native functions that execute directly on the SignalWire platform.
Register a callback for debug events received at the /debug_events endpoint.
Override hook called when a SWAIG function is invoked during a conversation.
Handle post-prompt summaries generated after a conversation ends.
Override hook for customizing the SWML document on a per-request basis.
Add a new section to the agent’s structured prompt.
Add a subsection to an existing prompt section.
Append content to an existing prompt section or create it if it does not exist.
Check whether a named section exists in the agent’s prompt.
Register a callback for dynamic request routing based on SIP URIs or POST data.
Register a specific SIP username to route calls to this agent.
Register a raw SWAIG function dictionary, typically from a DataMap.
Unload a skill from the agent.
Smart entry point that auto-detects the runtime environment and starts the agent accordingly.
Start a FastAPI/uvicorn web server to serve this agent’s SWML and SWAIG endpoints.
Handle requests in serverless environments like AWS Lambda, Google Cloud Functions, and Azure Functions.
Set a callback for per-request dynamic agent configuration.
Set the complete list of remote function includes.
Merge data into the global data dictionary available to the AI throughout a conversation.
Set filler phrases for native SWAIG functions.
Replace all language configurations at once with a list of raw language dictionaries.
Set a single AI parameter by key.
Configure AI model parameters such as temperature, timeouts, and speech recognition settings.
Set the post-prompt used for generating call summaries after a conversation ends.
Set LLM parameters specifically for the post-prompt.
Override the default URL where post-prompt summaries are delivered.
Set LLM parameters specifically for the main prompt.
Set the prompt using a raw Prompt Object Model dictionary structure.
Set the agent’s system prompt as a raw text string.
Replace all pronunciation rules at once with a list of raw rule dictionaries.
Register signal handlers for graceful shutdown in containerized deployments.
Override the default webhook URL used for SWAIG function calls in the SWML document.
Update the global data dictionary with new values.
Validate HTTP Basic Auth credentials against the agent’s stored credentials.