Add a Custom Function Tool with Bolna Voice AI Agents in Playground
You can design your own functions and use them in Bolna. Custom functions follow the OpenAI specifications .
You can paste your valid JSON schema and define your own custom function.
Screenshot of custom function call integration in Bolna Voice AI
Steps to write your own custom function
Make sure the key
is set as custom_task
.
Write a good description for the function. This helps the model to intelligently decide to call the mentioned functions.
All parameter properties must be mentioned in the value param as a JSON and follow Python format specifiers like below
Param Type Variable user_name
str
%(user_name)s
user_age
int
%(user_age)i
cost
float
%(cost)%f
More examples of writing custom function calls
Custom function for a GET request
curl
--location 'https://my-api-dev.xyz?customer_phone=+19876543210' \
--header 'Authorization: Bearer ***'
The above request corresponds to the following GET
custom function:
{
"name" : "get_product_details" ,
"description" : "Use this tool to fetch product details" ,
"parameters" : {
"type" : "object" ,
"properties" : {
"customer_phone" : {
"type" : "string" ,
"description" : "This is customer's phone number"
}
}
},
"key" : "custom_task" ,
"value" : {
"method" : "GET" ,
"param" : {
"customer_phone" : "%(customer_phone)s"
},
"url" : "https://my-api-dev.xyz" ,
"api_token" : 'Bearer ***'
}
}
Custom function for a POST request
curl --location 'https://my-api-dev.xyz/v1/store_rating' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer ***' \
--data '{
"customer_id": "134532",
"rating": "2.3"
}'
The above request corresponds to the following POST
custom function:
{
"name" : "save_feedback" ,
"description" : "Use this tool to save customer's feedback" ,
"parameters" : {
"type" : "object" ,
"properties" : {
"customer_id" : {
"type" : "string" ,
"description" : "This is customer's ID"
},
"rating" : {
"type" : "string" ,
"description" : "This is the rating provided by the customer"
}
}
},
"key" : "custom_task" ,
"value" : {
"method" : "POST" ,
"param" : {
"customer_id" : "%(customer_id)s"
"rating" : "%(rating)s"
},
"url" : "https://my-api-dev.xyz/v1/store_rating" ,
"api_token" : 'Bearer ***'
}
}
Using variables and dynamic context
All variables that are part of the agent prompt if included in custom function will be substituted automatically with their appropriate values. The model won’t enquire for these values since they’re already available.
You can check the following demonstration.
agent_prompt
custom_function
injected_call_params
final_custom_function
This is your agent Sam and you 're speaking to {customer_name}.
Please have a frienly conversation with the customer.
Please note:
The agent has a unique id which is "{agent_id}".
The call' s unique id is "{call_sid}" .
The customer 's phone number is "{to_number}".
Responses are generated using AI and may contain mistakes.