SwaigFunction wraps a function as a SWAIG (SignalWire AI Gateway) tool that the AI can invoke during a conversation. It manages the function’s name, description, parameter schema, security settings, and serialization to SWML.
In most cases you do not create SwaigFunction instances directly. The
defineTool() method
on AgentBase handles construction
internally. This class is documented for advanced use cases such as custom
registration via registerSwaigFunction().
For server-side API tools without a handler, see
DataMap. For building the
response returned from a handler, see
FunctionResult.
SwaigFunction serializes to a SWML SWAIG function definition. See the SWML SWAIG functions reference for the full specification.
Unique name used to register and invoke this tool.
The handler invoked when the AI calls this tool. Receives parsed
arguments and optional raw request data. Can return a FunctionResult,
a plain object, or a string. May be async.
Human-readable description shown to the AI so it knows when to call this tool.
JSON Schema properties object describing the tool’s parameters.
Whether the tool requires session token authentication.
Language-keyed filler phrases to speak while the tool executes
(e.g., { "en-US": ["Let me check on that..."] }).
URL of an audio file to play while the tool executes. Preferred over fillers.
Number of times to loop waitFile.
External webhook URL. When set, the tool call is forwarded to this URL instead of being handled locally.
List of required parameter names.
Additional fields to include in the SWAIG definition.
Whether the handler uses typed parameters.
The tool name.
The handler.
The tool description.
The parameter schema object.
Whether token authentication is required.
Filler phrases by language code.
URL of an audio file to play while the tool executes.
Number of times to loop waitFile.
External webhook URL for remotely handled tools.
List of required parameter names.
Additional SWAIG definition fields.
Whether the handler uses typed parameters.
true when webhookUrl is set, indicating the tool is handled externally.
Execute the tool with the given arguments.
Convert the tool to a SWAIG-compatible dictionary for SWML.
Validate arguments against the parameter JSON Schema.
In most cases, use defineTool() instead of constructing SwaigFunction directly: