toggle_functions

View as MarkdownOpen in Claude

Enable or disable specific SWAIG functions at runtime. This lets you control which tools are available to the AI at different points in the conversation (e.g., enabling payment functions only after identity verification).

Parameters

function_toggles
list[dict[str, Any]]Required

List of toggle objects. Each object must contain:

  • "function" — name of the SWAIG function to toggle
  • "active"True to enable, False to disable

Returns

FunctionResult — self, for chaining.

Example

1from signalwire import AgentBase
2from signalwire import FunctionResult
3
4agent = AgentBase(name="my-agent", route="/agent")
5agent.set_prompt_text("You are a helpful assistant.")
6
7@agent.tool(name="enable_payment_functions", description="Enable payment tools")
8def enable_payment_functions(args, raw_data):
9 return (
10 FunctionResult("Payment functions are now available.")
11 .toggle_functions([
12 {"function": "collect_payment", "active": True},
13 {"function": "refund_payment", "active": True},
14 {"function": "check_balance", "active": False}
15 ])
16 )
17
18agent.serve()