Courses / Agentic AI / Module 9
Module 9: Human-in-the-loop: approvals, interrupts, escalation
8 h · theory 2 · hands-on 3 · project 2 · revision 1
You will be able to
- Require approval for actions that change systems
- Show the reviewer what will happen and why
- Escalate when the agent is unsure
- Log who approved what, and when
Capstone increment: Approval gate for every change, with an audit log.
Job-description skills: Human-in-the-loop and approvals · Lab tools: langgraph, fastapi
1. Autonomy is a dial
An agent that can change production systems needs a person in the loop for the actions that matter. The skill is choosing which ones: gate too little and the agent eventually does damage; gate everything and reviewers approve without reading, which is worse than no gate.
The pattern: the agent proposes, your code classifies the action, the run pauses with its state saved, a reviewer sees exactly what will happen and why, and the run resumes executing exactly what was approved. Every decision is logged.
2. Gate by blast radius, decided in code
Classify every tool by blast radius in code you control: reads run freely; reversible changes may run automatically within limits; irreversible actions (deleting data, sending messages to customers, moving money, rotating credentials) always wait. Add a risk signal on top for reversible changes that are dangerous in context, such as a restart at peak hour.
Never let the model’s own opinion of its risk be the only gate. Use the tool below to see why.
Approvals requested 4 · ran automatically 14 · harmful actions that ran without a human 2 of 5
| Action | Blast radius | Model’s risk | Route |
|---|---|---|---|
| Read the last 500 API error logs | read | 0.05 | ran |
| Query p95 latency for checkout | read | 0.05 | ran |
| List deploys in the last 24 hours | read | 0.08 | ran |
| Read the payments runbook | read | 0.04 | ran |
| Search open incidents for 'timeout' | read | 0.06 | ran |
| Restart one staging pod | reversible | 0.20 | ran |
| Add one replica to the checkout service | reversible | 0.30 | ran |
| Open a ticket for the DB team | reversible | 0.15 | ran |
| Raise the DB connection pool from 50 to 80 | reversible | 0.45 | ran |
| Roll back checkout to v2.2 | reversible | 0.55 | ran |
| Restart the production database at peak hour ⚠ harmful | reversible | 0.72 | waits for approval |
| Scale the payments service to 0 replicas ⚠ harmful | reversible | 0.64 | waits for approval |
| Post the incident summary to #status | irreversible | 0.40 | ran |
| Email the customer list about the outage ⚠ harmful | irreversible | 0.50 | ran: caused harm |
| Drop the sessions table to clear stuck locks ⚠ harmful | irreversible | 0.25 | ran: caused harm |
| Delete last month's log bucket to free space ⚠ harmful | irreversible | 0.90 | waits for approval |
| Rotate the payments API key | irreversible | 0.60 | waits for approval |
| Page the on-call DBA | irreversible | 0.30 | ran |
Guided experiments
- Gate on the model’s risk score at 0.60. Which harmful actions ran? Why did the model rate dropping a table as low risk?
- Lower the threshold until nothing harmful slips through. How many approvals is that? What happens to reviewers who get that many requests a day?
- Try “only irreversible actions”. What does it miss, and why is “reversible” not the same as “safe” at peak hour?
- Use “irreversible, or risk ≥ threshold”. Find the threshold that catches all five with the fewest approvals. Which rule is decided by your code, and which by the model?
3. Show reviewers what will happen
An approval request should let a reviewer decide in under a minute: the exact action as a diff or the exact arguments, the evidence that led to it, the expected effect and risk, how to undo it, and when the request expires. Approve the exact call: hash the tool and arguments at review time and refuse to execute anything different.
Keep the volume low enough that each request gets real attention. If reviewers see dozens a day, move safe classes of change to automatic with limits, or batch them, rather than training people to click Approve.
4. Escalate when the agent is unsure
Some situations call for handing the task to a person rather than asking for a yes: conflicting evidence, repeated tool failures, a budget nearly spent, or an incident outside the agent’s known scenarios. Define these triggers in code and route escalations to the right on-call person with a summary of what was found and tried.
An escalation is a success, not a failure, if it arrives early with good context. Track how often it happens and why; the reasons point at the next tools, runbooks or evals to build.
5. Audit everything
Log every approval request and decision: who, what (tool and arguments), why, when, the outcome and the run it belonged to. Make the log append-only and keep it with the run’s trace. You will need it for incident reviews, for compliance and for answering “why did the agent do that?”.
Watch the numbers: approvals requested per day, approval rate, time to decision, and changes rejected or rolled back. A rising rejection rate means the agent’s proposals need work; a near-100% approval rate with seconds per decision means the gate has become a rubber stamp.
Hands-on: coding window
The coding window and the full VS Code lab are available after you sign in.
Sign in to codeLabs
Lab 9.1: Interrupt-based approvals
Classify capstone tools by blast radius; on a change, call interrupt() with the request; expose GET /approvals and POST /approvals/{id} with approve or reject and a reason.
Expected: Changes wait; rejections reach the agent as a tool result; approvals resume the thread.
Lab 9.2: A reviewer card
Render each request as a diff with evidence, risk, undo and expiry, delivered to a web page or a chat webhook with authenticated approve and reject.
Expected: A reviewer can decide without opening the trace.
Lab 9.3: Audit and metrics (capstone increment)
Write every request and decision to an append-only audit table with the args hash, and add approval metrics to the dashboard.
Expected: The audit log answers who approved what and when; the dashboard shows rate and time to decision.
Go deeper
Videos
- Why AI Agents Need A Human in the Loop Now · IBM Technology · ~7 min. Why agents need a human in the loop, and where the loop belongs.
- How to Build Human-in-the-Loop for AI Agents (Practical Guide) · Dave Ebbelaar · ~25 min. A practical build of human-in-the-loop approvals for AI agents.
- LangGraph Agents - Human-In-The-Loop - User Feedback · LangChain · ~6 min. LangGraph’s human-in-the-loop features in six minutes.
Further reading
- Docs Interrupts · LangGraph docs. Pause a graph for approval or edits and resume it with the human's answer.
- Paper Levels of Autonomy for AI Agents · Feng, McDonald and Zhang, 2025. Five levels defined by the user's role, from operator to observer: a vocabulary for the autonomy dial.
- Article Building effective agents · Anthropic. The clearest guide to when you need an agent at all, and the workflow patterns to try first.
GitHub repositories
- humanlayer/humanlayer: Approval and human-contact primitives for agents, including channel integrations.
- langchain-ai/langgraph: The human-in-the-loop docs: interrupt(), Command(resume=…) and review patterns.
- fastapi/fastapi: Security dependencies for authenticating reviewers on approval endpoints.
Checkpoint quiz
Interview questions
- How do you decide which agent actions need human approval?
- Design the approval flow for an agent that changes production config.
- How do you keep approvals meaningful instead of a rubber stamp?
- What do you log for each approval, and why?
- When should an agent escalate to a person, and what should it hand over?
Ask the professor
Sign in to ask questions about this module.
Discussion
Community discussion appears here once giscus is configured (see README).