Skip to main content
The tool() factory and the toolset classes compose to cover a wide range of runtime requirements. This page documents five patterns that appear repeatedly in production agents.

Conditional tools with prepare

Every ToolDefinition accepts an optional prepare function. It runs once per model turn and returns either a (possibly modified) tool definition to include in the turn, or null/undefined to exclude the tool entirely.
prepare on a single tool differs from PreparedToolset (which operates over a full set) in that it targets exactly one tool and can mutate its description or parameters before the turn.
Return undefined (or nothing) from prepare to include the tool unchanged. Return a modified ToolDefinition to alter its name, description, or parameters for that turn. Return null to exclude it.

Tools returning multimodal content

Tool execute functions can return BinaryContent (raw bytes with a MIME type) in addition to strings and objects. The agent run loop converts the value to an AI SDK image content part and forwards it to the model in the next turn.
A common use case is a screenshot tool that returns an image the model can reason about:
Tools can also return an UploadedFile reference when the file has already been uploaded server-side:

Sequential tools for transactional operations

When the model issues multiple tool calls in a single response, Vibes executes them concurrently by default. Set sequential: true on a ToolDefinition to serialize those tools using a run-level mutex — no two sequential tools will run at the same time within one agent run.
sequential only serializes tools that also have sequential: true. Tools without this flag are unaffected and may run concurrently with each other — but not with a currently-executing sequential tool.

Composing toolsets for role-based access

Combine FilteredToolset, PrefixedToolset, and CombinedToolset to build role-based tool access without modifying underlying tool definitions.

Approval workflows

Two mechanisms exist for requiring human approval before a tool executes:

Per-tool approval with requiresApproval

Set requiresApproval on a ToolDefinition to require approval every time the model calls that tool. It accepts a static boolean or a conditional function:

Toolset-level approval with ApprovalRequiredToolset

Wrap any toolset to mark all its tools as requiring approval:

Handling ApprovalRequiredError

When the model calls an approval-gated tool, agent.run() throws ApprovalRequiredError. Inspect the pending requests, supply results, and call agent.resume():
DeferredToolResult accepts either result (inject a pre-computed value) or argsOverride (re-execute the tool with modified arguments):
For a complete walkthrough of human-in-the-loop patterns including UI integration, see Human-in-the-Loop.

Built-in Toolsets

Reference for all toolset classes

Tools

tool() factory, plainTool(), outputTool(), fromSchema()

Human-in-the-Loop

Full approval workflow and UI integration

Multimodal

Images, audio, files in messages and tool returns