ai
Creates an AI agent that conducts voice conversations using automatic speech recognition (ASR), large language models (LLMs), and text-to-speech (TTS) synthesis. The agent processes caller speech in real-time, generates contextually appropriate responses, and can execute custom functions to interact with external systems and databases through SignalWire AI Gateway (SWAIG).
Since the prompt configuration is central to AI agent behavior, it is recommended to read the Prompting Best Practices guide.
Properties
ai
An object that defines an AI agent for conducting voice conversations. Accepts the following properties to configure the agent’s prompt, behavior, functions, language support, and other settings.
ai.prompt
Defines the AI agent’s personality, goals, behaviors, and instructions for handling conversations. The prompt establishes how the agent should interact with callers, what information it should gather, and how it should respond to various scenarios.
It is recommended to write prompts using markdown formatting as LLMs better understand structured content. Additionally it is recommended to read the Prompting Best Practices guide.
ai.global_data
A key-value object for storing data that persists throughout the AI session.
Can be set initially in the SWML script or modified during the conversation using the set_global_data action.
The global_data object is accessible everywhere in the AI session: prompts, AI parameters,
and SWML returned from SWAIG functions.
Access properties using template strings (e.g ${global_data.property_name})
ai.hints
Provide an array of strings and/or objects to guide the AI’s pronunciation and understanding of specific words or phrases. Words that can commonly be mispronounced can be added to the hints to help the AI speak more accurately.
Hints as strings: Each string in the array gives the AI context on how to interpret certain words.
For example, if a user says Toni and the hint is Tony, the AI understands that the user said Tony.
Hints as objects: An array of objects with the properties below to customize how the AI handles specific words.
hints[].hint
The hint to match. This will match the string exactly as provided.
hints[].pattern
A regular expression to match the hint against. This will ensure that the hint has a valid matching pattern before being replaced.
hints[].replace
The text to replace the hint with. This will replace the portion of the hint that matches the pattern.
hints[].ignore_case
If true, the hint will be matched in a case-insensitive manner. Defaults to false.
ai.languages
An array of JSON objects defining supported languages in the conversation.
See languages for more details.
ai.params
A JSON object containing parameters as key-value pairs.
See params for more details.
ai.post_prompt
The final set of instructions and configuration settings to send to the agent.
post_prompt.text
The instructions to send to the agent.
post_prompt.temperature
Randomness setting. Float value between 0.0 and 1.5. Closer to 0 will make the output less random.
post_prompt.top_p
Randomness setting. Alternative to temperature. Float value between 0.0 and 1.0. Closer to 0 will make the output less random.
post_prompt.confidence
Threshold to fire a speech-detect event at the end of the utterance. Float value between 0.0 and 1.0. Decreasing this value will reduce the pause after the user speaks, but may introduce false positives.
post_prompt.presence_penalty
Aversion to staying on topic. Float value between -2.0 and 2.0. Positive values increase the model’s likelihood to talk about new topics.
post_prompt.frequency_penalty
Aversion to repeating lines. Float value between -2.0 and 2.0. Positive values decrease the model’s likelihood to repeat the same line verbatim.
ai.post_prompt_url
The URL to which to send status callbacks and reports. Authentication can also be set in the url in the format of username:password@url.
See post_prompt_url callback below.
ai.pronounce
An array of objects to clarify the AI’s pronunciation of certain words or expressions.
pronounce[].replace
The expression to replace.
pronounce[].with
The phonetic spelling of the expression.
pronounce[].ignore_case
Whether the pronunciation replacement should ignore case.
ai.SWAIG
An array of JSON objects to create user-defined functions/endpoints that can be executed during the dialogue.
See SWAIG for more details.
post_prompt_url callback
SignalWire will make a request to the post_prompt_url with the following parameters:
action
Action that prompted this request. The value will be “post_conversation”.
ai_end_date
Timestamp indicating when the AI session ended.
ai_session_id
A unique identifier for the AI session.
ai_start_date
Timestamp indicating when the AI session started.
app_name
Name of the application that originated the request.
call_answer_date
Timestamp indicating when the call was answered.
call_end_date
Timestamp indicating when the call ended.
call_id
ID of the call.
call_log
The complete log of the call, as a JSON object.
call_log.content
Content of the call log entry.
call_log.role
Role associated with the call log entry (e.g., “system”, “assistant”, “user”).
call_start_date
Timestamp indicating when the call started.
caller_id_name
Name associated with the caller ID.
caller_id_num
Number associated with the caller ID.
content_disposition
Disposition of the content.
content_type
Type of content. The value will be text/swaig.
conversation_id
A unique identifier for the conversation thread, if configured via the AI parameters.
post_prompt_data
The answer from the AI agent to the post_prompt. The object contains the three following fields.
post_prompt_data.parsed
If a JSON object is detected within the answer, it is parsed and provided here.
post_prompt_data.raw
The raw data answer from the AI agent.
post_prompt_data.substituted
The answer from the AI agent, excluding any JSON.
project_id
ID of the Project.
space_id
ID of the Space.
SWMLVars
A collection of variables related to SWML.
swaig_log
A log related to SWAIG functions.
total_input_tokens
Represents the total number of input tokens.
total_output_tokens
Represents the total number of output tokens.
version
Version number.
Post prompt callback request example
Below is a JSON example of the callback request that is sent to the post_prompt_url:
Responding to post prompt requests
The response to the callback request should be a JSON object with the following parameters: