Pause the agent before a sensitive action (refund, deletion, financial move) and require human approval.
A junior doctor needs attending sign-off before prescribing anything risky. The junior drafts, the attending reviews, then the system acts.
user_q -> draft_action -> [PAUSE for review]
|
approve? yes / no
| |
execute abort
HITL flows gate dangerous steps behind human approval. LangGraph’s interrupt_before / interrupt_after pause execution; the application presents the proposed action to the user; an update_state call resumes (or aborts). Always use HITL for actions that have side-effects in production.
app = graph.compile(interrupt_before=['execute'])
state_history = []
for step in app.stream({'messages': [user_input]}, config=config):
state_history.append(step)
if step.get('next') == ('execute',):
print('awaiting approval; current draft:', step['__start__'] or step)
interrupt_before=[‘execute’] pauses execution right before a sensitive node.
# resume after approval
from langgraph.checkpoint.sqlite import SqliteSaver
app.update_state(config, {'approved': True})
for step in app.stream(None, config=config):
print(step)
update_state injects the human’s decision (approve or reject) into the state dict.
# abort after rejection
app.update_state(config, {'approved': False})
# walk to the END node manually or short-circuit
stream(None) resumes from the saved checkpoint — the agent re-runs from the interrupted node.
Running financial actions without HITL. The agent decides and the system acts — no approval. Always gate production-write actions.
interrupt_before sensitive nodes; present state to reviewer; update_state with approved flag; resume with stream(None). Test the abort path explicitly.