Module 7 Lesson 5: Human Approval Nodes
The pause button. Implementing 'interrupts' that allow humans to review and edit agent state before final actions.
Human Approval Nodes: The Ultimate Guardrail
The most powerful feature of LangGraph is the ability to "Breakpoint" a graph. This allows the system to pause mid-execution, save the state to a database, and wait for a human to continue, modify, or reject the work.
1. How Interrupts Work
In LangGraph, you declare which nodes require an "Interrupt."
interrupt_before=["send_email_node"]orinterrupt_after=["calculate_total"].
When the graph hits that point, the invoke or stream function stops. The state is persisted. The user sees a message. Only after a new "Resume" signal is sent does the graph continue.
2. The "State Editing" Pattern
A Human-in-the-Loop doesn't just click "Yes" or "No." They can actually edit the state.
- Agent drafts a tweet.
- Graph pauses at
post_tweetnode. - Human sees the draft and realizes it's too long.
- Human edits the state variable
draft_content. - Human clicks Resume.
- The agent posts the edited version.
3. Visualizing the Breakpoint
sequenceDiagram
participant A as Agent Node
participant DB as SQLite Checkpointer
participant H as Human
participant E as External System
A->>DB: Save State S1
A->>A: Logic Finished
Note over A: PAUSE (Interrupt)
H->>DB: View State S1
H->>DB: Update State to S2 (Edited)
H->>A: RESUME
A->>E: Execute S2 Action
4. Implementation Example
from langgraph.checkpoint.sqlite import SqliteSaver
# 1. Setup persistence
memory = SqliteSaver.from_conn_string(":memory:")
# 2. Compile with interrupt
app = workflow.compile(
checkpointer=memory,
interrupt_before=["tool_execution_node"]
)
# 3. Running
thread = {"configurable": {"thread_id": "1"}}
app.invoke(inputs, thread) # This will pause before the tool node
5. Why Not Use input()?
You might think: "Why not just use a Python input() function?"
- The Problem:
input()blocks the entire server thread. If you have 100 users, and one human is slow to respond, your whole server hangs. - The Solution: LangGraph's "Persistence" allows your server to handle 10,000 other requests while that one specific "Thread" sits idle in the database waiting for approval.
Key Takeaways
- Interrupts are non-blocking pauses in the graph execution.
- SqliteSaver (or similar) is required to remember the state during the pause.
- Humans can approve, reject, or modify the state during an interrupt.
- This is the standard for Enterprise Compliance and Safety.