tool() (with dependency injection), plainTool() (no context), outputTool() (terminal - ends the run), and fromSchema() (raw JSON Schema instead of Zod).
Tool execution pipeline
tool() - tools with dependencies
tool<TDeps>() is the full-featured factory. The execute function receives a RunContext<TDeps> as its first argument, giving it access to injected deps, token usage, the current run ID, and more.
plainTool() - simple tools
plainTool() is a simpler factory for tools with no side effects and no dependency injection requirements. The execute function receives only the validated args - no RunContext.
plainTool when your tool is a pure function: math, formatting, text transformation, or any computation that doesn’t need external resources.
outputTool() - terminal tools
outputTool() creates a tool that ends the run. When the model calls it, the tool’s return value becomes the agent’s final output and no further turns occur. Use this with outputMode: 'tool' for structured output that the model fills in via a tool call.
fromSchema() - raw JSON schema tools
fromSchema() builds a tool from a plain JSON Schema object instead of Zod. Use this when integrating with external schema registries, OpenAPI specs, or when Zod is overkill for a simple schema. Note: no TypeScript type inference is available for the args.
Tool options reference
All options accepted bytool():
| Option | Type | Required | Description |
|---|---|---|---|
name | string | yes | Tool name - must be unique within an agent |
description | string | yes | Describes the tool to the model |
parameters | ZodType | yes | Zod schema for the arguments |
execute | (ctx, args) => Promise<string | object> | yes | Implementation function |
argsValidator | (args) => void | Promise<void> | no | Cross-field validation - throw to reject without consuming a retry |
prepare | (ctx) => ToolDefinition | null | undefined | no | Per-turn availability check - return null to exclude this turn |
requiresApproval | boolean | (ctx, args) => boolean | no | When true, throws ApprovalRequiredError before execution |
sequential | boolean? | no | When true, acquires a run-level mutex so this tool never runs concurrently |
maxRetries | number? | no | Max retries on execution failure (independent of result validation retries) |
prepare - conditional tool availability
Theprepare function is called once per model turn before the tool list is sent to the model. Return null or undefined to exclude the tool from that turn’s available set:
prepare to dynamically change its description or parameters based on the current context.
Multi-modal returns
Toolexecute functions can return strings, plain objects, or multi-modal content (images and uploaded files). Vibes serializes the result into the message history automatically: