Human-in-the-Loop Pattern
When the agent should stop and ask a human
Imagine a new intern who is brilliant but sometimes overconfident. You'd happily let them draft emails on their own, but before they send money or delete a database , you'd want them to check with you first. The Human-in-the-Loop pattern gives your agent exactly that habit: do the safe stuff automatically, but pause and ask a human before anything risky.
Key points
- The agent pauses at critical or risky steps and waits for a human.
- A human approves, edits, or rejects the proposed action.
- After the human responds, the agent continues from where it stopped.
- It massively improves safety and trust for real-world tasks.
The one-line definition
The Human-in-the-Loop (HITL) pattern is when an agent pauses before a risky or important action and asks a human to approve, edit, or reject it, then resumes once the human responds.
Note: Automate the safe steps; ask a human before the dangerous ones.
Where the human steps in
Agent is working through its plan... │ ▼ ┌───────────────┐ │ Next action? │ └──────┬────────┘ │ is it RISKY? (send money? delete data? email a customer?) │ │ NO │ │ YES ▼ ▼ ┌──────────┐ ┌──────────────────────┐ │ just do │ │ ⏸️ PAUSE & ASK HUMAN │ │ it auto │ │ "Approve transfer │ └────┬─────┘ │ of $5000? (y/n)" │ │ └──────────┬───────────┘ │ approve / │ / reject │ edit │ ▼ ▼ continue ◄──────────────── human responds the plan (then resume)
Three things a human can do at the pause
When the agent pauses, the human is not limited to just yes/no. There are three useful responses, like a manager reviewing an intern's draft:
- Approve: "Looks good, go ahead." The agent runs the action.
- Edit: "Almost, but change the amount to $50." The agent runs the fixed version.
- Reject: "No, don't do this." The agent skips it and rethinks.
This is why HITL builds trust: the human is always the final boss on the actions that matter.
A tiny example (read it like English)
Here the agent decides on an action. If the action is marked risky, it stops and waits for a human before doing anything. Notice the agent does not run the risky tool until approved is true.
RISKY = {"send_money", "delete_data", "email_customer"}
def step(action, args):
if action in RISKY:
# PAUSE: ask a human before doing anything dangerous
choice = ask_human(f"Approve '{action}' with {args}? (yes/edit/no)")
if choice == "no":
return "skipped by human" # reject
if choice == "edit":
args = ask_human("Provide corrected args:") # edit
# 'yes' or edited -> fall through and run it
return run_tool(action, args) # safe action runs directly
Pause and resume: the task waits for the human
TIME ───────────────────────────────────────────────►
Agent: think ─► act ─► think ─► [⏸ PAUSE on risky step] │ │ waiting... Human: ▼ reviews & clicks ✅ Approve │ Agent: ▼ ▶ RESUME ─► act ─► ✅ done
The agent's progress is SAVED while it waits, then it picks up exactly where it left off.
When should you add a human checkpoint?
| Scenario | Recommendation | Why |
|---|---|---|
| Actions that move money or send legal/financial messages | ✅ Always pause for a human | Mistakes here are expensive and hard to undo. |
| Irreversible actions (delete data, publish publicly) | ✅ Pause for a human | You cannot take it back, so confirm first. |
| Low-risk, easily reversible steps (draft a note, fetch data) | ❌ Let the agent run freely | Asking every time annoys users and slows everything down. |
| The agent is very unsure / low confidence | ✅ Pause and ask | A human can resolve ambiguity the agent can't. |
Human-in-the-loop mistakes beginners make
| Mistake | Consequence | Fix |
|---|---|---|
| Asking the human to approve EVERY tiny step. | People get 'approval fatigue' and start clicking yes without reading. | Only pause for genuinely risky or irreversible actions; automate the rest. |
| Running the risky action before the human replies. | The whole safety point is defeated; damage is already done. | Block on the human's response; never execute a risky tool until approved. |
| Losing the agent's progress while it waits. | When the human approves, the agent restarts from scratch or breaks. | Save the agent's state at the pause so it can resume exactly where it stopped. |
Remember these lines
- HITL = pause before risky actions, ask a human, then continue.
- Humans can Approve, Edit, or Reject, not just say yes/no.
- Only interrupt for risky/irreversible steps to avoid approval fatigue.
- Always save state at the pause so the agent resumes cleanly.
Key takeaways
- Human-in-the-Loop pauses the agent before risky or important actions and asks a human.
- The human can approve, edit, or reject the proposed action.
- After the human responds, the agent resumes from where it stopped.
- Reserve checkpoints for risky/irreversible actions to avoid approval fatigue.
- Save the agent's state at the pause so it can continue cleanly, and never run a risky action before approval.
Frequently Asked Questions
What is Human-in-the-Loop Pattern?
Imagine a new intern who is brilliant but sometimes overconfident. You'd happily let them draft emails on their own, but before they send money or delete a database , you'd want them to check with you first.
How does Human-in-the-Loop Pattern work?
The Human-in-the-Loop (HITL) pattern is when an agent pauses before a risky or important action and asks a human to approve, edit, or reject it, then resumes once the human responds.
What are the key takeaways about Human-in-the-Loop Pattern?
Human-in-the-Loop pauses the agent before risky or important actions and asks a human. The human can approve, edit, or reject the proposed action. After the human responds, the agent resumes from where it stopped. Reserve checkpoints for risky/irreversible actions to avoid approval fatigue.
Related topics
Practice this on DevInterviewMaster
Read the full Human-in-the-Loop Pattern breakdown with interactive demos, quizzes, and Hinglish notes.
800+ system-design, LLD, coding, and design-pattern topics. Unlock everything with Pro (₹499, one-time) or Ultimate (₹999, one-time) — lifetime access, no subscription.