Results Actions
Results & Actions
SwaigFunctionResult is the return type for all SWAIG functions. It contains response text for the AI to speak and optional actions like transfers, SMS, or context changes.
Basic Results
Return a simple response:
SwaigFunctionResult Components
Method Chaining
SwaigFunctionResult methods return self for chaining:
Call Transfer
Transfer to another number:
Transfer options:
SIP REFER transfer:
Use SIP REFER for attended transfers:
SWML-specific transfer:
Transfer with AI response for context handoff:
Send SMS
Send a text message during the call:
SMS with media:
Payment Processing
Process credit card payments during the call:
Payment with custom prompts:
Call Recording
Start and stop call recording:
Record with auto-stop:
Audio Tapping
Tap audio to external endpoint for monitoring or transcription. Supports WebSocket (wss://) or RTP (rtp://) URIs:
WebSocket tap:
RTP tap:
Call Control
Hold:
Put caller on hold:
Hang Up
End the call:
Speech Control
Direct speech with .say():
Make the AI speak specific text immediately:
Stop AI from speaking:
Wait for user input:
Pause and wait for the user to speak:
Simulate user input:
Inject text as if the user spoke it:
Background Audio
Play audio files in the background during conversation:
Update Global Data
Store data accessible throughout the call:
Remove global data:
Metadata Management
Store function-specific metadata (separate from global data):
Remove metadata:
Context Switching
Advanced context switch:
Change the agent’s prompt/context with new system and user prompts:
SWML context switch:
Switch to a named SWML context:
SWML step change:
Change to a specific workflow step:
Function Control
Dynamically enable or disable functions during the call:
Enable functions on timeout:
Update AI settings:
Set speech timeouts:
Conference & Rooms
Join a conference:
Join a SignalWire room:
Post-Processing
Let AI speak once more before executing actions:
Multiple Actions
Chain multiple actions together:
Action Execution Order and Interactions
When chaining multiple actions, understanding how they interact is important.
Execution Order
Actions execute in the order they’re added to the SwaigFunctionResult. The response text is processed first, then actions execute sequentially.
Terminal Actions
Some actions end the call or AI session. Once a terminal action executes, subsequent actions may not run:
Terminal actions:
.connect(final=True)- Transfers call away permanently.hangup()- Ends the call.swml_transfer(final=True)- Transfers to another SWML endpoint
Non-terminal actions:
.update_global_data()- Continues normally.send_sms()- Continues normally.say()- Continues normally.connect(final=False)- Returns to agent if far end hangs up
Best practice: Put terminal actions last in the chain.
Conflicting Actions
Some action combinations don’t make sense together:
Using post_process with Actions
When post_process=True, the AI speaks the response and can respond to follow-up before actions execute:
This is useful for:
- Confirming before transfers
- Last-chance questions before hangup
- Warning before destructive actions
Action Timing Considerations
Immediate actions execute as soon as the function returns:
.update_global_data().toggle_functions()
Speech actions execute during AI’s turn:
.say().stop()
Call control actions affect the call flow:
.connect()- Immediate transfer.hangup()- Immediate disconnect.hold()- Immediate hold
External actions may have latency:
.send_sms()- Network delay possible.record_call()- Recording starts immediately but storage is async
Advanced: Execute Raw SWML
For advanced use cases, execute raw SWML documents directly:
Note: Most use cases are covered by the convenience methods above. Use execute_swml() only when you need SWML features not available through other action methods.