Skip to main content
Human-in-the-loop (HITL) lets you pause an agent run before a sensitive tool executes, ask a human for approval, then resume the run with the decision. Use it whenever an action is irreversible, high-risk, or requires accountability - deleting records, sending emails, making purchases, or executing code on behalf of a user.

Approval flow

requiresApproval on tool()

Add requiresApproval: true to any tool definition. The framework will throw ApprovalRequiredError before calling execute, giving your application a chance to intercept the call and ask for human approval.

DeferredToolRequests

When ApprovalRequiredError is thrown, err.deferred is a DeferredToolRequests object. Its requests array contains one entry for each tool the model called simultaneously. Each entry is a DeferredToolRequest:
Iterate over deferred.requests to build your approval UI and construct the results array:

ExternalToolset

Use ExternalToolset when tool execution happens client-side and you have a raw JSON Schema instead of a Zod schema. ExternalToolset automatically sets requiresApproval: true on every tool - the intent is always to throw ApprovalRequiredError, let the client execute the tool, then resume with the result.
ExternalToolset vs requiresApproval: true on tool()Use requiresApproval: true on tool() when you have a Zod schema and a server-side execute function, but want human approval before it runs.Use ExternalToolset when tool execution happens client-side/externally and you have a raw JSON Schema instead of Zod. ExternalToolset sets requiresApproval: true automatically.

Approving with modified args

To re-run a tool with different arguments (for example, letting a human correct a filename before proceeding), provide argsOverride instead of result in the resume results:
When argsOverride is present, the framework re-invokes the tool’s execute function with the new arguments. When result is present, the framework injects it directly as the tool result without calling execute.

API reference


Tools

Define tools with Zod schemas and execute functions

Toolsets

Group tools into reusable toolsets including ExternalToolset