Defining a tool
- TypeScript
- Go
- Python
inputSchema and outputSchema are Zod schemas. The descriptions are passed to the model so it knows when and how to call the tool.Passing tools to generate()
Pass tools to generate() using the tools option. The model will call tools as needed and Genkit will automatically run the tool implementations, send results back to the model, and continue until the model produces a final text response.
- TypeScript
- Go
- Python
Automatic multi-turn loop
Genkit handles the full tool call/response loop for you:- You call
ai.generate()with a prompt and tools. - The model returns a tool call request instead of a final answer.
- Genkit invokes the tool implementation with the model’s arguments.
- The tool’s output is sent back to the model as a tool response.
- The model uses the tool output to produce its final response.
- Steps 2–5 repeat until the model returns a final text response.
generate() returns only after the model has produced its final response. You don’t need to write any polling or loop logic.
The default maximum number of tool-call iterations is 5. You can change this via the
maxTurns option in TypeScript (config.maxTurns) or the ToolConfig.MaxTurns field in Go.Tool choice
Control whether the model is required to use a tool with thetoolChoice option:
Real-world example: web search agent
Here is a more complete example combining multiple tools in a flow:Using tools with prompts
Tools can also be declared in Dotprompt files:Dynamic tools
For tools that should not be registered in the global registry (for example, tools created per-request), useai.dynamicTool() (TypeScript):
Next steps
Agents
Build multi-step autonomous agents using tools.
Prompts
Declare tools inside .prompt files.
Models
Learn about all generate() options.
Flows
Wrap tool-using logic in observable, deployable flows.
