| name | langgraph-interrupt-pattern |
| description | Use when implementing LangGraph workflows that need to pause for user input or external confirmation before continuing execution |
LangGraph Interrupt Pattern
Overview
Pattern for using LangGraph interrupt() to pause graph execution at a node and resume after receiving external input (e.g., user confirmation, selection).
Prerequisites
- A checkpointer must be configured (MemorySaver for dev, AsyncPostgresSaver for production)
- Use a consistent
thread_id in the config across stream and resume calls
Pattern
Pausing execution
from langgraph.types import interrupt
def my_node(state):
user_input = interrupt({
"reason": "need_selection",
"options": ["option_a", "option_b"],
"context": "Choose which path to take"
})
match user_input.get("action"):
case "select":
selected = user_input["selected"]
return state.model_copy(update={"selected": selected})
case "skip":
return state
Resuming execution
from langgraph.types import Command
async for event in graph.astream_events(
Command(resume={"action": "select", "selected": chosen_item}),
config={"configurable": {"thread_id": thread_id}},
version="v2",
):
pass
Extracting interrupt data from state
state_snapshot = await graph.aget_state(config)
for task in state_snapshot.tasks:
for intr in task.interrupts:
payload = intr.value
reason = payload.get("reason")
options = payload.get("options")
Common Mistakes
| Mistake | Fix |
|---|
| No checkpointer configured | interrupt() silently fails without a checkpointer |
Different thread_id on resume | Must match the original stream's thread_id |
Passing full state to astream_events on resume | Pass Command(resume=...) only, not the state |
| Forgetting to handle the resume value | interrupt() returns whatever was passed in Command(resume=...) |