Skip to main content

Functions

Function calling improves Voice Bots by enabling them to connect with other tools and systems. This feature greatly boosts what your AI assistant can do, making it better suited to your specific needs.

Here are some examples of how function calling can be used:

  • Data Retrieval: If a user asks about their recent orders, the AI assistant can pull the latest customer information from an internal system and provide a response.

  • Action Execution: The AI assistant can help schedule meetings efficiently by considering user preferences and calendar availability.

  • Workflow Automation: For example, it can take unstructured text, convert it into a structured format, and save it in a database for future use.

Lifecycle

Understanding the lifecycle of function calling is essential to effectively integrate your services with the Voice Bots Service. Here’s how it works:

Configuration

Proper configuration is key for function calling and smooth interaction with your services.

Giving clear and simple instructions can help the model work better. For example, you can tell the model to "Use check_order_status when the user asks about their order, like 'Where is my order?' or 'Has my order shipped?'"

If the situation is more complicated, it's good to provide some background. For example, you might say, "Before you set up a meeting with schedule_meeting, first use check_availability to see if the user is free, so you don't have any scheduling problems."


Function Name

A clear and concise function name, along with a well-defined description, helps the AI model understand its purpose, ensuring correct usage and reducing mistakes.

Good Examples: get_weather_forecast, schedule_meeting, update_contact_information

Bad Examples: do_it, function123, process_request


Function Description

A clear function description helps the AI model understand its purpose and context, reducing errors.

Good Examples:

  • Retrieves the current weather forecast for a specified location.
  • Schedules a meeting based on the user's preferred date, time, and attendees.
  • Books a flight ticket using the provided destination, departure date, and passenger information.
  • Checks and returns the user's current account balance and recent transactions.
  • Updates the user's contact information in the customer database.

Bad Examples:

  • Gets data.
  • Performs an action.
  • Processes information.
  • Handles user input.
  • Executes a task.

Parameters

Parameters are the inputs that a function requires to perform its task. Defining parameters explicitly ensures that the AI model can provide the necessary data when invoking the function.

Parameters are defined as an object with properties, each representing a parameter.

For the function schedule_meeting, the parameters might be:

Parameters Definition
{
"type": "object",
"properties": {
"date": {
"type": "string",
"description": "The date of the meeting in YYYY-MM-DD format."
},
"time": {
"type": "string",
"description": "The time of the meeting in HH:MM format."
},
"attendees": {
"type": "array",
"items": {
"type": "string"
},
"description": "A list of email addresses of the attendees."
},
"location": {
"type": "string",
"description": "The location of the meeting."
},
"agenda": {
"type": "string",
"description": "The agenda for the meeting."
}
},
"required": ["date", "time", "attendees"]
}

When a user says, “Please schedule a meeting tomorrow at 10 AM with John and Sarah,” the model extracts the parameters:

Request Body
{
"date": "2023-09-02",
"time": "10:00",
"attendees": ["john@example.com", "sarah@example.com"],
"location": null,
"agenda": null
}

These parameters will be included in the request to your service.


Pipeline

The pipeline determines how the Voice Bots Service interacts with your server during a function call. It defines whether the AI assistant waits for a response before replying to the user or proceeds immediately.

  • Use Blocking Request when the user’s response depends on data from your server.
  • Use Async Request when the action can be performed without delaying the user’s experience.
  • Use Guided versions when you need to control the assistant’s response more precisely.

1. Blocking request

The AI assistant waits for the server’s response before generating a reply to the user. It is optimal when the user’s response depends on real-time data from your server.

Use Case: A user asks for their account balance, and the assistant fetches the latest balance from your server before replying.

2. Blocking request guided

Similar to 'Blocking request', but this option lets you give clear instructions on how you want it to handle the results. You can also use the {{response}} template, which will be filled in with the response from your server.

Example: Inform the user that their order status is {{response}} and ask if they need further assistance.

3. Async request

This variant is optimal when the action can be performed in the background and immediate feedback is not required. The AI assistant assumes the request will be completed successfully and does not wait for a server response before replying to the user.

Use Case: An assistant needs to send a confirmation email to the user after booking an appointment. This operation can be executed in the background, allowing the user to continue without having to wait while the system sends the email or performs any other functions.

4. Async request guided

Similar to 'Blocking request', but this option lets you give instructions on how you want the model to reply to the user.

Example: Tell the user that their meeting has been scheduled and they will receive an email confirmation shortly.

Limitations

Response Length

The server's response should be no longer than 20,000 characters. If responses go over this limit, they may be cut off, and extra information will not be taken into account by the model.

Make sure to keep answers short, focusing on what is really needed.

Request Duration

If your server does not respond within 10 seconds, the request is considered failed, and the function result is treated as an error. The user may receive an error message or a generic response from the assistant.

Optimize your server to respond quickly, ideally within a second. Use background processing or a task queue on your side to handle long-running tasks.