functions
An array of JSON objects to define functions that can be executed during the interaction with the AI.
Properties
SWAIG.functions
An array of JSON objects that accept the following properties.
functions[].description
A description of the context and purpose of the function, to explain to the agent when to use it.
functions[].function
A unique name for the function. This can be any user-defined string or can reference a reserved function. Reserved functions are SignalWire functions that will be executed at certain points in the conversation. To learn more about reserved functions, see Reserved Functions.
functions[].active
Whether the function is active.
functions[].data_map
An object that processes function inputs and executes operations through expressions, webhooks, or direct output. Properties are evaluated in strict priority order: (1) expressions, (2) webhooks, (3) output. Evaluation stops at the first property that returns a valid output result, similar to a return statement in a function.
See data_map for additional details.
functions[].parameters
A JSON object that defines the expected user input parameters and their validation rules for the function.
See parameters for additional details.
functions[].fillers
An object containing language-specific arrays of filler phrases that are played when calling a SWAIG function. These fillers help break silence between responses and are played asynchronously during the function call. Each key is a language code and each value is an array of filler phrases selected from randomly.
functions[].skip_fillers
Skips the top-level fillers specified in ai.languages (which includes speech_fillers and function_fillers). When set to true, only function-specific fillers defined directly on SWAIG.functions.fillers will play.
functions[].meta_data
A powerful and flexible environmental variable which can accept arbitrary data that is set initially in the SWML script or from the SWML set_meta_data action. This data can be referenced locally to the function. All contained information can be accessed and expanded within the prompt - for example, by using a template string.
functions[].meta_data_token
Scoping token for meta_data. If not supplied, metadata will be scoped to function’s web_hook_url.
functions[].wait_file
A file to play while the function is running. wait_file_loops can specify the amount of times that files should continously play.
functions[].wait_file_loops
The amount of times that wait_file should continuously play/loop.
functions[].wait_for_fillers
Whether to wait for fillers to finish playing before continuing with the function.
functions[].web_hook_url
Function-specific URL to send status callbacks and reports to. Takes precedence over a default setting. Authentication can also be set in the url in the format of username:password@url.
functions[].purpose
Deprecated. Use description instead.
functions[].argument
Deprecated. Use parameters instead.
Webhook response
When a SWAIG function is executed, the function expects the user to respond with a JSON object that contains a response key and an optional action key.
This request response is used to provide the LLM with a new prompt response via the response key and to execute SWML-compatible objects that will perform
new dialplan actions via the action key.
response
Static text that will be added to the AI agent’s context.
action
A list of SWML-compatible objects that are executed upon the execution of a SWAIG function.
action[].SWML
A SWML object to be executed.
action[].say
A message to be spoken by the AI agent.
action[].stop
Whether to stop the conversation.
action[].hangup
Whether to hang up the call. When set to true, the call will be terminated after the AI agent finishes speaking.
action[].hold
Places the caller on hold while playing hold music (configured via the params.hold_music parameter).
During hold, speech detection is paused and the AI agent will not respond to the caller.
The value specifies the hold timeout in seconds. Can be:
- An integer (e.g.,
120for 120 seconds) - An object with a
timeoutproperty
Default timeout is 300 seconds (5 minutes). Maximum timeout is 900 seconds (15 minutes).
Unholding a call
There is no unhold SWAIG action because the AI agent is inactive during hold and cannot process actions.
To take a caller off hold, either:
- Let the hold timeout expire (the AI will automatically resume with a default message), or
- Use the Calling API
ai_unholdcommand to programmatically unhold the call with a custom prompt.
hold.timeout
The duration to hold the caller in seconds. Maximum is 900 seconds (15 minutes).
action[].change_context
The name of the context to switch to. The context must be defined in the AI’s prompt.contexts configuration.
This action triggers an immediate context switch during the execution of a SWAIG function.
Visit the contexts documentation for details on defining contexts.
action[].change_step
The name of the step to switch to. The step must be defined in prompt.contexts.{context_name}.steps for the current context.
This action triggers an immediate step transition during the execution of a SWAIG function.
Visit the steps documentation for details on defining steps.
action[].toggle_functions
An array of objects to toggle SWAIG functions on or off during the conversation. Each object identifies a function by name and sets its active state.
See toggle_functions for additional details.
toggle_functions[].function
The name of the SWAIG function to toggle.
toggle_functions[].active
Whether to activate or deactivate the function.
action[].set_global_data
A JSON object containing any global data, as a key-value map. This action sets the data in the global_data to be globally referenced.
action[].set_meta_data
A JSON object containing any metadata, as a key-value map. This action sets the data in the meta_data to be referenced locally in the function.
See set_meta_data for additional details.
action[].unset_global_data
The key of the global data to unset from the global_data. You can also reset the global_data by passing in a new object.
action[].unset_meta_data
The key of the metadata to unset from the meta_data. You can also reset the meta_data by passing in a new object.
action[].playback_bg
A JSON object containing the audio file to play.
playback_bg.file
URL or filepath of the audio file to play. Authentication can also be set in the url in the format of username:password@url.
playback_bg.wait
Whether to wait for the audio file to finish playing before continuing.
action[].stop_playback_bg
Whether to stop the background audio file.
action[].user_input
Used to inject text into the users queue as if they input the data themselves.
action[].context_switch
A JSON object containing the context to switch to.
See context_switch for additional details.
context_switch.system_prompt
The instructions to send to the agent.
context_switch.consolidate
Whether to consolidate the context.
context_switch.user_prompt
A string serving as simulated user input for the AI Agent. During a context_switch in the AI’s prompt, the user_prompt offers the AI pre-established context or guidance.
action[].transfer
Transfer the call to a new destination.
transfer.dest
The destination to transfer to (phone number, SIP URI, or SWML URL).
transfer.summarize
Whether to include a conversation summary when transferring.
Webhook response example
Callback Request for web_hook_url
SignalWire will make a request to the web_hook_url of a SWAIG function with the following parameters:
call_id
The unique identifier for the current call.
ai_session_id
The unique identifier for the AI session.
project_id
The project ID associated with the call.
space_id
The Space ID associated with the call.
caller_id_name
Name of the caller.
caller_id_num
Number of the caller.
global_data
Global data set via the set_global_data action, as a key-value map.
content_disposition
Content disposition identifier (e.g., "SWAIG Function").
channel_active
Whether the channel is currently active.
channel_offhook
Whether the channel is off-hook.
channel_ready
Whether the channel is ready.
content_type
Type of content. The value will be text/swaig.
app_name
Name of the application that originated the request.
function
Name of the function that was invoked.
meta_data
A JSON object containing any user metadata, as a key-value map.
SWMLVars
A collection of variables related to SWML.
purpose
The purpose of the function being invoked. The value will be the functions.purpose value you provided in the SWML Function properties.
argument_desc
The description of the argument being passed. This value comes from the argument you provided in the SWML Function properties.
argument
The argument the AI agent is providing to the function. The object contains the three following fields.
argument.parsed
If a JSON object is detected within the argument, it is parsed and provided here.
argument.raw
The raw argument provided by the AI agent.
argument.substituted
The argument provided by the AI agent, excluding any JSON.
version
Version number.
Webhook request example
Below is a json example of the callback request that is sent to the web_hook_url:
Variables
- ai_result: (out)
success|failed - return_value: (out)
success|failed
Reserved Functions
Reserved functions are special SignalWire functions that are automatically triggered at specific points during a conversation. You define them just like any other SWAIG function, but their names correspond to built-in logic on the SignalWire platform, allowing them to perform specific actions at the appropriate time.
Function name conflicts
Do not use reserved function names for your own SWAIG functions unless you want to use the reserved function’s built-in behavior. Otherwise, your function may not work as expected.
List of Reserved Functions
start_hook
Triggered when the call is answered. Sends the set properties of the function to the defined web_hook_url.
stop_hook
Triggered when the call is ended. Sends the set properties of the function to the defined web_hook_url.
summarize_conversation
Triggered when the call is ended. The post_prompt must be defined for this function to be triggered. Provides a summary of the conversation and any set properties to the defined web_hook_url.
Where are my function properties?
If the AI is not returning the properties you set in your SWAIG function, it may be because a reserved function was triggered before those properties were available. To ensure your function receives all necessary information, make sure the AI has access to the required property values before the reserved function is called. Any property missing at the time the reserved function runs will not be included in the data sent back.