Human-in-the-Loop Agents With LangGraph
LangGraph lets you pause an agent mid-execution for human review, collect feedback, and resume exactly where the agent left off, making it the right tool for high-stakes automations.
Key Takeaways
- Comprehensive strategies proven to work at top companies
- Actionable tips you can implement immediately
- Expert insights from industry professionals
Full automation is not always the right goal. There are tasks where an agent does 90 percent of the work well but the final 10 percent requires a human judgment call. There are actions that are irreversible, such as sending an email to 10,000 users, that should never fire without an approval. There are workflows where you want to review intermediate outputs before the agent continues.
LangGraph handles all of these cases through a pattern called human-in-the-loop. The agent runs, pauses at a checkpoint, waits for human input, and then resumes with that input incorporated into its state. The full execution history is preserved across the pause.
The interrupt_before Pattern
LangGraph's interrupt_before parameter tells the graph to stop before executing a specific node and wait for a human to provide input. The graph state is saved automatically. When the human responds, execution resumes from that exact point.
Here is the key configuration: when you compile the graph, pass a checkpointer (an in-memory or persistent store) and specify which nodes should pause for human input.
from langgraph.graph import StateGraph, END
from langgraph.checkpoint.memory import MemorySaver
from typing import TypedDict
class ApprovalState(TypedDict):
task: str
draft_action: str
human_approved: bool
result: str
def plan_action(state: ApprovalState) -> dict:
return {'draft_action': f'Send campaign email to all users re: {state["task"]}'}
def execute_action(state: ApprovalState) -> dict:
if state['human_approved']:
return {'result': 'Email campaign sent successfully'}
return {'result': 'Action cancelled by reviewer'}
graph = StateGraph(ApprovalState)
graph.add_node('plan', plan_action)
graph.add_node('execute', execute_action)
graph.set_entry_point('plan')
graph.add_edge('plan', 'execute')
graph.add_edge('execute', END)
# Pause before 'execute' and persist state with a checkpointer
checkpointer = MemorySaver()
app = graph.compile(
checkpointer=checkpointer,
interrupt_before=['execute']
)
Running the Approval Loop
With interrupt_before set, the graph pauses after the plan node completes and before execute begins. You inspect the draft action, collect a human decision, and resume with the updated state.
# Thread ID keeps the paused state associated with this run
config = {'configurable': {'thread_id': 'approval-run-001'}}
initial = {
'task': 'Q3 product launch',
'draft_action': '',
'human_approved': False,
'result': ''
}
# Run until the interrupt fires
for event in app.stream(initial, config=config):
print(event)
# Inspect the pending action
current_state = app.get_state(config)
print('Pending action:', current_state.values['draft_action'])
# Human reviews and decides
human_decision = True # set False to cancel
# Update state and resume
app.update_state(config, {'human_approved': human_decision})
for event in app.stream(None, config=config):
print(event)
Where to Use Human-in-the-Loop
The clearest use cases are: any action that sends external communications (emails, Slack messages, webhooks to production systems), any financial transaction, any data deletion, and any agent output that will be published publicly.
Prompt
"You are a careful execution agent. Before taking any irreversible action, summarize exactly what you plan to do, who it will affect, and what the impact will be. Present this as a clear approval request. Wait for explicit confirmation before proceeding."
Beyond Approval: Feedback and Correction
Human-in-the-loop is not just for approvals. You can also use it to inject corrections. If the agent drafts a report that is 80 percent right, a human can edit the draft in the state and resume. The agent continues from that corrected starting point rather than starting over. This is the pattern that makes AI-assisted workflows genuinely collaborative rather than all-or-nothing.
Want to build this live with Aki?
Join a Lightning Lesson and go deeper on this topic. Browse upcoming sessions →
Aki Wijesundara
Expert team of AI professionals and career advisors with experience at top tech companies. We've helped 500+ students land internships at Google, Meta, OpenAI, and other leading AI companies.
Ready to Launch Your AI Career?
Join our comprehensive program and get personalized guidance from industry experts who've been where you want to go.
Table of Contents
Share Article
Get Weekly AI Career Tips
Join 5,000+ professionals getting actionable career advice in their inbox.
No spam. Unsubscribe anytime.