DevInterviewMasterStart free →
Agentic AI PatternsFree to read

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 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:

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?

ScenarioRecommendationWhy
Actions that move money or send legal/financial messages✅ Always pause for a humanMistakes here are expensive and hard to undo.
Irreversible actions (delete data, publish publicly)✅ Pause for a humanYou cannot take it back, so confirm first.
Low-risk, easily reversible steps (draft a note, fetch data)❌ Let the agent run freelyAsking every time annoys users and slows everything down.
The agent is very unsure / low confidence✅ Pause and askA human can resolve ambiguity the agent can't.

Human-in-the-loop mistakes beginners make

MistakeConsequenceFix
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

Key takeaways

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.

Browse all Agentic AI Patterns topics →

Practice this on DevInterviewMaster

Read the full Human-in-the-Loop Pattern breakdown with interactive demos, quizzes, and Hinglish notes.

Open the interactive topic →

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.