SWAIG

View as Markdown

The SignalWire AI Gateway Interface. Allows you to create user-defined functions that can be executed during the dialogue.

Properties

ai.SWAIG
object

An object that accepts the following properties.

SWAIG.defaults
object

Default settings for all SWAIG functions. If defaults is not set, settings may be set in each function object. Default is not set.

defaults.web_hook_url
string

The default URL to send status callbacks and reports to for all SWAIG functions. If defaults is not set, web_hook_url may be set in each SWAIG function object. Authentication can also be set in the url in the format of username:password@url.

SWAIG.functions
object[]

An array of JSON objects to define functions that can be executed during the interaction with the AI. Default is not set. The fields of this object are the six following.

See functions for additional details.

SWAIG.includes
object[]

An array of objects to include remote function signatures. This allows you to include functions that are defined in a remote location.

See includes for additional details.

SWAIG.internal_fillers
object

An object that defines language-specific filler phrases for internal SWAIG functions. These fillers help break silence between responses and are played asynchronously during function execution. Each key is a function name, and each value is an object mapping language codes to arrays of filler phrases.

internal_fillers.hangup
object

Filler phrases played when the AI Agent is hanging up the call.

internal_fillers.check_time
object

Filler phrases played when the AI Agent is checking the time.

internal_fillers.wait_for_user
object

Filler phrases played when the AI Agent is waiting for user input.

internal_fillers.wait_seconds
object

Filler phrases played during deliberate pauses or wait periods.

internal_fillers.adjust_response_latency
object

Filler phrases played when the AI Agent is adjusting response timing.

internal_fillers.next_step
object

Filler phrases played when transitioning between conversation steps when utilizing prompt.contexts.

internal_fillers.change_context
object

Filler phrases played when switching between conversation contexts when utilizing prompt.contexts.

internal_fillers.get_visual_input
object

Filler phrases played when the AI Agent is processing visual input. Enabled when enable_vision is set to true in ai.params.

internal_fillers.get_ideal_strategy
object

Filler phrases played when the AI Agent is thinking or considering options. Enabled when enable_thinking is set to true in ai.params.

SWAIG.native_functions
string[]

Prebuilt functions the AI agent is able to call. The agent is already aware of these functions and can use them creatively based on prompting. For example, a prompt like “tell the user what time it is” will automatically use check_time.

Accepted values:

  • adjust_response_latency - Adjust how long the agent will wait for the user to stop talking.
  • check_time - Returns the current time for the time zone set in ai.local_tz.
  • wait_for_user - Causes the AI to wait until the user speaks again. Use when the user asks to wait or hold on.
  • wait_seconds - Waits for the given amount of time.

Filler language codes

Several SWAIG properties accept filler phrases keyed by language code, including internal_fillers and per-function fillers. The following language codes are supported across all filler configurations.

CodeDescription
defaultDefault language set by the user in the ai.languages property
bgBulgarian
caCatalan
csCzech
daDanish
da-DKDanish (Denmark)
deGerman
de-CHGerman (Switzerland)
elGreek
enEnglish
en-AUEnglish (Australia)
en-GBEnglish (United Kingdom)
en-INEnglish (India)
en-NZEnglish (New Zealand)
en-USEnglish (United States)
esSpanish
es-419Spanish (Latin America)
etEstonian
fiFinnish
frFrench
fr-CAFrench (Canada)
hiHindi
huHungarian
idIndonesian
itItalian
jaJapanese
koKorean
ko-KRKorean (South Korea)
ltLithuanian
lvLatvian
msMalay
multiMultilingual (Spanish + English)
nlDutch
nl-BEFlemish (Belgian Dutch)
noNorwegian
plPolish
ptPortuguese
pt-BRPortuguese (Brazil)
pt-PTPortuguese (Portugal)
roRomanian
ruRussian
skSlovak
svSwedish
sv-SESwedish (Sweden)
thThai
th-THThai (Thailand)
trTurkish
ukUkrainian
viVietnamese
zhChinese (Simplified)
zh-CNChinese (Simplified, China)
zh-HansChinese (Simplified Han)
zh-HantChinese (Traditional Han)
zh-HKChinese (Traditional, Hong Kong)
zh-TWChinese (Traditional, Taiwan)

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
stringRequired

Static text that will be added to the AI agent’s context.

action
object[]

A list of SWML-compatible objects that are executed upon the execution of a SWAIG function.

action[].SWML
object

A SWML object to be executed.

action[].say
string

A message to be spoken by the AI agent.

action[].stop
boolean

Whether to stop the conversation.

action[].hangup
boolean

Whether to hang up the call. When set to true, the call will be terminated after the AI agent finishes speaking.

action[].hold
integer | object

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., 120 for 120 seconds)
  • An object with a timeout property

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_unhold command to programmatically unhold the call with a custom prompt.
hold.timeout
integerDefaults to 300

The duration to hold the caller in seconds. Maximum is 900 seconds (15 minutes).

action[].change_context
string

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
string

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
object[]

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
stringRequired

The name of the SWAIG function to toggle.

toggle_functions[].active
booleanDefaults to true

Whether to activate or deactivate the function.

action[].set_global_data
object

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
object

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
string | object

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
string | object

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
object

A JSON object containing the audio file to play.

playback_bg.file
string

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
booleanDefaults to false

Whether to wait for the audio file to finish playing before continuing.

action[].stop_playback_bg
boolean

Whether to stop the background audio file.

action[].user_input
string

Used to inject text into the users queue as if they input the data themselves.

action[].context_switch
object

A JSON object containing the context to switch to.

See context_switch for additional details.

context_switch.system_prompt
string

The instructions to send to the agent.

context_switch.consolidate
booleanDefaults to false

Whether to consolidate the context.

context_switch.user_prompt
string

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
object

Transfer the call to a new destination.

transfer.dest
string

The destination to transfer to (phone number, SIP URI, or SWML URL).

transfer.summarize
booleanDefaults to false

Whether to include a conversation summary when transferring.

Webhook response example

1{
2 "response": "Oh wow, it's 82.0°F in Tulsa. Bet you didn't see that coming! Humidity at 38%. Your hair is going to love this! Wind speed is 2.2 mph. Hold onto your hats, or don't, I'm not your mother! Looks like Sunny. Guess you'll survive another day.",
3 "action": [
4 {
5 "set_meta_data": {
6 "temperature": 82.0,
7 "humidity": 38,
8 "wind_speed": 2.2,
9 "weather": "Sunny"
10 }
11 },
12 {
13 "SWML": {
14 "version": "1.0.0",
15 "sections": {
16 "main": [
17 {
18 "play": {
19 "url": "https://example.com/twister.mp3"
20 }
21 }
22 ]
23 }
24 }
25 }
26 ]
27}

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
string

The unique identifier for the current call.

ai_session_id
string

The unique identifier for the AI session.

project_id
string

The project ID associated with the call.

space_id
string

The Space ID associated with the call.

caller_id_name
string

Name of the caller.

caller_id_num
string

Number of the caller.

global_data
object

Global data set via the set_global_data action, as a key-value map.

content_disposition
string

Content disposition identifier (e.g., "SWAIG Function").

channel_active
boolean

Whether the channel is currently active.

channel_offhook
boolean

Whether the channel is off-hook.

channel_ready
boolean

Whether the channel is ready.

content_type
string

Type of content. The value will be text/swaig.

app_name
string

Name of the application that originated the request.

function
string

Name of the function that was invoked.

meta_data
object

A JSON object containing any user metadata, as a key-value map.

SWMLVars
object

A collection of variables related to SWML.

purpose
string

The purpose of the function being invoked. The value will be the functions.purpose value you provided in the SWML Function properties.

argument_desc
string | object

The description of the argument being passed. This value comes from the argument you provided in the SWML Function properties.

argument
object

The argument the AI agent is providing to the function. The object contains the three following fields.

argument.parsed
object

If a JSON object is detected within the argument, it is parsed and provided here.

argument.raw
string

The raw argument provided by the AI agent.

argument.substituted
string

The argument provided by the AI agent, excluding any JSON.

version
string

Version number.

Webhook request example

Below is a json example of the callback request that is sent to the web_hook_url:

1{
2 "app_name": "swml app",
3 "global_data": {
4 "caller_id_name": "",
5 "caller_id_number": "sip:guest-246dd851-ba60-4762-b0c8-edfe22bc5344@46e10b6d-e5d6-421f-b6b3-e2e22b8934ed.call.signalwire.com;context=guest"
6 },
7 "project_id": "46e10b6d-e5d6-421f-b6b3-e2e22b8934ed",
8 "space_id": "5bb2200d-3662-4f4d-8a8b-d7806946711c",
9 "caller_id_name": "",
10 "caller_id_num": "sip:guest-246dd851-ba60-4762-b0c8-edfe22bc5344@46e10b6d-e5d6-421f-b6b3-e2e22b8934ed.call.signalwire.com;context=guest",
11 "channel_active": true,
12 "channel_offhook": true,
13 "channel_ready": true,
14 "content_type": "text/swaig",
15 "version": "2.0",
16 "content_disposition": "SWAIG Function",
17 "function": "get_weather",
18 "argument": {
19 "parsed": [
20 {
21 "city": "Tulsa",
22 "state": "Oklahoma"
23 }
24 ],
25 "raw": "{\"city\":\"Tulsa\",\"state\":\"Oklahoma\"}"
26 },
27 "call_id": "6e0f2f68-f600-4228-ab27-3dfba2b75da7",
28 "ai_session_id": "9af20f15-7051-4496-a48a-6e712f22daa5",
29 "argument_desc": {
30 "properties": {
31 "city": {
32 "description": "Name of the city",
33 "type": "string"
34 },
35 "country": {
36 "description": "Name of the country",
37 "type": "string"
38 },
39 "state": {
40 "description": "Name of the state",
41 "type": "string"
42 }
43 },
44 "required": [],
45 "type": "object"
46 },
47 "purpose": "Get weather with sarcasm"
48}

Variables

  • ai_result: (out) success | failed
  • return_value: (out) success | failed

Examples

internal_fillers

1SWAIG:
2 internal_fillers:
3 hangup:
4 en-US:
5 - 'Goodbye!'
6 - 'Thank you for calling.'
7 - 'Have a great day!'
8 es-ES:
9 - '¡Adiós!'
10 - 'Gracias por llamar.'
11 - '¡Que tengas un buen día!'
12 check_time:
13 default:
14 - 'Let me check the time.'
15 - 'One moment while I get the time.'
16 - 'Just checking the current time.'