FunctionResult
FunctionResult is the return type for all SWAIG tool functions. It wraps a response
(a prompt the AI reads, not text it speaks verbatim) 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.
Parameters
response
A prompt injected into the model’s context after the function executes. The
model reads it and decides what to say, so write it as an instruction in the
second person: "Tell the caller their order shipped Tuesday." rather than
"Your order shipped Tuesday.". A first-person script usually still works
because the model tends to repeat it, but it is interpreted, not spoken, and
can drift or be merged with other context.
post_process
Let the AI take one more turn before executing actions. Set it whenever the
caller must hear something before an action that ends or suspends the AI’s
turn: hold pauses speech detection, connect and transfer replace the
leg, and hangup ends the call.
tool_result
Factual outcome of the call, such as "status: on hold". When given, the
response takes the structured form described under
set_tool_response().
tool_prompt
Instruction for what the model should say next, in the second person. Pairs
with tool_result.
Properties
response
The prompt injected into the model’s context. Either a plain string or a
{"tool_result": ..., "tool_prompt": ...} object built by
set_tool_response().
action
Ordered list of action objects to execute. Actions run sequentially in the order they were added.
post_process
When True, the AI responds to the prompt and takes one more conversational
turn with the user before executing actions. When False (default), actions
execute immediately after the response.
Example
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.
Methods
Core
Set or replace the response prompt on a FunctionResult.
Split the response into a factual result and a speaking instruction.
Enable or disable post-processing on a FunctionResult.
Append a raw action to the FunctionResult action list.
Append multiple raw actions to the FunctionResult action list.
Serialize a FunctionResult to the SWAIG response format.
Call Control
Transfer or connect the call to another destination.
End the call immediately.
Put the call on hold, announce it first, and route where it resumes.
Transfer the call to a SWML endpoint with a return message.
Speech
Make the AI agent speak specific text immediately.
Control how the agent pauses and waits for user input.
Stop the agent execution immediately.
Media
Play an audio or video file in the background during a call.
Stop the currently playing background audio file.
Start recording the call in the background.
Stop an active background call recording.
Stream call audio to an external endpoint via WebSocket or RTP.
Stop an active media tap stream.
Data
Set or update key-value pairs in the global session data.
Remove one or more keys from the global session data.
Set function-scoped metadata on a FunctionResult.
Remove one or more keys from the current function’s metadata store.
Context Navigation
Transition to a different step within the current conversation context.
Switch to a different conversation context.
Perform an advanced context switch with prompt replacement and history control.
Events
Send a custom user event through SWML for real-time UI updates.
Inject text as simulated user speech input.
Functions
Enable or disable specific SWAIG functions at runtime.
Allow SWAIG function calls when a speaker timeout occurs.
Hints
Add speech recognition hints dynamically during a call.
Remove all dynamically added speech recognition hints.
Settings
Adjust the end-of-speech silence timeout for speech recognition.
Adjust the speech event timeout for noisy environments.
Update AI runtime settings dynamically during a call.
Send full data to the LLM for the current turn only.
Control how this function call appears in the AI’s conversation history.
SMS
Payment
Collect and process a credit card payment during a call.
Build a payment prompt object for use with pay().
Build a single action entry for a payment prompt.
Build a parameter entry for the pay() method.
SIP
Rooms and Conferences
Join a SignalWire Relay room for multi-party communication.
Join an ad-hoc audio conference with extensive configuration options.
SWML and RPC
Execute a raw SWML document as an action.
Execute a generic RPC method on a call.
Dial out to a phone number with a destination SWML URL via RPC.
Inject a message or global data into the AI agent running on another call.
Merge data into another call’s global_data without a conversation turn.
Release another call from hold via RPC.