interrupt
interrupt
function in the appropriate place. The graph will pause, which allows for human intervention, and then resumes the graph with their input. It’s useful for tasks like approvals, edits, or gathering additional context.
interrupt
is the recommended way to pause a graph. NodeInterrupt
is deprecated and will be removed in v2.0.interrupt
in your graph, you need to:
interrupt()
in the appropriate place. See the Common Patterns section for examples.interrupt
is hit.invoke
/stream
(see The Command
primitive).interrupt(...)
pauses execution at human_node
, surfacing the given payload to a human.interrupt
function. Here, a dict containing the text to revise.interrupt(...)
is the human-provided input, which is used to update the state.Interrupt
object with the payload and metadata.Command(resume=...)
, injecting the human’s input and continuing execution.Extended example: using `interrupt`
interrupt(...)
pauses execution at human_node
, surfacing the given payload to a human.
interrupt
function. Here, a dict containing the text to revise.
interrupt(...)
is the human-provided input, which is used to update the state.
Interrupt
object with the payload and metadata.
Command(resume=...)
, injecting the human’s input and continuing execution.
__interrupt__
is a special key that will be returned when running the graph if the graph is interrupted. Support for __interrupt__
in invoke
and ainvoke
has been added in version 0.4.0. If you’re on an older version, you will only see __interrupt__
in the result if you use stream
or astream
. You can also use graph.get_state(thread_id)
to get the interrupt value(s).Command
primitiveinterrupt
is different from Python’s input()
function, where execution resumes from the exact point where the input()
function was called.interrupt
function is used within a graph, execution pauses at that point and awaits user input.
To resume execution, use the Command
primitive, which can be supplied via the invoke
or stream
methods. The graph resumes execution from the beginning of the node where interrupt(...)
was initially called. This time, the interrupt
function will return the value provided in Command(resume=value)
rather than pausing again. All code from the beginning of the node to the interrupt
will be re-executed.
Command.resume
, passing a dictionary mapping of interrupt ids to resume values.
interrupt
and Command
.
Extended example: approve or reject with interrupt
Extended example: edit state with interrupt
interrupt()
in the tool to pause execution.Command
to continue based on human input.interrupt
function pauses the agent graph at a specific node. In this case, we call interrupt()
at the beginning of the tool function, which pauses the graph at the node that executes the tool. The information inside interrupt()
(e.g., tool calls) can be presented to a human, and the graph can be resumed with the user input (tool call approval, edit or feedback).InMemorySaver
is used to store the agent state at every step in the tool calling loop. This enables short-term memory and human-in-the-loop capabilities. In this example, we use InMemorySaver
to store the agent state in memory. In a production application, the agent state will be stored in a database.checkpointer
.stream()
method, passing the config
object to specify the thread ID. This allows the agent to resume the same conversation on future invocations.
You should see that the agent runs until it reaches the interrupt()
call, at which point it pauses and waits for human input.
Resume the agent with a Command
to continue based on human input.
interrupt
function is used in conjunction with the Command
object to resume the graph with a value provided by the human.interrupt()
before executing the wrapped tool.interrupt()
is using special input and output format that’s expected by Agent Inbox UI: - a list of HumanInterrupt
objects is sent to AgentInbox
render interrupt information to the end user - resume value is provided by AgentInbox
as a list (i.e., Command(resume=[...])
)interrupt()
to any tool without having to add it inside the tool:
add_human_in_the_loop
wrapper is used to add interrupt()
to the tool. This allows the agent to pause execution and wait for human input before proceeding with the tool call.
You should see that the agent runs until it reaches the interrupt()
call,
at which point it pauses and waits for human input.
Resume the agent with a Command
to continue based on human input.
Extended example: validating user input
interrupt_before
and interrupt_after
at compile time or run time.
compile
time.interrupt_before
specifies the nodes where execution should pause before the node is executed.interrupt_after
specifies the nodes where execution should pause after the node is executed.None
for the input. This will run the graph until the next breakpoint is hit.Setting static breakpoints
langgraph dev
.
interrupt
or in a separate node to avoid duplication, as these are re-triggered every time the node is resumed.
interrupt
was triggered. Similarly, the subgraph will resume from the beginning of the node where the interrupt()
function was called.
Extended example: parent and subgraph execution flow
node_1
→ node_2
(subgraph call) → node_3
And the subgraph has 3 nodes, where the second node contains an interrupt
:Subgraph: sub_node_1
→ sub_node_2
(interrupt
) → sub_node_3
When resuming the graph, the execution will proceed as follows:node_1
in the parent graph (already executed, graph state was saved in snapshot).node_2
in the parent graph from the start.sub_node_1
in the subgraph (already executed, graph state was saved in snapshot).sub_node_2
in the subgraph from the beginning.sub_node_3
and subsequent nodes.Command(resume=..., update=SOME_STATE_MUTATION)
or relying on global variables to modify the node’s structure dynamically.
Extended example: incorrect code that introduces non-determinism