Contents

Human-in-the-Loop

Also known as: HITL, approval gate, interrupt

Who decides
A person
Shape
Gate

Intent

Stop an agent at a few chosen points, save its full state, and let a person approve, edit or reject the proposed action, or answer a question, before the run continues. Code decides where the run stops, the person decides what happens there, and the run resumes from exactly where it paused with that decision added.

Problem

You run a customer-support agent for an online homeware shop. It can look up orders, issue refunds and send emails. A customer writes: “Order 981 arrived broken, refund my $480.” Shop policy says support can refund up to $250; anything above goes to finance.

The agent reads the order, sees a damaged item and calls issue_refund(order=981, amount=480). Every step was reasonable; the agent simply did not know the cap. The two obvious designs both fail:

What is missing is a few well-placed stops that a person can judge quickly.

Two naive designs. Without gates, the agent sends a 480 dollar refund over the 250 dollar cap. With a gate on every call, the reviewer approves everything without reading, so the bad refund gets through anyway.No gatesA gate on every callSupport agent"refund my $480"issue_refundorder=981, amount=480Refund sentover the $250 capcannot be undoneSupport agentsame requestApproval prompton every call, even readsReviewerclicks yes by habitbad refund gets through
Scroll to see all of it.
Without gates the refund goes straight out; with a gate on every call the reviewer approves by habit and the same refund goes out.

Solution

Add three things around the agent loop. A policy, written in code, decides which proposed actions need a person. A durable pause saves the whole run and returns, so nothing keeps running while the person thinks. A resume loads the run, applies the decision exactly once and continues. The agent itself does not change.

On the refund request, a run looks like this:

  1. The agent proposes. The model emits issue_refund(order=981, amount=480). Nothing runs yet.
  2. The policy decides. Ordinary code, not the model, checks the call: order lookups run freely, refunds above $250 need finance, and deleting an account is denied outright. This refund goes to finance.
  3. Pause and save. The harness builds an approval request (what will happen, why, and that it cannot be undone), saves the messages and the pending call under the thread id ticket-981, and returns. The agent tells the customer the refund is waiting for approval.
  4. Notify and wait. The request lands in the finance channel and may sit there for hours. If nobody decides before a deadline, the default is to not refund.
  5. The person decides. Alice from finance edits the amount to 250 and adds a comment: “policy cap, offer store credit for the rest”.
  6. Resume. The app calls the run again with the same thread id and Alice’s decision. The harness checks that the order was not refunded in the meantime, runs issue_refund(order=981, amount=250) with the request id as idempotency keyIdempotency key A unique id sent with a request. The system remembers it and ignores a second request with the same id, so a retry cannot refund twice., and the model reads the comment and offers store credit.
  7. Record. The request, the decision, who made it and what actually ran go to the audit log.

The nearest pattern, Evaluator–Optimizer, judges an output after it exists; an approval gate stops an action before it has any effect, which is what matters for payments, sent messages and deletes.

Structure

The agent proposes a tool call to a policy gate. Allowed calls run and return a result. Denied calls return a reason to the agent. Calls that need a human pause the run, save its state and notify a reviewer. The reviewer's decision goes to a resume step, which logs it and feeds it back into the agent loop.resulttool calldeny + reasonallownotifyapprove, edit, rejectdecision injectedloggedAgent loopproposes an actionPolicy gatecode: allow, ask, denyTool runswith idempotency keyPause and savefull state, thread idReviewerinbox, Slack or CLIResumesame thread id, onceAudit logrequest, decision, whoask1234567
Scroll to see all of it.

Hover over a number, or tap it, to read what it is.

Solid arrows carry a proposal or a decision, dashed arrows carry results and records. The accent arrows are the human path, which can take seconds or days; the run can stop after the save and resume later in another process.
  1. Agent loop. Any agent or workflow, such as a ReAct loop or a plan executor. It proposes a tool call, a plan, a draft or a question.
  2. Policy gate. Code outside the model that maps each proposal to allow, ask or deny. A denied call goes back to the model as an error with a reason, so it can try another way.
  3. Tool runs. Allowed calls run at once, approved or edited calls after resume. Each gated call carries an idempotency key, so a retry or a double click cannot run it twice.
  4. Pause and save. Builds the approval request and saves the messages and pending calls to a durable store under a thread id. Then it returns; no process waits.
  5. Reviewer. A person with the authority and context to judge the request, reached where they already work. A deadline applies a safe default if nobody answers.
  6. Resume. Loads the run by thread id, matches the decision to the stored request, re-checks that the action still makes sense, applies it once and gives the result to the model.
  7. Audit log. A record of each request, the decision, the reviewer, the time and what actually ran.

Use it when / Avoid it when

Use it when

Avoid it when

How it fails

Approval fatigue

Reviewers approve in a second without reading; Anthropic reports that users accept 93% of Claude Code’s permission prompts.

Mitigation: gate fewer, higher-stakes actions and run the rest in a sandbox.

Uninformative request

The reviewer sees “Allow tool run?” and raw JSON, cannot judge it, and clicks yes.

Mitigation: show a summary, the agent’s reason, the impact, a preview and whether the action can be undone.

Double execution on resume

Two clicks, a retry, or a crash after the tool ran but before the state was saved sends the refund twice.

Mitigation: give every gated call an idempotency key the payment system checks.

Stale approval

Approved yesterday, run today on a world that changed: a colleague already refunded the order.

Mitigation: let requests expire, and re-check preconditions when the run resumes.

Related patterns

Try it

List the agent’s tools and say which run freely, which need a person and which are forbidden. The generator writes the system prompt section on gates and rejections, plus the approval request a reviewer sees.

Further reading