翻篇收录说明
翻篇网页快照

Human-in-the-Loop – eve

https://eve.dev/docs/human-in-the-loop

最近抓取:2026-12-01 23:43:01(北京时间)

最近内容变化:2026-12-01 23:43:01(北京时间)

这是最近一次有效抓取的文本快照,不含网页脚本、图片和动态交互内容。实际网页可能已更新。

访问原网页

页面简介

Pause a run for a person — gate a tool on approval or have the agent ask a question — and resume durably when they answer.

正文摘录

ToolsMenuHuman-in-the-LoopCopy for LLMView MarkdownAsk AI about this pageHuman-in-the-loop (HITL) is any point where the agent pauses and waits for a person. Two things cause a pause: Approvals: a tool's approval policy allows, denies, or holds a call for a person to review. Questions: the agent asks the user a clarifying question or a choice in the middle of a turn. The turn stays open and the stream reports turn.paused. The wait survives process restarts, so it can last seconds or days. When the answer arrives, the run continues where it stopped. Approvals Set approval on a tool, including a workflow tool, to check each call before it runs. Use the helpers from eve/tools/approval: agent/tools/refund_charge.tsimport { defineTool } from "eve/tools"; import { auto } from "eve/tools/approval"; import { z } from "zod"; export default defineTool({ description: "Refund a charge.", inputSchema: z.object({ tenantId: z.string(), chargeId: z.string(), amount: z.number() }), approval: auto(), // or always() / once() / never() / a policy async execute(input) { return refund(input); }, }); HelperBehaviornever()Never require approval (the default when omitted).once()Remember approval for this tool for the rest of the session.always()Require approval before every call.auto()Ask a decision model whether to run the exact call or require user approval.steered()Ask the caller when other people's messages joined the running turn. Rules: A call that waits for approval hasn't started, and a denied call never runs. Other calls from the same model response that need no approval run while it waits. Omitted approval behaves like never(), so tool calls run without human approval by default. Require human approval or other safeguards for sensitive, irreversible, regulated, financial, healthcare, employment, housing, legal, safety-impacting, user-impacting, or external side-effecting actions. An agent-wide policy can add a gate to any call, including one whose tool omits approval. Approval doesn't make a charge or email happen exactly once. Give non-idempotent side effects their own idempotency keys. Approval is consent only. The approved call, its policy recheck, and the rest of the turn run with the requesting user's identity, connections, and credentials, never the approver's. See Act as the approver. Let a decision model review calls auto() sends each call to an AI SDK decision model, which classifies it as clear or caution. A clear call runs. A caution, a failed review, or incomplete input requires user approval. The tool name and input go to the decision model's provider. Omit model to use typesafe-ai/jev, TypeSafe AI's Jev decision model. As with decide, a model string uses Vercel AI Gateway unless the application configures a global AI SDK default provider: approval: auto({ model: "typesafe-ai/jev" }); Override the classifier text for an application-specific policy: approval: auto({ model: "typesafe-ai/jev", instructions: "Review whether this refund needs finance approval.", criteria: { clear: "The refund can proceed automatically.", caution: "A person must review the refund.", }, }); A dynamic tool rebuilds its policy each time eve evaluates the tool. To keep external data that configures a policy, save it with ctx.memo(). Pass modelOptions.providerOptions to configure the decision call, for example to keep it on Gateway providers with zero data retention: approval: auto({ modelOptions: { providerOptions: { gateway: { zeroDataRetention: true } } }, }); Customize the approval prompt Use the object form of approval to replace the default Approve <tool label>? text. The prompt callback receives the validated input, final toolName, and callId: agent/tools/refund_charge.tsimport { defineTool } from "eve/tools"; import { always } from "eve/tools/approval"; import { z } from "zod"; export default defineTool({ description: "Refund a charge.", inputSchema: z.object({ chargeId: z.string(), amount: z.number() }), approval: { request: always(), prompt: ({ input }) => `Refund $${input.amount.toFixed(2)} for charge ${input.chargeId}?`, }, async execute(input) { return refund(input); }, }); Channels show this prompt in their approval UI. Slack shows it as the title of one approval card that also lists the tool input, one field per line and shortened to a fixed size, above the Approve and Deny buttons. Write your own policy When the decision depends on the input, pass a function. It receives session, the same as ctx.session in execute, plus { toolName, toolInput, callId, abortSignal }. Connection tools also get toolAnnotations. This policy denies cross-tenant calls, then requires approval only above an amount: approval: ({ session, toolInput }) => { const callerTenant = session.auth.current?.attributes.tenantId; if (callerTenant === undefined || callerTenant !== toolInput?.tenantId) { return { type: "denied", reason: "Caller cannot access this tenant." }; } return (toolInput?.amount ?? 0) > 1000 ? "user-approval" : "not-applicable"; }, The policy returns an ApprovalStatus, directly or as a promise: ReturnResult"user-approval" or truePause for a person."not-applicable" or falseContinue without a prompt."approved"Run the call without a person."denied"Deny the call without a person.{ type: "denied", reason }Deny the call and give the model reason. When you write a policy: Pass abortSignal to asynchronous work, so the work stops with the turn. Check session.auth.current for the caller of the current turn, or session.auth.initiator for the caller that started the session. Handle a toolInput of undefined. A denied call never starts, including when the policy denies an approved call on its recheck. Its call.settled event has outcome: "rejected", cause: { policy: "approval" }, and a TOOL_EXECUTION_DENIED output. A tool that runs and throws ends with outcome: "failed" instead. The call.started event records what let the call run in clearedBy: Cleared byclearedByA policy returning "approved"{ policy: "approval" }A remembered once() approval{ policy: "approval" }A person{ interactionId }Nothing, because the call needed no approvalomitted The Approval, ApprovalConfiguration, ApprovalContext, ApprovalPolicy, and ApprovalStatus types are exported from eve/tools/approval. Gate every call from one policy Set approval in agent.ts to apply one policy to every call the model makes: your tools, built-in and extension tools, dynamic and workflow tools, connection tools, and subagents. It's an ordinary approval policy, so the helpers above work: agent/agent.tsimport { defineAgent } from "eve"; export default defineAgent({ model: "anthropic/claude-sonnet-4.6", approval: ({ toolName, toolAnnotations }) => { if (toolName.startsWith("billing__")) return "user-approval"; if (toolAnnotations?.destructiveHint === true) return "user-approval"; return undefined; // leave the tool's own decision }, }); For each call, eve runs this policy and the tool's own approval and keeps the stricter result: denied, then user approval, then approved. The agent's policy can add a gate but never remove one, and undefined leaves the tool's decision. When both ask, the tool's prompt and response policy apply. A plain "user-approval" from the agent's policy asks on every call, like always(), even for a tool whose once() a person already approved. To let one approval cover the rest of the session, return once()'s status from the agent's policy; it shares the tool's once() memory: import { once } from "eve/tools/approval"; const askOnce = once(); // ... approval: (ctx) => (ctx.toolAnnotations?.destructiveHint === true ? askOnce(ctx) : undefined), auto() works here too, but it runs a decision model before every call, including reads, and asks a person when the model errors, times out, or the input is over 64 KB. A direct invokeTool call it would ask about is rejected. Put cheap rules first and call auto() only for the calls that need it. Local subagent sessions run under the root agent's policy too. A subagent's own approval in its agent.ts adds to it and can't loosen it. A remote agent runs in its own deployment under that deployment's policy. Your policy gates the call to the remote agent, not the calls it makes. A call through eve__tool runs the resolved entry's policy, such as linear__create_issue's. Not gated: eve__search, eve__skill, task controls, the built-in ask_question, no_reply, and sleep tools, connection sign-in, and provider-executed tools such as a provider's native web search. Neither is ctx.agent() in workflow code, though a local child's own calls are. A channel calling invokeTool directly gets the same policy: a call it would ask about is rejected with approval-required. With a policy set, eve evaluates it on every call, so keep it fast and pass abortSignal to asynchronous work. Remember approval for a tool once() remembers the latest answer to its prompts for the tool's final name, across turns and context clears, until the session ends. A remembered approval covers later calls to that tool, whatever their input. A later denial of a once() prompt replaces the approval, so the next call asks again. When one message answers several of those prompts, a denial among the answers wins. A once() approval covers later calls, not other approvals already waiting. Each waiting approval needs its own answer. eve remembers only prompts that once()'s own status asked for. It remembers nothing for an always() prompt, or for a wrapping policy that calls once() but returns a different status. When you wrap once(), pass the policy context through and return its status object unchanged. A remembered approval is consent, not authorization. Authorize the current caller on every call. Use always() or an input-dependent policy when different tenants, environments, or other inputs need separate approval decisions. Ask the caller when someone else steers the turn steered() asks the turn's caller before a call starts while ctx.session.auth.steeredBy is set. Otherwise it returns undefined, which leave