Using toggle_functions
In this example, the transfer
function is toggled off from the start. The AI agent will toggle this
function on after the get_joke
function is called and will also toggle the get_joke
function off. This creates a scenario where a user can only
be transferred after hearing a joke from the AI, and can only request one joke. The AI agent will then match the transfer destination
based on the user's input, with the meta_data
table serving as a directory for the transfer destinations.
If no match is found, the AI agent will fall back to the ".*"
expression, which will inform the user
that the transfer was unsuccessful and requires a valid input.
transfer
Function
- YAML
- JSON
SWAIG:
functions:
- function: transfer
active: "false"
purpose: use to transfer to a target
argument:
type: object
properties:
target:
description: the target to transfer to
type: string
data_map:
expressions:
- pattern: "\\w+"
string: "%{meta_data.table.%{lc:args.target}}"
output:
action:
- say: Please stand by while I connect your call.
- SWML:
version: 1.0.0
sections:
main:
- connect:
to: "%{meta_data.table.%{lc:args.target}}"
- stop: "true"
response: transferred, the call has ended.
- string: "%{args.target}"
pattern: ".*"
output:
response: "I'm sorry, I was unable to transfer your call to %{input.args.target}."
meta_data:
table:
support: "+1XXXXXXXXXX"
sales: "+1YYYYYYYYYY"
{
"SWAIG": {
"functions": [
{
"function": "transfer",
"active": "false",
"purpose": "use to transfer to a target",
"argument": {
"type": "object",
"properties": {
"target": {
"description": "the target to transfer to",
"type": "string"
}
}
},
"data_map": {
"expressions": [
{
"pattern": "\\w+",
"string": "%{meta_data.table.%{lc:args.target}}",
"output": {
"action": [
{
"say": "Please stand by while I connect your call."
},
{
"SWML": {
"version": "1.0.0",
"sections": {
"main": [
{
"connect": {
"to": "%{meta_data.table.%{lc:args.target}}"
}
}
]
}
}
},
{
"stop": "true"
}
],
"response": "transferred, the call has ended."
}
},
{
"string": "%{args.target}",
"pattern": ".*",
"output": {
"response": "I'm sorry, I was unable to transfer your call to %{input.args.target}."
}
}
]
},
"meta_data": {
"table": {
"support": "+1XXXXXXXXXX",
"sales": "+1YYYYYYYYYY"
}
}
}
]
}
}
We set the function to being toggled off with the following line:
active: "false"
get_joke
Function
- YAML
- JSON
- function: get_joke
purpose: use to get a joke
data_map:
webhooks:
- url: 'https://example.com/v1/%{args.type}'
headers:
X-Api-Key: api-token-here
method: GET
output:
response: "Tell the user: %{array[0].joke}." # array[0] is the first joke in the array
action:
- toggle_functions:
- active: true
function: transfer
- active: false
function: get_joke
[
{
"function": "get_joke",
"purpose": "use to get a joke",
"data_map": {
"webhooks": [
{
"url": "https://example.com/v1/%{args.type}",
"headers": {
"X-Api-Key": "api-token-here"
},
"method": "GET",
"output": {
"response": "Tell the user: %{array[0].joke}.",
"action": [
{
"toggle_functions": [
{
"active": true,
"function": "transfer"
},
{
"active": false,
"function": "get_joke"
}
]
}
]
}
}
]
}
}
]
In the above function, we set the transfer
function to be toggled on.
Now when a user asks to be transferred, the AI agent will now be able to do so because the transfer
function is toggled on.
Additionally, the get_joke
function is toggled off, so the user will not be able to request another joke.
- YAML
- JSON
- toggle_functions:
- active: true
function: transfer
- active: false
function: get_joke
[
{
"toggle_functions": [
{
"active": true,
"function": "transfer"
},
{
"active": false,
"function": "get_joke"
}
]
}
]
Full example
- YAML
- JSON
sections:
main:
- ai:
prompt:
text: >-
Your name is Frank. You help transfer to the right department. Use
the 'get_joke' function to get a joke.
# Greetings Greet the user, and inform them that your name is Frank
and you can help assist them in transferring the call to Support or
Sales. However, let them know the only way to be transferred is to
hear a joke.
# Rules A user cannot be transferred until they have asked for at
least one joke throughout the call. When a user is able to be
transferred, use the 'transfer' function. Only provide one joke to
the user, if the user asks for more jokes after the first one, tell
them you are no longer giving out jokes, but can help with
transferring the call to a different department.
post_prompt: Summarize the call as a json object
post_prompt_url: 'https://example.com/post_prompt'
SWAIG:
functions:
- function: transfer
active: 'false'
purpose: use to transfer to a target
argument:
type: object
properties:
target:
description: the target to transfer to
type: string
data_map:
expressions:
- pattern: \w+
string: '%{meta_data.table.%{lc:args.target}}'
output:
action:
- say: Please stand by while I connect your call.
- SWML:
version: 1.0.0
sections:
main:
- connect:
to: '%{meta_data.table.%{lc:args.target}}'
- stop: 'true'
response: 'transferred, the call has ended.'
- string: '%{args.target}'
pattern: .*
output:
response: >-
I'm sorry, I was unable to transfer your call to
%{input.args.target}.
meta_data:
table:
support: '+1XXXXXXXXXX'
sales: '+1YYYYYYYYY'
- function: get_joke
purpose: used to get a joke
argument:
type: object
properties:
type:
type: string
description: must either be 'jokes' or 'dadjokes'
data_map:
webhooks:
- url: >-
https://example.com/secret_bank?name=%{lc:args.type}
method: GET
output:
response: 'Tell the user: %{array[0].joke}.'
action:
- toggle_functions:
- active: true
function: transfer
- active: false
function: get_joke
{
"sections": {
"main": [
{
"ai": {
"prompt": {
"text": "Your name is Frank. You help transfer to the right department. Use the 'get_joke' function to get a joke.\n# Greetings Greet the user, and inform them that your name is Frank and you can help assist them in transferring the call to Support or Sales. However, let them know the only way to be transferred is to hear a joke.\n# Rules A user cannot be transferred until they have asked for at least one joke throughout the call. When a user is able to be transferred, use the 'transfer' function. Only provide one joke to the user, if the user asks for more jokes after the first one, tell them you are no longer giving out jokes, but can help with transferring the call to a different department."
},
"post_prompt": "Summarize the call as a json object",
"post_prompt_url": "https://example.com/post_prompt",
"SWAIG": {
"functions": [
{
"function": "transfer",
"active": "false",
"purpose": "use to transfer to a target",
"argument": {
"type": "object",
"properties": {
"target": {
"description": "the target to transfer to",
"type": "string"
}
}
},
"data_map": {
"expressions": [
{
"pattern": "\\w+",
"string": "%{meta_data.table.%{lc:args.target}}",
"output": {
"action": [
{
"say": "Please stand by while I connect your call."
},
{
"SWML": {
"version": "1.0.0",
"sections": {
"main": [
{
"connect": {
"to": "%{meta_data.table.%{lc:args.target}}"
}
}
]
}
}
},
{
"stop": "true"
}
],
"response": "transferred, the call has ended."
}
},
{
"string": "%{args.target}",
"pattern": ".*",
"output": {
"response": "I'm sorry, I was unable to transfer your call to %{input.args.target}."
}
}
]
},
"meta_data": {
"table": {
"support": "+1XXXXXXXXXX",
"sales": "+1YYYYYYYYY"
}
}
},
{
"function": "get_joke",
"purpose": "used to get a joke",
"argument": {
"type": "object",
"properties": {
"type": {
"type": "string",
"description": "must either be 'jokes' or 'dadjokes'"
}
}
},
"data_map": {
"webhooks": [
{
"url": "https://example.com/secret_bank?name=%{lc:args.type}",
"method": "GET",
"output": {
"response": "Tell the user: %{array[0].joke}.",
"action": [
{
"toggle_functions": [
{
"active": true,
"function": "transfer"
},
{
"active": false,
"function": "get_joke"
}
]
}
]
}
}
]
}
}
]
}
}
}
]
}
}