AI Tools (Function Calling)
Create AI tools that enable function calling, letting AI models access real-time data, perform calculations, and interact with your systems.
AI Tools enable AI models to call functions in your code, providing access to real-time data, external APIs, databases, and any other system integration.
📋 Table of Contents
🎯 What are AI Tools?
Tools are functions that you define and make available to AI models. When the AI needs information or wants to perform an action, it can call these tools:
User: "What's the weather in Boston?"
↓
AI: Determines it needs weather data → Calls your weather tool
↓
Your Tool: Fetches actual weather from API → Returns "72°F, Sunny"
↓
AI: "The weather in Boston is 72°F and sunny."🔄 Tool Execution Flow
🏗️ Tool Architecture
🔧 Creating Tools
Basic Tool
Using Tools
📝 Tool Definition
The aiTool() Function
aiTool() FunctionParameters:
name(string): The function name the AI uses to call the tooldescription(string): Explains what the tool does (AI uses this to decide when to call it)callback(function): Your function that executes when called
Describing Parameters
Use .describeArg() or the fluent .describe{ArgName}() pattern:
Multiple Parameters
⚙️ Tool Properties
Access tool properties:
💡 Common Tool Patterns
Database Query Tool
API Integration Tool
Calculator Tool
File Operations Tool
🔗 Multiple Tools
Provide multiple tools for complex tasks:
Multi-Tool Orchestration
Tools with Agents
Agents can use tools across multiple interactions:
Tools with Models
Bind tools to models for reuse:
Tool Execution Flow
When you provide tools, the AI:
Receives your message and available tools
Decides if a tool is needed based on the question
Calls the tool with arguments it determines
Receives the result from your function
Generates response using the tool result
Handling Tool Errors
Design tools to handle errors gracefully:
Advanced: Custom Schema
For complex parameter types, provide a custom schema:
Best Practices
1. Clear Descriptions
Good descriptions help the AI understand when to use tools:
2. Validate Input
3. Return Structured Data
4. Handle Missing Data
5. Keep Tools Focused
Provider Support
OpenAI
✅ Full
Best support, parallel tool calls
Claude
✅ Full
Excellent tool use
Gemini
🔜 Coming
In development
Ollama
✅ Model-dependent
Works with supported models
DeepSeek
✅ Full
Good support
Grok
✅ Full
Good support
Next Steps
Advanced Chatting - Tool examples with
aiChat()AI Agents - Using tools with autonomous agents
Working with Models - Binding tools to models
MCP Client - Connect to external tool servers
Last updated