AgentBase
AgentBase is the central class in the SignalWire Server 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.
signing_key
SignalWire Signing Key (Dashboard → API Credentials). When set, webhook signature
validation is enforced on the POST /, /swaig, and /post_prompt endpoints, and
unsigned or invalidly-signed requests receive an HTTP 403. Falls back to the
SIGNALWIRE_SIGNING_KEY environment variable when not passed. When unset, the SDK
logs a one-time startup warning.
trust_proxy_for_signature
If True, honor the X-Forwarded-Proto / X-Forwarded-Host headers when
reconstructing the request URL during signature validation. Defaults to False
because proxy headers are spoofable; opt in only when you control the proxy chain.
swaig_secret
Secret used to sign this agent’s per-call SWAIG function tokens. Falls back to
the SIGNALWIRE_SWAIG_SECRET environment variable. When neither is set, a
random secret is generated per process, so tokens issued before a restart stop
verifying and callers mid-call see “the security token for this function is
invalid or expired” on their next tool call. Set it in production and whenever
more than one replica serves the same agent. Distinct from signing_key, which
validates inbound webhooks.
When signing_key is set, the POST /, /swaig, and /post_prompt endpoints are
signature-validated. The X-SignalWire-Signature request header carries the signature,
and X-Twilio-Signature is accepted as an alias for compatibility with legacy callers.
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).