For AI agents: a documentation index is available at the root level at /llms.txt and /llms-full.txt. Append /llms.txt to any URL for a page-level index, or .md for the markdown version of any page.
Log inSign up
Support
GuidesReference
GuidesReference
    • Core
      • Overview
    • Agents
      • Overview
      • AgentBase
      • AgentServer
      • BedrockAgent
      • CLI Tools
      • Configuration
      • ContextBuilder
      • DataMap
      • FunctionResult
      • Helper Functions
      • LiveWire
      • MCP Gateway
      • PomBuilder
      • Prefabs
      • Search
      • SkillBase
      • Skills
      • SWAIGFunction
        • execute
        • to_swaig
        • validate_args
      • SWMLBuilder
      • SWMLService
      • WebService
    • RELAY
      • Overview
      • Actions
      • Call
      • Constants
      • Events
      • Message
      • RelayClient
      • RelayError
    • REST Client
      • Overview
      • Addresses
      • Calling
      • Chat
      • Compat
      • Datasphere
      • Fabric
      • Imported Numbers
      • Logs
      • Lookup
      • MFA
      • Number Groups
      • Phone Numbers
      • Project
      • PubSub
      • Queues
      • Recordings
      • Registry
      • RestClient
      • Short Codes
      • SignalWireRestError
      • SIP Profile
      • Verified Callers
      • Video
LogoLogoSignalWire Docs
Log inSign up
Support
On this page
  • Parameters
  • Returns
  • Example
AgentsSWAIGFunction

execute

|View as Markdown|Open in Claude|
Was this page helpful?
Edit this page
Previous

to_swaig

Next
Built with

Execute the function with the given arguments. Calls the handler and normalizes the return value into a FunctionResult dictionary.

Parameters

args
dict[str, Any]Required

Parsed arguments for the function, matching the parameter schema.

raw_data
dict[str, Any]

Full raw request data including global_data, call_id, caller_id_number, meta_data, and ai_session_id.

Returns

dict[str, Any] — The function result as a dictionary (from FunctionResult.to_dict()). If the handler raises an exception, returns a generic error message rather than exposing internal details.

The handler can return a FunctionResult, a dict with a "response" key, or a plain string. All formats are normalized to a FunctionResult dictionary.

Example

1from signalwire import SWAIGFunction
2from signalwire import FunctionResult
3
4def handle_lookup(args, raw_data):
5 account_id = args.get("account_id", "")
6 return FunctionResult(f"Account {account_id} is active.")
7
8func = SWAIGFunction(
9 name="lookup_account",
10 handler=handle_lookup,
11 description="Look up account status",
12 parameters={
13 "type": "object",
14 "properties": {
15 "account_id": {"type": "string", "description": "Account ID"}
16 },
17 "required": ["account_id"]
18 }
19)
20
21result = func.execute({"account_id": "12345"}, raw_data={})
22print(result)
23# {"response": "Account 12345 is active."}