Human-in-the-Loop
~2 min read
Concept & How It Works
Why Does It Exist?
High-stakes actions — refunds, database writes, external emails — need human judgment. HITL embeds governance into the graph instead of bolting on a separate approval UI.
Real-World Analogy
HITL is a co-pilot switch: the plane flies itself, but the captain must confirm before landing or changing course.
Visual Workflows
What is Human-in-the-Loop?
Example
Scenario
Graph pauses before `send_email` node. Support lead edits the draft in a UI, clicks Approve; graph resumes and sends the edited version.
Solution
In Agent Frameworks, apply Human-in-the-Loop to this scenario: Graph pauses before `send_email` node. Identify the inputs, run the technique, validate the output, and note one thing you would monitor in production.
Practice Task
Do this before moving to the next module — reading alone is not enough.
Open the Code Walkthrough below and run it locally. Change one parameter related to Human-in-the-Loop (e.g. model, temperature, top_k, or tool name), observe the difference in output, and write 2–3 sentences explaining what changed.
Code Walkthrough
Highlighted lines show where Human-in-the-Loop happens in the code.
1app = graph.compile(checkpointer=saver, interrupt_before=["send_email"])2
3# First run — stops before send_email4app.invoke(input_state, config)5
6# Human edits state["draft"] in UI, then:7app.invoke(None, config) # resumes and executes send_emailCommands to Remember
Commands to Remember
pip install langgraph langchain-openai # LangGraph agent frameworkpip install openai-agents # OpenAI Agents SDKpip install crewai # multi-agent CrewAI framework
Common Mistakes
- Treating Human-in-the-Loop as a black box without evaluation
- Ignoring cost and latency in production
- Skipping error handling for langgraph human in the loop
Cheat Sheet
Quick recap — the most important points from this module.
Cheat Sheet
quick ref- •Human-in-the-Loop
- •interrupt_before
- •Resume
- •Audit Trail