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.