Define a tool
Create a file intools/:
"get-weather" (hyphens from the filename are preserved).
How agents use tools
When you add a tool to an agent, the framework sends the Zod schema to the model. The model decides when to call the tool and provides the parameters:- Sends the question to the model
- The model calls
getWeather({ city: "Tokyo" }) - The tool returns
{ temperature: 22, conditions: "sunny" } - The model formats a natural language response
Tool configuration
| Property | Type | Description |
|---|---|---|
description | string | What the tool does (shown to the model) |
inputSchema | z.ZodSchema | Zod schema for input validation |
execute | (params) => Promise<unknown> | Function that runs when the tool is called |
id | string | Override the auto-generated ID |
Returning errors
Throw fromexecute to signal an error. The agent sees the error message and can retry or respond accordingly:
Tools with context
Tools can access the request context when executed during an API route:Inline tools
For one-off tools that don’t need auto-discovery, define them inline:Next
- Memory & Streaming: persist conversations across requests
- MCP Server: expose tools over Model Context Protocol
Related
veryfront/tool: tool API reference