Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Principle:Langchain ai Langgraph Execution Resumption

From Leeroopedia
Property Value
Concept Resuming a paused graph execution with human-provided input
Workflow Human_in_the_Loop_Agent
Pipeline Stage Resumption
Repository Langchain_ai_Langgraph
Source libs/langgraph/langgraph/types.py:L367-418

Overview

Execution resumption is the process of continuing a paused graph from its last checkpoint, optionally injecting human-provided values that resolve pending interrupts. The Command dataclass is the primary mechanism for resumption: passing a Command(resume=value) as the input to stream() or invoke() tells the Pregel execution loop to load the saved checkpoint and re-execute the interrupted node, with the resume value available to the interrupt() function.

Description

When a graph is paused at an interrupt, its state is fully persisted in the checkpointer. Resumption involves:

Loading the checkpoint

The Pregel execution loop loads the most recent checkpoint for the given thread_id. This checkpoint contains all channel values, pending writes (including the interrupt records), and metadata about which node was executing.

Injecting the resume value

The Command dataclass carries the resume value via its resume field. The resume value can be:

  • A single value: Resolves the next pending interrupt in sequence. The node re-executes, and when it reaches the interrupt() call, the function returns the resume value instead of raising GraphInterrupt.
  • A mapping of interrupt IDs to values: Allows targeting specific interrupts by their deterministic ID. This is useful when multiple interrupts are pending or when the client wants to be explicit about which interrupt is being resolved.

Node re-execution

A critical aspect of the resume protocol is that the interrupted node re-executes from the beginning. All code in the node runs again. The interrupt() function uses a counter-based mechanism to match resume values to their corresponding positions:

  1. On re-execution, the interrupt counter starts at zero.
  2. Each interrupt() call increments the counter.
  3. If a resume value exists at the current counter index, it is returned immediately.
  4. If no resume value exists, a new GraphInterrupt is raised.

This means that nodes using interrupt() should be designed with re-execution in mind. Side effects before the interrupt point will execute again on resume.

Additional Command capabilities

Beyond resumption, the Command dataclass supports:

  • update: Apply a state update as part of the resume (equivalent to calling update_state() before resuming).
  • goto: Navigate to a specific node or send messages to nodes, overriding the normal graph routing.
  • graph: Target a specific graph (None for the current graph, Command.PARENT for the parent graph in subgraph scenarios).

Usage

Resumption is used in the second phase of any interrupt-based workflow:

  1. After an in-node interrupt: The client calls graph.stream(Command(resume=value), config) to provide the human's response to the interrupt() call.
  2. After a compile-time interrupt_before: The client can call graph.stream(None, config) to continue without changes, or graph.stream(Command(resume=value), config) if the node expects a resume value.
  3. With state modification: The client can use Command(update={...}, resume=value) to both modify the state and provide a resume value in a single operation.

Theoretical Basis

The resume protocol implements several key concepts:

  • Resume protocol: The interrupt-resume cycle follows a request-response pattern. The interrupt is the request (graph to human), and the Command(resume=...) is the response (human to graph). The Command dataclass encodes the full response.
  • Interrupt ID mapping: Each interrupt has a deterministic ID derived from its checkpoint namespace. This enables precise targeting of resume values to specific interrupts, which is essential for scenarios with multiple pending interrupts or parallel subgraph execution.
  • Graph navigation via Command: The goto field enables the human (or orchestration layer) to redirect the graph's control flow. This goes beyond simple resume: it allows the human to steer the graph to a different node, skip steps, or retry with different parameters.
  • Idempotent re-execution with position-based matching: The counter-based matching of resume values to interrupt() calls ensures deterministic behavior on re-execution. As long as the node's interrupt calls are in the same order, the correct resume value will be returned at the correct position.

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment