Approval flow
requiresApproval on tool()
AddrequiresApproval: 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
WhenApprovalRequiredError 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:
deferred.requests to build your approval UI and construct the results array:
ExternalToolset
UseExternalToolset 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), provideargsOverride instead of result in the resume results:
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
| Symbol | Type | Description |
|---|---|---|
requiresApproval | boolean | Option on tool() - causes ApprovalRequiredError before execute runs |
ApprovalRequiredError | class | Thrown when a tool with requiresApproval: true is called; has .deferred property |
DeferredToolRequest | interface | { toolCallId: string, toolName: string, args: unknown } - one entry per pending tool call |
DeferredToolRequests | class | err.deferred; has .requests: DeferredToolRequest[] |
DeferredToolResults | interface | Argument to agent.resume() - { results: DeferredToolResult[] } |
DeferredToolResult | interface | { toolCallId: string, result?: unknown, argsOverride?: unknown } - provide one or the other |
agent.resume(deferred, results) | method | Resumes a paused run; returns Promise<RunResult<TOutput>> |
ExternalToolset | class | Toolset for client-side tools defined with JSON Schema; auto-sets requiresApproval: true |
ExternalToolDefinition | interface | { name: string, description: string, jsonSchema: object } |