What are Tools?
A tool is a function that an AI model can choose to call during generation. The model:- Analyzes the user’s request
- Decides which tool(s) to use
- Calls the tool(s) with appropriate arguments
- Incorporates the tool results into its response
Defining Tools
How Tool Calling Works
The tool execution flow:- User sends prompt: “What’s the weather in Paris?”
- Model analyzes prompt and available tools
- Model decides to call
getWeatherwith{city: "Paris"} - Genkit executes the tool function
- Tool returns
{temperature: 72, conditions: "Sunny", humidity: 65} - Model incorporates result into its response
- Model returns: “The weather in Paris is currently sunny…”
Multiple Tools
Provide multiple tools for the model to choose from:Tool Choice Strategies
Control how the model uses tools:Tool Interrupts (Human-in-the-Loop)
Interrupts let you pause tool execution for human approval - perfect for sensitive operations like financial transactions or data deletion.Interrupt Flow
Max Turns (Limiting Tool Iterations)
Prevent infinite tool calling loops:Return Tool Requests Without Execution
Inspect what tools the model wants to call without executing them:- Debugging tool selection
- Custom tool execution logic
- Rate limiting
- Logging/auditing
Tool Best Practices
1. Write Clear Descriptions
The model uses descriptions to decide when to call tools:2. Use Detailed Schema Descriptions
3. Handle Errors Gracefully
Tools should return user-friendly error messages:4. Use Interrupts for Sensitive Actions
Always useinterrupt=True for:
- Financial transactions
- Data deletion
- Sending emails/messages
- Modifying user data
- External API calls with side effects
5. Keep Tools Focused
Each tool should do one thing well:Real-World Example: Travel Agent
Next Steps
- Learn about Flows - building multi-step workflows with tools
- Explore Prompts - using tools in prompt templates
- See Observability - tracing tool executions