Tool Calling (Function Calling)
OpenAI-Compatible Tool Calling
Captain supports OpenAI-compatible function calling, allowing your AI to use tools and execute code client-side. Tools are executed on the client side, giving you full control over security and data access.
Overview
Tool calling (also known as function calling) allows the AI model to request the execution of specific functions when it needs to perform actions like:
- ๐งฎ Calculations: Perform complex math operations
- ๐ Data Retrieval: Look up information from databases or APIs
- ๐ Data Processing: Transform or analyze data
- ๐ External APIs: Call third-party services
- ๐ File Operations: Read or write files (client-side)
How It Works
- Define tools with their parameters and descriptions
- Send request to Captain API with tools included
- Model decides if it needs to use a tool
- API returns tool call request (not executed yet)
- Client executes the tool locally
- Continue conversation with tool results (optional)
Client-Side Execution
Tools are never executed on Captainโs servers. The API only returns tool call requests - you execute them in your own environment with full control.
Quick Start
Python Example
JavaScript/TypeScript with Vercel AI SDK
Complete Examples
Python: Calculator Tool
TypeScript: Database Query Tool
Tool Calling with Context
Combine tool calling with Captainโs infinite context processing:
Python: Analyze Document with Tools
TypeScript: Search Documents with API Calls
Advanced Patterns
Multi-Step Tool Calling
Use Vercel AI SDKโs maxSteps for automatic multi-turn conversations:
Error Handling
API Reference
Tool Definition Format
Response Format
When the model wants to use a tool:
Parameters
Best Practices
1. Clear Tool Descriptions
2. Strict Parameter Schemas
3. Security Considerations
4. Handle Empty Arguments
Limitations
Current Limitations
- Multi-Turn Continuation: Sending tool results back for final answer requires frameworks like Vercel AI SDK with
maxSteps2. Model Parameter Extraction: Model may occasionally return empty/incomplete arguments (provide clear descriptions) 3. Server-Side Execution: Tools are client-side only - cannot execute on Captainโs servers
Framework Support
Troubleshooting
Tool Not Being Called
Empty Tool Arguments
Multi-Turn Issues
Next Steps
- API Reference - Complete API documentation
- Vercel AI SDK Guide - Framework integration
- Getting Started - Basic usage guide
Support
Need help with tool calling?
- ๐ง Email: support@runcaptain.com
- ๐ Documentation: docs.runcaptain.com
- ๐ Website: runcaptain.com