Mapping of node names to their PregelNode implementations
Mapping of channel names to their BaseChannel or ManagedValueSpec implementations
Type of context that can be passed to the graph
Type of input values accepted by the graph
Type of output values produced by the graph
Whether to automatically validate the graph structure when it is compiled. Defaults to true.
Optional
cacheOptional cache for the graph, useful for caching tasks.
The channels in the graph, mapping channel names to their BaseChannel or ManagedValueSpec instances
Optional
checkpointerOptional checkpointer for persisting graph state. When provided, saves a checkpoint of the graph state at every superstep. When false or undefined, checkpointing is disabled, and the graph will not be able to save or restore state.
Optional
configThe default configuration for graph execution, can be overridden on a per-invocation basis
Whether to enable debug logging. Defaults to false.
The input channels for the graph. These channels receive the initial input when the graph is invoked. Can be a single channel key or an array of channel keys.
Optional
interruptOptional array of node names or "all" to interrupt after executing these nodes. Used for implementing human-in-the-loop workflows.
Optional
interruptOptional array of node names or "all" to interrupt before executing these nodes. Used for implementing human-in-the-loop workflows.
The nodes in the graph, mapping node names to their PregelNode instances
The output channels for the graph. These channels contain the final output when the graph completes. Can be a single channel key or an array of channel keys.
Optional
retryOptional retry policy for handling failures in node execution
Optional
stepOptional timeout in milliseconds for the execution of each superstep
Optional
storeOptional long-term memory store for the graph, allows for persistence & retrieval of data across threads
Optional
streamOptional channels to stream. If not specified, all channels will be streamed. Can be a single channel key or an array of channel keys.
The streaming modes enabled for this graph. Defaults to ["values"]. Supported modes:
Gets a list of all channels that should be streamed. If streamChannels is specified, returns those channels. Otherwise, returns all channels in the graph.
Array of channel keys to stream
Gets a drawable representation of the graph structure. This is an async version of getGraph() and is the preferred method to use.
Configuration for generating the graph visualization
A representation of the graph that can be visualized
Gets the current state of the graph. Requires a checkpointer to be configured.
Configuration for retrieving the state
Optional
options: GetStateOptionsAdditional options
A snapshot of the current graph state
Gets the history of graph states. Requires a checkpointer to be configured. Useful for:
Configuration for retrieving the history
Optional
options: anyOptions for filtering the history
An async iterator of state snapshots
Gets all subgraphs within this graph. A subgraph is a Pregel instance that is nested within a node of this graph.
Optional
namespace: stringOptional namespace to filter subgraphs
Optional
recurse: booleanWhether to recursively get subgraphs of subgraphs
Generator yielding tuples of [name, subgraph]
Gets all subgraphs within this graph asynchronously. A subgraph is a Pregel instance that is nested within a node of this graph.
Optional
namespace: stringOptional namespace to filter subgraphs
Optional
recurse: booleanWhether to recursively get subgraphs of subgraphs
AsyncGenerator yielding tuples of [name, subgraph]
Run the graph with a single input and config.
The input to the graph.
Optional
options: Partial<The configuration to use for the run.
Streams the execution of the graph, emitting state updates as they occur. This is the primary method for observing graph execution in real-time.
Stream modes:
The input to start graph execution with
Optional
options: Partial<Configuration options for streaming
An async iterable stream of graph state updates
Optional
streamOptions: Omit<EventStreamCallbackHandlerInput, "autoClose">Optional
streamOptions: Omit<EventStreamCallbackHandlerInput, "autoClose">Updates the state of the graph with new values. Requires a checkpointer to be configured.
This method can be used for:
Configuration for the update
The values to update the state with
Optional
asNode: string | keyof NodesOptional node name to attribute the update to
Updated configuration
Creates a new instance of the Pregel graph with updated configuration. This method follows the immutable pattern - instead of modifying the current instance, it returns a new instance with the merged configuration.
The configuration to merge with the current configuration
A new Pregel instance with the merged configuration
The Pregel class is the core runtime engine of LangGraph, implementing a message-passing graph computation model inspired by Google's Pregel system. It provides the foundation for building reliable, controllable agent workflows that can evolve state over time.
Key features:
The Pregel class is not intended to be instantiated directly by consumers. Instead, use the following higher-level APIs:
Pregel
Pregel
instance is returned by the entrypoint functionExample
Example