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
Toolexecute 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.
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. Setsequential: 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.
Composing toolsets for role-based access
CombineFilteredToolset, 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):
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