Agent Tool Approval, Human-in-the-Loop, and Durable Pause
When agent tools need human approval, how inline pause differs from durable pause, and how Actions, Code Mode, and MCP gates fit together.
This page summarises how Cloudflare Agents document tool approval and related human-in-the-loop (HITL) patterns, with overlapping guidance from the AI SDK needsApproval option, Perplexity Agent API MCP approvals, and Chrome WebMCP form guidance on when automated submission is appropriate. The common thread is simple: anything that pays, deletes, sends, or otherwise changes external state should pause until a human (or your policy layer) explicitly allows it.
When tool calls need human approval
Section titled “When tool calls need human approval”High-stakes operations should not run on the model’s word alone. Cloudflare’s Human-in-the-loop patterns tie approval to compliance, safety, quality, and user trust—for example financial approvals, bulk data changes, access-control updates, and side-effecting tool calls before they execute.
Chrome’s Agentic Forms guidance aligns on risk, using different vocabulary:
Read-Only Operations & Queries: Searches, filters, fetching details, or checking status (e.g., a car model search, searching a directory, checking stock availability).
Low-Risk, Reversible Actions: Form actions that can easily be undone or refined by the user manually (e.g., adding items to a cart, applying a coupon code, saving a draft, or setting temporary layout options).
Destructive or Irreversible Actions: Deleting records, resetting system configurations, or clearing databases.
Financial & Transactional Actions: Submitting a checkout form, transferring funds, authorizing subscription payments, or final order placements.
High-Impact User Communication: Submitting a final job application, sending emails/messages to other real users, or publishing public-facing content.
Sensitive Account Settings: Changing passwords, modifying user roles/permissions, or updating billing/profile info.
— Chrome, Agentic Forms
Common conclusion: read-only and easily reversible UI actions can auto-run; destructive, financial, outbound communication, and sensitive account changes should gate on explicit user confirmation—whether that is a form policy, needsApproval, an action() approval, or an MCP require_approval filter.
Cloudflare Chat agents describe three familiar tool patterns: server-side (API/DB), client-side (browser APIs via onToolCall), and approval (server execute only after confirmation—for payments, deletions, external actions).
Plain tool() versus action() for side effects
Section titled “Plain tool() versus action() for side effects”A plain AI SDK tool() from getTools() remains appropriate for read-only or trivial tools. Cloudflare Think action() is aimed at server tools where getting idempotency, approval, and authorization wrong is costly:
Actions are server-side tools with batteries included. Where a plain AI SDK tool() is just a description, a schema, and an execute function, an action() adds the things that are tedious and dangerous to get right by hand for a tool that has real side effects:
Idempotency — a durable ledger replays a settled result by a stable key instead of re-running the side effect on a recovery retry. Approvals — gate a call behind a human, either inline (the turn waits) or durably (the turn parks and resumes later, even from a dashboard with no live socket). Authorization — declare the permissions a call requires and grant them per-turn. Reply attachments — record advisory delivery metadata (a drafted email, a card, a voice note) without changing what the model sees.
Actions compile into Think tools, so the model calls them exactly like any other tool. Return them from getActions(); Think merges them into the tool set alongside getTools(), workspace tools, extensions, and MCP tools.
— Cloudflare, Actions
A plain tool() from getTools() still works and is the right choice for a read-only or trivial tool. Reach for action() when a tool has side effects you must not run twice, needs human approval, or needs declarative authorization — the ledger, approval descriptors, default timeout, and structured error mapping only apply to actions.
— Cloudflare, Actions
| Concern | Plain tool() in getTools() |
action() in getActions() |
|---|---|---|
| Idempotent replay on retry | Not built in | idempotencyKey + ledger |
| Human gate | needsApproval (client flow) |
approval + kind |
| Permissions | Ad hoc in execute |
permissions + authorizeTurn / authorizeAction |
| Long waits without open socket | Limited | kind: "durable-pause" |
needsApproval: inline pause in the chat turn
Section titled “needsApproval: inline pause in the chat turn”For AIChatAgent and Think getTools(), set needsApproval on server tools so the stream stops until the client approves. The Agents SDK v0.3.0 changelog shows conditional approval from input:
processPayment: tool({ description: "Process a payment", inputSchema: z.object({ amount: z.number() }), needsApproval: async ({ amount }) => amount > 100, execute: async ({ amount }) => charge(amount)})Think documents the same pattern for path-sensitive deletes in Tool approval:
When needsApproval returns true, the tool call is sent to the client for approval. The conversation pauses until the client responds with CF_AGENT_TOOL_APPROVAL.
— Cloudflare, Tools
On the client, render parts in approval-requested (or waiting-approval) state and call addToolApprovalResponse. The Chat agent example walks through approving a high calculate call before server execute runs.
Custom denial reasons
Section titled “Custom denial reasons”If the user rejects a tool, addToolApprovalResponse with approved: false yields a generic denial. For a specific reason the model can use, Chat agents recommend addToolOutput with state: "output-error" and errorText—note that this path does not auto-continue the turn unless you call sendMessage() afterward.
action() approval: approval-gated versus durable-pause
Section titled “action() approval: approval-gated versus durable-pause”Think action() offers two approval mechanisms (Actions):
Approval-gated (turn waits on the connection)
Section titled “Approval-gated (turn waits on the connection)”Default when approval is set without kind. The action compiles to a tool with the AI SDK needsApproval flag: the stream pauses, the client approves or rejects, and execute runs only after approval.
approval may be a boolean or predicate ({ input, ctx }) => boolean. approvalSummary and approvalRisk ("low" | "medium" | "high") populate the ActionApprovalDescriptor for your UI.
Durable-pause (turn parks; resume later)
Section titled “Durable-pause (turn parks; resume later)”Use kind: "durable-pause" when approval may take minutes or days. The turn ends; execute does not run until you call approveExecution(executionId) or rejectExecution(executionId, reason?)—including from a dashboard with no live WebSocket.
approveExecution() runs execute once and auto-continues the turn even if no client is connected; rejectExecution() resolves the action without running it. pendingApprovals() merges parked actions and paused Codemode executions, so a single approval UI can drive both. (durable-pause requires an approval policy — an action that would never park is rejected at definition time.)
— Cloudflare, Actions
Agent helpers from the same page include pendingApprovals(), approveExecution(), rejectExecution(), and replyAttachments(). Approval calls are idempotent—a second approve is a no-op.
Code Mode and connector requiresApproval
Section titled “Code Mode and connector requiresApproval”Inside the Code Mode durable runtime, approval is not the same as per-call AI SDK UI approval. ToolSetConnector maps needsApproval to the runtime’s requiresApproval annotation and pauses the run; you resume with runtime.approve({ executionId }).
Important constraints from the cluster:
| Integration | Approval behavior |
|---|---|
| ToolSetConnector | Function-valued needsApproval cannot be evaluated before the sandbox supplies arguments, so the connector always treats the tool as requiring approval. needsApproval: false runs without pausing. |
| Browser Code Mode | createBrowserCodeTool() excludes tools whose needsApproval is true or a function—keep approval-gated tools as standard tools and use the useAgentChat() approval flow. |
TanStack createCodeTool() |
Does not pause for TanStack approvals; tools with needsApproval true or a function are excluded from the sandbox descriptor. |
| Code Mode MCP server | codeMcpServer() does not provide durable approval per upstream call—enforce authorization and per-operation approval inside each upstream handler. |
Code Mode API reference defines ConnectorTool with requiresApproval?: boolean. requiresApproval: true pauses before execution; requiresApproval and replay: "reexecute" cannot be combined.
For sandbox pauses, Think Tools notes: render approval cards from pendingExecutions(), not truncated paused output in the transcript—full args (up to 1 MB) are authoritative for what runs on approve.
Workflow and MCP approval layers
Section titled “Workflow and MCP approval layers”HITL patterns place the pause at different layers:
| Pattern | Where it pauses | Typical wait |
|---|---|---|
| MCP elicitation | MCP request in your agent client | Minutes |
| Workflow approval | Durable task via waitForApproval() |
Months or longer |
| Code Mode approval | Connector call in generated code | Until configured expiry |
Workflows suit operations that must outlive a single chat connection; set explicit timeouts (for example "7 days") and escalate or auto-reject when they expire—see Human-in-the-loop patterns.
Perplexity Agent API gates MCP tools with require_approval on the tool definition (MCP tools):
By default, Agent API runs MCP tool calls without approval. Set require_approval to review calls before they run.
A call that needs approval creates an mcp_approval_request item in the response output, and the tool does not run. Review the requested tool and its arguments, then send an mcp_approval_response item in a new request.
— Perplexity, MCP
Values include omitted/"never", "always", or a filter object (never / always with tool_names and/or read_only from server annotations). The changelog notes the same for connector tools. Follow-up requests must include the same tools array, previous_response_id (unless Zero Data Retention), and one mcp_approval_response per pending request—decide in your backend, not an untrusted browser (Review calls safely).
Perplexity’s Decisions API recipe adds a policy check on custom functions after the run pauses; built-in tools such as web_search are not visible to that gate—route consequential work through gated custom functions or MCP approvals.
Client-side tools and approval
Section titled “Client-side tools and approval”Server-defined tools without execute route to the browser (onToolCall). That is independent of approval policy: you can still set needsApproval on server tools that execute on the server after approval. For dynamic browser-only surfaces, Client tools notes that most apps should define schemas on the server and handle execution with onToolCall; passing client tools into useAgentChat suits runtimes where the browser defines the tool surface.
Long-running server tools can stream preliminary results with async generator execute (Chat agents)—orthogonal to approval, but useful so users see progress while waiting on a later gated step.
Common mistakes
Section titled “Common mistakes”- Double-running side effects on retry—use
action()idempotency keys or Code Mode replay semantics instead of bareexecutefor payments and deletes. - Putting
needsApprovaltools inside browser Code Mode—they are excluded; register them as normal tools (Browser integration). - Approving from truncated sandbox output—fetch full pending args via
pendingExecutions(executionId)before enabling Approve (Think Tools). - Trusting MCP
read_onlyannotations alone—Perplexity documents that servers setread_only; it does not guarantee no side effects (MCP). - Empty
neverfilter—{"never": {"tool_names": []}}matches every tool and disables approval for all MCP calls on that server. - Forwarding
mcp_approval_requestitems to untrusted clients—make the decision server-side.
How to check this on your site
Section titled “How to check this on your site”- Run your agent locally per Chat agent (
npx wrangler types,npm run dev) and confirm server tools run, client tools return viaonToolCall, and aneedsApprovaltool shows an approval UI beforeexecute. - For Think
action()withkind: "durable-pause", callpendingApprovals()after parking and verifyapproveExecution(executionId)runsexecuteonce and continues the turn without an active client (Actions). - If you use Code Mode, confirm gated connectors use
requiresApprovalandruntime.approve({ executionId })per AI SDK integration, and that browser sandboxes excludeneedsApprovaltools per Browser integration. - For Perplexity MCP, send a request with
require_approval: "always", inspectmcp_approval_requestin the response, and complete the flow withmcp_approval_responseand matchingtools(MCP). - You can check automatically in Answerwell (our tool): https://answerwell.org/workspace
Report an error or ask a question
Section titled “Report an error or ask a question”If something on this page is wrong or unclear, email yimasynthetic@gmail.com with the page URL and the exact statement you are asking about, and we will correct or clarify it.