ToolDefinition
Defines a tool available to an AI agent. This interface represents the metadata needed to describe a tool in a system prompt. It contains only the declarative information that an AI model needs to understand when and how to use the tool - it does NOT include execution logic. The separation of tool definition from execution follows the principle that system prompts are text sent to the model, while tool execution happens in your application runtime when the model requests to use a tool.Type Definition
Properties
Unique identifier for the tool. This name is used by the AI model to reference the tool when it decides to use it. Should be descriptive, snake_case, and unique within your toolset.Examples:
"get_weather", "search_database", "send_email"Human-readable description of what the tool does and when to use it. This description is shown to the AI model in the system prompt. It should clearly explain the tool’s purpose, what it returns, and any important usage guidelines. Be specific about when the model should choose this tool over others.
Zod schema defining the tool’s input parameters. This schema serves dual purposes:
- Documents the parameters in the system prompt (via introspection)
- Can be used at runtime to validate tool invocation arguments
.describe() on schema fields to provide parameter descriptions that will appear in the generated system prompt.Usage Example
When to Use
UseToolDefinition when you:
- Need to document tools in a system prompt without providing execution logic
- Want to separate tool descriptions from tool implementations
- Are building prompts for documentation purposes
- Plan to handle tool execution separately from prompt generation
ExecutableToolDefinition
Extended tool definition that includes execution logic for AI SDK integration. This interface extendsToolDefinition to include an optional execute function that implements the actual tool logic.
When tools include execution logic, they can be exported directly to Vercel AI SDK format using .toAiSdkTools() or .toAiSdk().
Type Definition
Properties
Inherited from
ToolDefinition. Unique identifier for the tool.Inherited from
ToolDefinition. Human-readable description of the tool’s purpose.Inherited from
ToolDefinition. Zod schema defining the tool’s input parameters.Execution function for the tool (optional). When provided, this function implements the actual tool logic. It receives the validated arguments (matching the schema) and returns the tool’s result.The function can be either synchronous or asynchronous (returning a Promise).
Usage Example
Integration with AI SDK
When to Use
UseExecutableToolDefinition when you:
- Want to combine tool documentation and execution in one place
- Are integrating with Vercel AI SDK or similar frameworks
- Need to export tools in a format ready for runtime execution
- Want the convenience of calling
.toAiSdk()to get both prompt and tools
Flexibility
The separation remains flexible:- Tools without
executeare used for documentation only (system prompt) - Tools with
executecan be used for both documentation and runtime execution