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.
AgentBase uses composition internally, assembling functionality from
PromptManager, SwmlBuilder, SessionManager, ContextBuilder, and SkillManager.
All setter methods return this 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.
Constructor
Constructor Parameters
name
Display name of the agent. 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 HTTP server binds to.
port
Port the HTTP server listens on. Defaults to the PORT environment variable,
falling back to 3000.
basicAuth
Explicit [username, password] tuple 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.
usePom
Enable Prompt Object Model for structured prompt building. Set to false to use
plain text prompts only.
tokenExpirySecs
Expiration time in seconds for SWAIG function authentication tokens.
autoAnswer
Automatically add an answer verb before the AI verb in the SWML document.
recordCall
Enable call recording. When true, a record_call verb is added to the SWML document.
recordFormat
Recording file format. Common values: "mp4", "wav".
recordStereo
Record in stereo (separate channels for each party) when true.
defaultWebhookUrl
Base URL for SWAIG function webhooks. If not set, the SDK auto-detects from the
incoming request or uses SWML_PROXY_URL_BASE.
nativeFunctions
List of native SWAIG function names to enable at construction time (e.g.,
["check_time", "wait_for_user"]). Can also be set later via
setNativeFunctions().
agentId
Unique identifier for this agent instance. Auto-generated as a random hex string if not provided.
suppressLogs
Suppress SDK log output. Useful in testing or when integrating with external logging.
Properties
name
The agent’s display name. Set at construction time.
route
HTTP route path where this agent is served.
host
Network interface the HTTP server binds to.
port
Port the HTTP server listens on.
agentId
Unique identifier for this agent instance.
Static Members
PROMPT_SECTIONS
Class-level attribute. Subclasses can set this to declaratively define prompt sections
instead of calling promptAddSection() in the constructor.
Examples
Basic agent with a tool
Subclass with declarative prompt sections
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 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 Hono app for mounting as a sub-router.
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.
Define multi-step conversation contexts and workflows.
Define a SWAIG tool that the AI can invoke during conversations.
Define a tool with a typed handler and automatic schema inference.
Override hook that registers tools during construction.
Enable real-time debug event webhooks from the AI module during calls.
Expose the agent’s tools as an MCP server endpoint.
Enable SIP-based call routing for this agent.
Extract a SIP username from a request body (static method).
Get the Hono application instance.
Retrieve the agent’s Basic Auth credentials and their origin.
Get the full URL for this agent’s endpoint.
Get the list of configured MCP servers.
Get the agent’s display name.
Retrieve the current post-prompt text.
Retrieve the current rendered prompt text.
Get summaries of all registered tools.
Look up a registered tool by name.
Handle an MCP JSON-RPC 2.0 request.
Check whether a specific skill is currently loaded.
Check if the MCP server endpoint is enabled.
List all currently loaded skills.
Manually set the proxy URL base for webhook callbacks.
Set the list of native platform functions.
Lifecycle hook for debug events received at /debug_events.
Pre-execution hook called before each SWAIG function invocation.
Handle post-prompt summaries generated after a conversation ends.
Lifecycle hook called on every SWML request before rendering.
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.
Check whether a named section exists in the agent’s prompt.
Register a SIP username to route calls to this agent.
Register a raw SWAIG function descriptor, typically from a DataMap.
Unload a skill from the agent.
Render the complete SWML document.
Start the HTTP server (alias for serve).
Start the Hono HTTP server to serve SWML and SWAIG endpoints.
Set a callback for per-request dynamic agent configuration.
Replace the global data object available to the AI.
Replace all language configurations at once.
Set a single AI parameter by key.
Configure AI model parameters such as temperature and timeouts.
Set the post-prompt for generating call summaries.
Set LLM parameters for the post-prompt.
Override the URL where post-prompt summaries are delivered.
Set LLM parameters for the main prompt.
Set the agent’s system prompt as raw text.
Register signal handlers for graceful shutdown (static method).
Override the default webhook URL for SWAIG function calls.
Merge data into the global data object.
Custom basic-auth validation hook.