Function Calling Guide for Aivoco Voice AI Agent
Overview
Function calling allows your AI agents to interact with external APIs and services during voice calls. When enabled, Rose can intelligently decide when to call functions, execute them asynchronously, and incorporate the results into the conversation naturally.Features
- Define custom functions per agent with API endpoints
- Automatic function execution via HTTP requests (GET, POST, PUT, DELETE)
- Rose continues conversation while function executes
- Support for multiple functions per agent
- Automatic cost tracking and billing
- Function validation and error handling
Cost Structure
For Admin
- 0.1 units per function call
- 5 units per 1000 Tokens (combined input + output parameters)
For Regular Users
- Dynamic via
cost_functionper minute in users table
Function Schema Format
Functions are stored in thefunctions JSONB field of the agents table:
Field Descriptions
Required Fields
- name: Function name (alphanumeric and underscores only)
- description: Clear description for Rose to understand when to use it
- api_url: Full URL to the API endpoint (must start with http:// or https://)
- method: HTTP method (GET, POST, PUT, DELETE, PATCH)
- parameters: OpenAPI-style parameter schema
Optional Fields
- headers: Custom HTTP headers (can include placeholders like
{param_name})
Parameter Schema
Theparameters field follows OpenAPI 3.0 schema format:
Example Use Cases
1. Weather Function
2. CRM Lookup Function
3. Appointment Booking Function
4. Database Query Function
API Usage
Creating an Agent with Functions
Updating Agent Functions
How It Works
1. Call Initiation
2. During Call
3. Cost Tracking
4. Call Completion
Best Practices
1. Function Naming
- Use descriptive, action-oriented names (e.g.,
get_weather,book_appointment) - Use snake_case (underscores)
- Avoid spaces and special characters
2. Descriptions
- Be very specific about what the function does
- Include examples in the description
- Mention any constraints or requirements
3. Parameters
- Use clear parameter names
- Provide detailed descriptions
- Use
enumfor fixed value sets - Mark required parameters correctly
4. API Design
- Ensure your API returns JSON responses
- Include proper error handling
- Set appropriate timeouts (max 30 seconds)
- Use authentication headers wisely
5. Cost Optimization
- Keep parameter and response sizes small
- Use efficient API endpoints
Validation Rules
The system validates function definitions:- Required fields: name, description, api_url, method, parameters
- Name: Alphanumeric and underscores only
- Method: Must be GET, POST, PUT, DELETE, or PATCH
- URL: Must start with http:// or https://
- Parameters: Must have a
propertiesfield
Error Handling
Common Errors
-
Invalid function definition
- Error: Missing required fields
- Solution: Ensure all required fields are present
-
HTTP timeout
- Error: Function timed out after 30 seconds
- Solution: Optimize your API or increase efficiency
-
API errors
- Error: HTTP 4xx/5xx responses
- Solution: Check API endpoint, authentication, parameters
Example Conversation Flow
User: “What’s the weather like in San Francisco?” AI: “Let me check the current weather in San Francisco for you.”[Calls get_weather function with location=“San Francisco”]AI: “While I’m getting that information, is there anything specific you’d like to know about the weather?”
[Function executing in background]AI: “The current weather in San Francisco is 68°F and sunny with light winds. Perfect weather for outdoor activities!”
[Function results received and incorporated]
Troubleshooting
Functions not being called
- Check function descriptions are clear and specific
- Verify system_message guides the AI to use functions
- Ensure parameters are well-defined
High costs
- Review parameter sizes
- Optimize API responses
- Consider caching frequently-used data
API failures
- Test API endpoints independently
- Check authentication headers
- Verify parameter types match API requirements
Advanced Usage
Multiple Functions
Define multiple functions for complex workflows:Parameter Placeholders in Headers
Use parameter values in headers:{api_key} and {user_id} with actual parameter values.
© 2025 AIVOCO | AIvoco Agents – Dynamic Voice Personas Powered by ROSE