Agents

FunctionResult

View as MarkdownOpen in Claude

FunctionResult is the return type for all SWAIG tool functions. It wraps a response message (text for the AI to speak) and an ordered list of actions (transfers, SMS, data updates, context switches, and more). Every method returns self, so you can chain calls into a single fluent expression.

Returned from functions defined with the @tool() decorator or define_tool() on AgentBase.

FunctionResult builds the response payload for a SWAIG function. See the SWML SWAIG functions reference for the full response format specification.

Properties

response
strDefaults to ''

Text the AI speaks back to the caller after the function executes.

action
list[dict[str, Any]]Defaults to []

Ordered list of action objects to execute. Actions run sequentially in the order they were added.

post_process
boolDefaults to False

When True, the AI speaks the response and takes one more conversational turn with the user before executing actions. When False (default), actions execute immediately after the response.

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="transfer_to_billing", description="Transfer the caller to billing")
8def transfer_to_billing(args, raw_data):
9 return (
10 FunctionResult(
11 "I'll transfer you to billing. Anything else first?",
12 post_process=True
13 )
14 .update_global_data({"transferred": True})
15 .send_sms(
16 to_number="+15551234567",
17 from_number="+15559876543",
18 body="You are being transferred to billing."
19 )
20 .connect("+15551234567", final=True)
21 )
22
23agent.serve()

Fluent Chaining Pattern

Every method on FunctionResult returns self, so you build complex responses in a single expression. Actions execute in the order they are added.

Terminal actions like connect(final=True) and hangup() end the call flow. Place them last in the chain so that preceding actions (data updates, SMS, etc.) have a chance to execute.

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="transfer_call", description="Transfer the call")
8def transfer_call(args, raw_data):
9 # Data update + SMS execute before the terminal transfer
10 return (
11 FunctionResult("Transferring you now.")
12 .update_global_data({"transferred": True})
13 .send_sms(
14 to_number="+15551234567",
15 from_number="+15559876543",
16 body="Your call is being transferred."
17 )
18 .connect("+15551234567", final=True) # terminal — goes last
19 )
20
21agent.serve()

Methods

Core

Call Control

Speech

Media

Data

Context Navigation

Events

Functions

Hints

Settings

SMS

Payment

SIP

Rooms and Conferences

SWML and RPC