Function Result
SwaigFunctionResult API
Complete API reference for SwaigFunctionResult, the class for returning responses and actions from SWAIG functions.
Class Definition
Constructor
Core Concept
Post-Processing Behavior:
post_process=False(default): Execute actions immediatelypost_process=True: AI responds first, then actions execute
Basic Methods
set_response
Set the response text.
set_post_process
Set post-processing behavior.
add_action
Add a single action.
add_actions
Add multiple actions.
Call Control Actions
connect
Transfer the call to another destination.
hangup
End the call.
hold
Put the call on hold (max 900 seconds).
stop
Stop agent execution.
Speech Actions
say
Make the agent speak specific text.
wait_for_user
Control how agent waits for user input.
Data Actions
update_global_data
Update global session data.
remove_global_data
Remove keys from global data.
set_metadata
Set metadata scoped to the function’s token.
remove_metadata
Remove metadata keys.
Media Actions
play_background_file
Play background audio.
stop_background_file
Stop background playback.
Recording Actions
record_call
Start call recording.
stop_record_call
Stop recording.
Messaging Actions
send_sms
Send SMS message.
Payment Actions
pay
Process payment.
Context Actions
swml_change_step
Change conversation step.
swml_change_context
Change conversation context.
switch_context
Advanced context switching.
Conference Actions
join_room
Join a RELAY room.
join_conference
Join audio conference.
Tap/Stream Actions
tap
Start media tap/stream.
stop_tap
Stop media tap.
SIP Actions
sip_refer
Send SIP REFER for call transfer.
Advanced Actions
execute_swml
Execute raw SWML.
toggle_functions
Enable/disable specific functions.
Settings Actions
update_settings
Update AI runtime settings.
set_end_of_speech_timeout
Adjust speech detection timeout.
Method Chaining
All methods return self for chaining:
to_dict Method
Convert to SWAIG response format. Called automatically when returning from functions.
Action Execution Order
Actions execute in the order they’re added. Some actions are terminal and end the call flow:
Best practice: Put terminal actions last so preceding actions can execute.
See Also
Common Patterns
Conditional transfer:
Multi-action response: