defineTool
Programmatically define a SWAIG function (tool) that the AI can invoke during a conversation.
Tool definitions map to SWML SWAIG function entries. See the SWML SWAIG functions reference for the full specification.
For cleaner typed handler signatures with automatic parameter inference, consider
using defineTypedTool()
instead.
Parameters
opts
Tool definition object.
opts.name
Tool name. Must be unique within the agent. The AI uses this name to invoke the function.
opts.description
Human-readable description of what the tool does. The AI reads this to decide when to call the tool.
opts.parameters
JSON Schema describing the tool’s parameters. The AI generates arguments conforming to this schema.
opts.handler
Callback invoked when the AI calls this tool. Receives
(args: Record<string, unknown>, rawData: Record<string, unknown>) and should
return a FunctionResult.
opts.secure
Whether to require token validation on tool calls.
opts.fillers
Language-specific filler phrases spoken while the tool executes.
Format: { 'en-US': ['Looking that up...', 'One moment...'] }.
opts.waitFile
URL of an audio file to play while the tool executes.
opts.waitFileLoops
Number of times to loop the wait file.
opts.required
List of required parameter names from the JSON Schema.
Returns
AgentBase — Returns this for method chaining.