defineTool
Programmatically define a SWAIG function (tool) on a
SWMLService. The SWAIG tool registry was lifted from
AgentBase into SWMLService, so any service — including standalone SWAIG
hosts and sidecars that do not produce an AI block — can register and dispatch
tools.
Tool definitions map to SWML SWAIG function entries. See the SWML SWAIG functions reference for the full specification.
Parameters
opts
Tool definition object.
opts.name
Tool name. Must be unique within the service. The AI uses this name to invoke the function.
opts.description
Human-readable description of what the tool does.
opts.parameters
JSON Schema describing the tool’s parameters.
opts.handler
Callback invoked when the tool is called. 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.
Returns
SWMLService — Returns this for method chaining.