SwaigFunction
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.
Constructor
SwaigFunctionOptions
name
Unique name used to register and invoke this tool.
handler
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.
description
Human-readable description shown to the AI so it knows when to call this tool.
parameters
JSON Schema properties object describing the tool’s parameters.
secure
Whether the tool requires session token authentication.
fillers
Language-keyed filler phrases to speak while the tool executes
(e.g., { "en-US": ["Let me check on that..."] }).
waitFile
URL of an audio file to play while the tool executes. Preferred over fillers.
waitFileLoops
Number of times to loop waitFile.
webhookUrl
External webhook URL. When set, the tool call is forwarded to this URL instead of being handled locally.
required
List of required parameter names.
extraFields
Additional fields to include in the SWAIG definition.
isTypedHandler
Whether the handler uses typed parameters.
SwaigHandler type
Properties
name
The tool name.
handler
The handler.
description
The tool description.
parameters
The parameter schema object.
secure
Whether token authentication is required.
fillers
Filler phrases by language code.
waitFile
URL of an audio file to play while the tool executes.
waitFileLoops
Number of times to loop waitFile.
webhookUrl
External webhook URL for remotely handled tools.
required
List of required parameter names.
extraFields
Additional SWAIG definition fields.
isTypedHandler
Whether the handler uses typed parameters.
isExternal
true when webhookUrl is set, indicating the tool is handled externally.
Methods
Execute the tool with the given arguments.
Convert the tool to a SWAIG-compatible dictionary for SWML.
Examples
Manual registration
Using defineTool (preferred)
In most cases, use defineTool() instead of constructing SwaigFunction directly: