Skip to main content
Tools give AI models the ability to call functions, enabling them to interact with external systems, access real-time data, and perform complex operations beyond text generation.

What are Tools?

A tool is a function that an AI model can choose to call during generation. The model:
  1. Analyzes the user’s request
  2. Decides which tool(s) to use
  3. Calls the tool(s) with appropriate arguments
  4. Incorporates the tool results into its response
This enables agentic workflows where the model acts autonomously to solve problems.

Defining Tools

How Tool Calling Works

The tool execution flow:
  1. User sends prompt: “What’s the weather in Paris?”
  2. Model analyzes prompt and available tools
  3. Model decides to call getWeather with {city: "Paris"}
  4. Genkit executes the tool function
  5. Tool returns {temperature: 72, conditions: "Sunny", humidity: 65}
  6. Model incorporates result into its response
  7. 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:
Default is typically 5 turns. Each turn = model call + tool execution(s).

Return Tool Requests Without Execution

Inspect what tools the model wants to call without executing them:
Useful for:
  • 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 use interrupt=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