import Tabs from @theme/Tabs; import TabItem from @theme/TabItem; [](./connect.mdx) verbs noun allows the connection to a virtual AI agent. For example: xml You are a recipe bot. You can help me cook any recipe, step by step. Summarize the conversation. js const { RestClient } = require(@signalwire/compatibility-api); const response = new RestClient.LaML.VoiceResponse(); const connect = response.connect(); const ai = connect.ai(); ai.setPostPromptURL(https://webhook.site/10d74766-3782-414d-8d40-614dacdaf140); ai.prompt( { confidence: 0.6 }, You are a recipe bot. You can help me cook any recipe, step by step. ); ai.postPrompt({ confidence: 0.6 }, Summarize the conversation.); console.log(response.toString()); The agent has the ability to perform a number of actions when needed, for example it can hang up the call or send an SMS to the caller. ## Noun Attributes | Attribute | | | -: | | | engine optional | The Text-To-Speech engine to use. Default: gcloud. | | voice optional | Default Text-To-Speech voice to use. Default: en-US-Neural2-J. | | postPromptURL optional | SignalWire will make a POST request to this URL when the conversation terminates. It can include an optional username and password. See [below](#postPromptURL) for specified request parameters. | | postPromptAuthUser optional | HTTP user to use for the request to postPromptURL. Ignored if a user already appears in the URL. | | postPromptAuthPassword optional | HTTP password to use for the request to postPromptURL. Ignored if a password already appears in the URL. | | hints optional | A list of words and phrases that a caller is likely to say during a call. This is used to improve speech recognition accuracy. | ### and {#prompts} You can specify two prompts: and . Any text inside will be used as the initial prompt for the AI agent (it will remain hidden from the user). You typically use to instruct the agent on who it is, what it should do, and what it knows. Similarly, any text in will be used after the end of the conversation with the agent (it will remain hidden from the user, but the response of the agent will be available in the postPromptURL request). You typically use to instruct the agent to emit a final message that youll consume from your API (e.g., summarizing the conversation, or retrieving a specific entity — such as a customer id — from the conversation). Both and accept the following attributes: | Attribute | | | -: | | | temperature optional | What statistical sampling temperature to use, between 0 and 2. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic. | | topP optional | An alternative to sampling with temperature, called nucleus sampling, where the model considers the results of the [tokens](https://en.wikipedia.org/wiki/Lexical_analysis#Tokenization) with topP probability mass. So 0.1 means only the tokens comprising the top 10% probability mass are considered. Accepts values between 0 and 1. We recommend setting temperature=1 when altering this parameter. | | confidence optional | Confidence threshold, between 0 and 1, needed to consider the current utterance as end of speech. Decreasing this value will reduce the pause after the user speaks, but may introduce false positives. | | bargeConfidence optional | Confidence threshold, between 0 and 1, needed to consider the current utterance as end of speech. This only applies when the user is speaking over the AI agent. Decreasing this value will reduce the time it takes the agent to stop, but may introduce false positives. | | presencePenalty optional | Number between -2.0 and 2.0. Positive values penalize new tokens based on whether they appear in the text so far, increasing the models likelihood to talk about new topics. | | frequencyPenalty optional | Number between -2.0 and 2.0. Positive values penalize new tokens based on their existing frequency in the text so far, decreasing the models likelihood to repeat the same line verbatim. | The default values change depending on the prompt type: | Attribute | Default for | Default for | | --: | - | -- | | temperature | 0.3 | 0.0 | | topP | 1.0 | 1.0 | | confidence | 0.6 | 0.6 | | bargeConfidence | 0.3 | 0.0 | | presencePenalty | 0.1 | 0.0 | | frequencyPenalty | 0.1 | 0.0 | #### Request parameters for the postPromptURL URL {#postPromptURL} The postPromptURL request contains the following parameters: | Parameter | | | --: | | | content_type string | Type of content. Its value is Conversation/Log. | | app_name string | Name of the application that originated this request. | | action string | Action that this message is about. Its value is post_conversation. | | call_log object | The complete log of the call, as a JSON object. | | post_prompt_data object | The answer of the AI agent to the message in . See below for the fields within this object. | | post_prompt_data.parsed object | If a JSON object is detected within the answer, it is parsed and provided here. | | post_prompt_data.raw string | The raw answer of the AI agent. | | post_prompt_data.substituted string | The answer of the AI agent, excluding any JSON. | ### You can allow the AI agent to speak more than one language using the tag. The agent will pick the correct language appropriately. For example: xml You are a translation bot. Summarize the conversation. Each tag accepts the following attributes: | Parameter | | | --: | | | code | Language code. For example, fr-FR. | | name | Name of the language. For example, French. | | voice | Voice to use for the language. The engine is the one specified in the s engine attribute. For example, fr-FR-Neural2-B. | #### Supported Codes and Voices You can find the list of supported codes (*languages*) and voices [here](/guides/voice-and-languages) ### (SignalWire AI Gateway) You can define a set of functions that the AI agent will be able to invoke. Functions allow the agent to perform external actions (e.g., sending an SMS) or gathering data (e.g., the current weather in a specific city). For example: xml You are a general-purpose AI bot. Summarize the conversation. Value1 In the example above, when needed, the agent will be able to invoke the get_weather or get_world_time functions. At each invocation, a request will be made to the webHookURL, which should respond with the result of the function invocation (for example, Sunny). #### In , use the tag to set default parameters for all function definitions. The allowed parameters are: | Parameter | | | -: | - | | webHookURL string | The webhook to invoke when a function is called. | | webHookAuthUser string | Username for webHookURL. Ignored if a username is already provided in webHookURL. | | webHookAuthPass string | Password for webHookURL. Ignored if a password is already provided in webHookURL. | In the content of the tag you can specify default metadata too, for example: xml Value1 Value2 #### In , use the tag to define a function that the AI agent will be able to invoke when needed. The allowed parameters are: | Parameter | | | -: | | | name | A unique name for the function. For example, get_weather. | | argument | A description of the input to the function. For example, The location or name of the city. | | purpose | A description of the context and purpose of the function, to explain the agent when to use it. | | webHookURL string | The webhook to invoke when the function is called. [Request parameters](#webHookURL) are sent to the webook. | | webHookAuthUser string | Username for webHookURL. Ignored if a username is already provided in webHookURL. | | webHookAuthPass string | Password for webHookURL. Ignored if a password is already provided in webHookURL. | In the content of the tag you can specify metadata too, for example: xml Value1 Value2 #### Request parameters for functions webHookURL URL {#webHookURL} The webHookURL request contains the following parameters: | Parameter | | | : | | | app_name string | Name of the application that originated this request. | | content_type string | Type of content. Its value is Conversation/SWAIG-function. | | function string | Name of the function that was invoked. | | meta_data object | A JSON object containing any metadata, as a key-value map. | | call_log object | The complete log of the call, as a JSON object. | | argument object | The actual argument to the function. See below for the fields within this object. | | argument_desc string | The description of the function that was provided to the agent. | | purpose string | The purpose of the function that was provided to the agent. | | 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. | You need to answer the request with a JSON object containing the result. For example, if your function was called get_weather, your webhook would check the weather in the requested city using a 3rd party API, and then provide the answer to the agent with the following JSON response: json { response: Its sunny. } ## Examples ### A Customer Support Agent The following agent will help customers troubleshoot the most common problems with their devices. At the end of the conversation, the agent will include in the post_prompt_data field (see [request parameters](#postPromptURL)) a token that will indicate whether the troubleshooting was successful ([solved:true] or [solved:false]). You can use the postPromptURL webhook to retrieve this result. xml You are a customer support agent for a vacuum cleaner company called Best Quality Vacuum. You are going to help the customer troubleshoot their problem. If the vacuum cleaner has lost suction power, the customer needs to empty the container and check for any clogged filter. Filters can be cleaned. Sometimes, foreign items can restrict the air flow in the hose. Those can be removed with the help of a long stick. If the vacuum does not power on, the customer should check if the battery is charged by pressing the blue button to see the percentage of charge. Start by asking the customer what their issue is. Did the customer solve the issue? Answer with true or false in square brackets after the solved keyword (e.g, [solved:true]). Then, summarize the conversation. js const { RestClient } = require(@signalwire/compatibility-api); const response = new RestClient.LaML.VoiceResponse(); const connect = response.connect(); const ai = connect.ai(); ai.setPostPromptURL(https://my-application.example.com/my-webhook); ai.prompt( You are a customer support agent for a vacuum cleaner company called Best Quality Vacuum. You are going to help the customer troubleshoot their problem. If the vacuum cleaner has lost suction power, the customer needs to empty the container and check for any clogged filter. Filters can be cleaned. Sometimes, foreign items can restrict the air flow in the hose. Those can be removed with the help of a long stick. If the vacuum does not power on, the customer should check if the battery is charged by pressing the blue button to see the percentage of charge. Start by asking the customer what their issue is. ); ai.postPrompt( Did the customer solve the issue? Answer with true or false in square brackets after the solved keyword (e.g, \[solved:true]\). Then, summarize the conversation. ); console.log(response.toString()); ### A Voicemail Bot The following agent will collect a message from the caller, then will produce a JSON that an application can consume. xml You are Franklins assistant, and your job is to collect messages for him over the phone. You can reassure that Franklin will get in touch as soon as possible. Collect the users name and number if you do not already know it from the caller id. Start by presenting yourself, then let the contact know that Franklin is not available, then offer to collect a message. After collecting the message, do not wait for the user to end the conversation: say good bye and hang up the call. Summarize the message as a valid anonymous json object by filling the upper case placeholders in this template: { contact_info: { name: CONTACT_NAME, number: CONTACT_PHONE }, message: MESSAGE } js const { RestClient } = require(@signalwire/compatibility-api); const response = new RestClient.LaML.VoiceResponse(); const connect = response.connect(); const ai = connect.ai(); ai.setPostPromptURL(https://my-application.example.com/my-webhook); ai.prompt( You are Franklins assistant, and your job is to collect messages for him over the phone. You can reassure that Franklin will get in touch as soon as possible. Collect the users name and number if you do not already know it from the caller id. Start by presenting yourself, then let the contact know that Franklin is not available, then offer to collect a message. After collecting the message, do not wait for the user to end the conversation: say good bye and hang up the call. ); ai.postPrompt( Summarize the message as a valid anonymous json object by filling the upper case placeholders in this template: { contact_info: { name: CONTACT_NAME, number: CONTACT_PHONE }, message: MESSAGE } ); console.log(response.toString());