Documentation Index
Fetch the complete documentation index at: https://concentrate.ai/docs/llms.txt
Use this file to discover all available pages before exploring further.
Overview
Tool calling (also known as function calling) enables AI models to request the execution of external functions and tools. Instead of trying to generate structured data directly, the model can indicate it wants to call a function with specific parameters, your code executes the function, and then you send the result back to continue the conversation. Use tool calling when you need to:- Access real-time data (weather, stock prices, databases)
- Perform calculations or data processing
- Interact with external APIs and services
- Execute actions on behalf of users (send emails, create calendar events)
- Retrieve information the model doesn’t have in its training data
Prerequisites
Before using tool calling, ensure you have:- A Concentrate AI API key (get one here)
- A model that supports tool calling (refer to the models endpoint to see models that support tool calling)
- An understanding of JSON Schema for defining function parameters
Quick Start
Here’s a basic example of tool calling with a weather function:Defining Tools
Each tool is defined using theFunctionTool schema. Here are the properties:
| Property | Type | Required | Description |
|---|---|---|---|
type | string | Yes | Must be "function" |
name | string | Yes | Function name (alphanumeric, underscores, dots, hyphens only) |
description | string | No | Clear description of what the function does |
parameters | object | Yes | JSON Schema defining the function’s parameters |
strict | boolean | No | Enable strict schema validation (default: true) |
cache_control | object | No | Cache this tool definition for better performance |
Tool Name Pattern
Tool names must match the pattern:^[a-zA-Z0-9_.-]+$
Valid names:
get_weathersend_emailuser.get_profilecalculate-sum
get weather(contains space)send@email(contains @)
Parameters as JSON Schema
Theparameters field uses JSON Schema to define the function’s inputs. This helps the model understand what data to provide.
- Always include
descriptionfields to help the model understand the purpose - Use
enumfor fields with fixed options - Mark essential parameters in the
requiredarray - Keep schemas simple and focused on the task
Strict Mode
By default,strict: true is enabled. This ensures the model’s output strictly follows your schema.
strict: true, the model will only include name and email in its output—no additional properties. Set strict: false if you don’t want to enforce additionalProperties.
Cache Control
Cache tool definitions to improve performance and reduce costs:Tool Choice Modes
Control which tools the model can use with thetool_choice parameter:
None - Disable Tool Calling
Auto - Let Model Decide (Default)
Required - Force Tool Use
Specific Tool - Force Specific Function
Allowed Tools - Limit to Subset
mode can be:
"auto"- Model can use these tools or skip them"required"- Model must use at least one of these tools
Parallel Tool Calls
Enable the model to call multiple tools simultaneously:- Multiple independent operations (e.g., get weather for multiple cities)
- No dependencies between tool calls
- Want faster results through parallelization
- Sequential operations where order matters
- Tool calls depend on each other’s results
- Want more predictable, step-by-step execution
Multi-Turn Workflow
Tool calling typically follows this pattern:- User sends a message with tools available
- Model responds with function_call indicating it wants to use a tool
- You execute the function in your application
- You send the result back with
function_call_output - Model provides final response using the tool result
Streaming with Tools
When streaming is enabled, tool calls are delivered incrementally:Event Types
response.function_call_arguments.delta- Incremental tool arguments as they’re generatedresponse.function_call_arguments.done- Complete tool call with final arguments
Example
TypeScript - Streaming Tool Calls
Advanced Patterns
Error Handling
When a tool execution fails, use theis_error flag:
Caching Tool Definitions
For frequently used tools, cache their definitions:Provider Support
Tool calling is supported across all major providers:| Provider | Supported | Notes |
|---|---|---|
| OpenAI | ✅ Yes | Full support including parallel calls |
| Anthropic | ✅ Yes | Full support with Claude models |
| Azure OpenAI | ✅ Yes | Same as OpenAI |
| AWS Bedrock | ✅ Yes | Supported on compatible models |
| Google Vertex AI | ✅ Yes | Supported on Gemini models |
| Cohere | ✅ Yes | Supported on Command models |
| Mistral | ✅ Yes | Supported on recent models |
Best Practices
Schema Design
- Keep it simple - Only include necessary parameters
- Clear descriptions - Help the model understand what each field does
- Use enums - For fields with fixed options
- Validate inputs - Always validate tool arguments before execution
- Handle errors gracefully - Return meaningful error messages
Security Considerations
- Validate all inputs - Never trust model-generated arguments blindly
- Limit permissions - Tools should have minimal necessary permissions
- Rate limiting - Implement rate limits on expensive operations
- Audit logs - Log all tool executions for monitoring
- Sanitize outputs - Clean tool results before sending back to model
Performance Optimization
- Cache definitions - Use
cache_controlfor frequently used tools - Parallel calls - Enable when tools are independent
- Lazy loading - Only load tools when needed
- Timeout handling - Set reasonable timeouts for tool execution
- Batch operations - Combine multiple related calls when possible
Troubleshooting
Model doesn’t call the tool
Problem: Model responds with text instead of calling the tool. Solutions:- Make the tool description clearer and more specific
- Use
tool_choice: "required"to force tool usage - Ensure the user’s input clearly requires the tool’s functionality
- Check if the model supports tool calling
Invalid arguments
Problem: Model provides incorrect or incomplete arguments. Solutions:- Add detailed descriptions to parameter fields
- Use
strict: trueto enforce schema validation - Include examples in parameter descriptions
- Mark essential fields as
required
Tool not found error
Problem:"Tool 'xyz' not found" error.
Solutions:
- Verify tool name matches exactly (case-sensitive)
- Ensure tool name follows the pattern:
^[a-zA-Z0-9_.-]+$ - Check that tools array is included in the request
Streaming issues
Problem: Tool calls not appearing in streaming mode. Solutions:- Listen for
response.function_call_arguments.deltaand.doneevents - Buffer the arguments until the
.doneevent - Check that
stream: trueis set in the request
Related Pages
Create Response
Main API endpoint for generating responses
Request Parameters
Complete parameter reference
Streaming
Real-time response streaming
Prompt Caching
Cache tool definitions for better performance