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

from signalwire import AgentBase
from signalwire import FunctionResult
agent = AgentBase(name="my-agent", route="/agent")
agent.set_prompt_text("You are a helpful assistant.")
@agent.tool(name="enable_payment_functions", description="Enable payment tools")
def enable_payment_functions(args, raw_data):
return (
FunctionResult("Payment functions are now available.")
.toggle_functions([
{"function": "collect_payment", "active": True},
{"function": "refund_payment", "active": True},
{"function": "check_balance", "active": False}
])
)
agent.serve()