on_function_call
on_function_call
Called when the SignalWire platform invokes a SWAIG function on this agent. The default implementation looks up the function in the tool registry and executes it. Override this method in a subclass to intercept tool calls for logging, metrics, pre/post-processing, or custom dispatch logic.
Most agents do not need to override this method. The default implementation handles function lookup, argument validation, and execution automatically. Token verification occurs upstream in the HTTP handler before this method is called. Override only when you need cross-cutting behavior across all tool calls.
This method is the tool dispatch mechanism. If you override it without calling
super().on_function_call(name, args, raw_data), the registered tool handler will
not execute. Always call super() to preserve default dispatch behavior.
Parameters
name
The name of the SWAIG function being invoked.
args
Arguments passed by the AI, conforming to the function’s parameter schema.
raw_data
The complete raw POST data from the SWAIG request, including metadata such as
call_id, caller_id_number, and global_data.
Returns
FunctionResult or dict — The tool’s response. The default
implementation returns the result of executing the registered handler.