functions
An array of JSON objects to define functions that can be executed during the interaction with the AI.
Each function needs somewhere to run: a web_hook_url, set on the function or inherited from
SWAIG.defaults.web_hook_url, or a data_map.
A function with none of these is not added to the agent.
A function’s property names are matched without regard to case, so Gates is read as gates.
Write each property once, in the case shown on this page: when a function has the same property in
two casings, only the first is read, and the other is ignored without a warning.
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. A function with neither description nor the deprecated purpose isn’t added to the agent.
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. Credentials embedded in the URL take precedence over web_hook_auth_user and web_hook_auth_password.
functions[].web_hook_auth_user
Username for basic auth on this function’s webhook. Falls back to defaults.web_hook_auth_user.
functions[].web_hook_auth_password
Password for basic auth on this function’s webhook. Falls back to defaults.web_hook_auth_password.
functions[].gates
Semantic gates: 1 to 8 yes/no questions about the call that must all pass before the function runs. When any gate fails, the function doesn’t run, and the AI gets the first failing gate’s on_fail response instead. A gated function needs a description and a web_hook_url (its own or from SWAIG.defaults) or a data_map. If any gate is invalid, the function isn’t added to the agent at all.
See gates for additional details.
functions[].gate_fillers
What the agent says while the function’s gates are checked, shaped like fillers. Ignored on a function without gates.
functions[].fillers_at_gates
For a gated function without gate_fillers, whether its fillers play as soon as the AI calls it, during the gate check (true), or only after the gates pass (false). Set it to false when the function’s fillers announce the action (“OK, cancelling your account now”), so the caller doesn’t hear them before a gate blocks it. When unset, the function inherits SWAIG.defaults.fillers_at_gates, which is true unless you change it.
functions[].visual_input
How many of the caller’s newest video frames your web_hook_url receives with the function call, as visual_input in the request body: true is 1, a whole number from 0 to 5, and false or 0 is none. On a gated function, the frames are taken when its gates are checked, never later, and a blocked call sends none. Ignored on a data_map function.
functions[].purpose
Deprecated. Use description instead. When a function sets both, purpose is used.
functions[].argument
Deprecated. Use parameters instead.
functions[].web_hook_auth_pass
Password for basic auth on this function’s webhook. Deprecated — use web_hook_auth_password instead.
The alias is used only when web_hook_auth_password is not set.
Tool webhook
When the agent calls one of your SWAIG functions, the platform sends an HTTP POST to that function’s
web_hook_url (or the SWAIG defaults.web_hook_url). Your endpoint runs the function and returns a JSON
object with a response (the result the AI reads next) and, optionally, an action — a single
object or an array — telling the agent what to do. Every field is optional.
Request
The function's parameter definition, as you declared it in parameters.
The description you gave the function in
SWAIG.functions.
The token that scopes meta_data. This is the meta_data_token you set on the function, or a
value derived from the function's web_hook_url and credentials when you did not set one.
Metadata scoped to meta_data_token. An empty object when the function has none yet.
The content type of the request body. Always text/swaig.
How the body is delivered. Always SWAIG Function.
The conversation ID, when the AI session has one. A text conversation held over the
AI chat endpoint always has one, and it matches
call_id.
The AI session's current global_data, when it has any.
The kind of conversation the agent is running: a call, or a text conversation held over the AI chat endpoint. Not included on function calls made during a call.
true when the AI session has hit an unrecoverable error. Included only in that case.
A description of the error. Included only when fatal_error is set.
SWML variables for the call. Included when you enable swaig_post_swml_vars.
SWML call state. Included when you enable swaig_post_swml_vars.
The conversation so far, with sensitive values redacted. Included when you enable swaig_post_conversation.
The full, unredacted conversation so far. Included when you enable swaig_post_conversation.
The caller's newest video frames, oldest first, up to the function's
visual_input count.
Included only for a function that sets visual_input; an empty array when the call has no video,
and for functions called after the call ends. On a gated function, the frames are taken when its
gates are checked, never later.
The evaluation_id of the semantic gate check that judged the frames in visual_input. Included
when one of the function's gates looked at them.
See the AI SWAIG tool webhook webhook page for the full field reference.
Reply
Return a JSON object with an optional response and an optional action. The response is the result
the AI reads next, and action carries objects that change what the call does next.
response
The result the agent reads next. A string becomes the tool message as written. An object splits the result into tool_result, the data the agent reads, and tool_prompt, an instruction added right after it. When omitted, the agent gets a default result.
post_process
If true, the actions run after the agent has spoken its reply rather than immediately.
action
An action, or a list of actions, for the platform to perform on the call.
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
timeout, and optionallystepandtimeout_step
Default timeout is 300 seconds (5 minutes). Maximum timeout is 900 seconds (15 minutes).
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).
hold.step
The step to move to when the caller is taken off hold. When omitted, the conversation stays on the current step. Applies only if the hold starts.
hold.timeout_step
The step to move to when the hold times out without the caller being taken off hold. When omitted, the conversation stays on the current step. Applies only if the hold starts.
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.
A function can only toggle functions that have the same meta_data_token as itself.
See toggle_functions for additional details.
toggle_functions[].function
The name of the SWAIG function to toggle. One name per object; to toggle several functions, add an object for each.
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 to remove from global_data, or an array of keys to remove.
action[].unset_meta_data
The key to remove from the function’s meta_data, or an array of keys to remove.
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
Stops the background audio file. The action runs whenever the key is present, whatever its value, so false also stops playback. Leave the key out to keep playing.
action[].user_input
Used to inject text into the users queue as if they input the data themselves.
action[].context_switch
Replaces the agent’s instructions mid-conversation. You can use variables in system_prompt, user_prompt, system_pom, and user_pom. In a data_map function they’re expanded along with the rest of the output; in a reply from your web_hook_url, they’re expanded when the action runs. Either way they’re expanded only once, so a value that itself contains ${...} is left as it is.
See context_switch for additional details.
context_switch.system_prompt
The new instructions for the agent. Set this or system_pom.
context_switch.system_pom
The new instructions as an object with text or pom, the same shape as a prompt. Used instead of system_prompt when both are set.
context_switch.consolidate
If true, the conversation so far is summarized and the summary is carried into the new context. When the caller hasn’t spoken yet there’s nothing to summarize, so full_reset is ignored.
context_switch.full_reset
If true, the new instructions replace the agent’s original prompt. Otherwise the conversation is cleared and the new instructions are added.
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.
context_switch.user_pom
The simulated user input as an object with text or pom. Used instead of user_prompt when both are set.
action[].settings
Changes the AI model’s settings for the rest of the conversation, as a key-value map. Only settings the selected model supports are applied. Requires params.swaig_allow_settings, which is on by default. The new map replaces the current settings: any setting you leave out, including one set on prompt, returns to the model’s default.
action[].user_event
Sends a custom event to the client connected to the call, with this object as its payload, like the user_event method.
action[].transfer
Transfer the call to a new destination. Accepts two forms depending on whether it accompanies a sibling action[].SWML payload:
- Boolean — use alongside a sibling
action[].SWMLpayload in the same action object. Whentrue, ends the AI session and hard-transfers the call to that SWML. When omitted orfalse, the SWML executes inline and the AI session continues afterward. - Object or string — use on its own, without
SWML, to end the AI session and transfer the call to the destination configured with the fields below. A string is shorthand fortransfer.dest.
transfer.dest
The destination to transfer to: the name of a section in the current SWML document, or a URL that returns SWML to execute.
transfer.summarize
Whether to include a conversation summary when transferring.
Variables
SWAIG functions don’t set SWML variables of their own. The ai method sets
ai_result when the agent ends.
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.
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
startup_hook
Runs when the conversation starts. Sends the set properties of the function to the defined web_hook_url.
hangup_hook
Runs when the conversation ends. 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.
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.