LangChain Reference home pageLangChain ReferenceLangChain Reference
  • GitHub
  • Main Docs
Deep Agents
LangChain
LangGraph
Integrations
LangSmith
LangGraph
  • Web
  • Channels
  • Pregel
  • Prebuilt
  • Remote
LangGraph SDK
  • Client
  • Auth
  • React
  • Logging
  • React Ui
  • Server
LangGraph Checkpoint
LangGraph Checkpoint MongoDB
LangGraph Checkpoint Postgres
  • Store
LangGraph Checkpoint Redis
  • Shallow
  • Store
LangGraph Checkpoint SQLite
LangGraph Checkpoint Validation
  • Cli
LangGraph API
LangGraph CLI
LangGraph CUA
  • Utils
LangGraph Supervisor
LangGraph Swarm
⌘I

LangChain Assistant

Ask a question to get started

Enter to send•Shift+Enter new line

Menu

LangGraph
WebChannelsPregelPrebuiltRemote
LangGraph SDK
ClientAuthReactLoggingReact UiServer
LangGraph Checkpoint
LangGraph Checkpoint MongoDB
LangGraph Checkpoint Postgres
Store
LangGraph Checkpoint Redis
ShallowStore
LangGraph Checkpoint SQLite
LangGraph Checkpoint Validation
Cli
LangGraph API
LangGraph CLI
LangGraph CUA
Utils
LangGraph Supervisor
LangGraph Swarm
Language
Theme
JavaScript@langchain/langgraphwebPregel
Class●Since v0.3

Pregel

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:

  • Message passing between nodes in discrete "supersteps"
  • Built-in persistence layer through checkpointers
  • First-class streaming support for values, updates, and events
  • Human-in-the-loop capabilities via interrupts
  • Support for parallel node execution within supersteps

The Pregel class is not intended to be instantiated directly by consumers. Instead, use the following higher-level APIs:

  • StateGraph: The main graph class for building agent workflows
    • Compiling a StateGraph will return a CompiledGraph instance, which extends Pregel
  • Functional API: A declarative approach using tasks and entrypoints
    • A Pregel instance is returned by the entrypoint function
Copy
class Pregel

Bases

PartialRunnable<InputType | CommandType | null, OutputType, PregelOptions<Nodes, Channels, ContextType>>

Example 1

Copy
// Using StateGraph API
const graph = new StateGraph(annotation)
  .addNode("nodeA", myNodeFunction)
  .addEdge("nodeA", "nodeB")
  .compile();

// The compiled graph is a Pregel instance
const result = await graph.invoke(input);

Example 2

Copy
// Using Functional API
import { task, entrypoint } from "@langchain/langgraph";
import { MemorySaver } from "@langchain/langgraph-checkpoint";

// Define tasks that can be composed
const addOne = task("add", async (x: number) => x + 1);

// Create a workflow using the entrypoint function
const workflow = entrypoint({
  name: "workflow",
  checkpointer: new MemorySaver()
}, async (numbers: number[]) => {
  // Tasks can be run in parallel
  const results = await Promise.all(numbers.map(n => addOne(n)));
  return results;
});

// The workflow is a Pregel instance
const result = await workflow.invoke([1, 2, 3]); // Returns [2, 3, 4]

Properties

property
autoValidate: boolean

Whether to automatically validate the graph structure when it is compiled. Defaults to true.

property
cache: BaseCache<unknown>

Optional cache for the graph, useful for caching tasks.

property
channels: Channels

The channels in the graph, mapping channel names to their BaseChannel or ManagedValueSpec instances

property
checkpointer: boolean | BaseCheckpointSaver<number>

Optional 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.

property
config: LangGraphRunnableConfig<Record<string, any>>

The default configuration for graph execution, can be overridden on a per-invocation basis

property
debug: boolean

Whether to enable debug logging. Defaults to false.

property
inputChannels: keyof Channels | keyof Channels[]

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.

property
interruptAfter: keyof Nodes[] | "*"

Optional array of node names or "all" to interrupt after executing these nodes. Used for implementing human-in-the-loop workflows.

property
interruptBefore: keyof Nodes[] | "*"

Optional array of node names or "all" to interrupt before executing these nodes. Used for implementing human-in-the-loop workflows.

property
lc_kwargs: SerializedFields
property
lc_runnable: boolean
property
lc_serializable: boolean
property
name: string

The name of the task, analogous to the node name in StateGraph.

property
nodes: Nodes

The nodes in the graph, mapping node names to their PregelNode instances

property
outputChannels: keyof Channels | keyof Channels[]

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.

property
retryPolicy: RetryPolicy

Optional retry policy for handling failures in node execution

property
stepTimeout: number

Optional timeout in milliseconds for the execution of each superstep

property
store: BaseStore

Optional long-term memory store for the graph, allows for persistence & retrieval of data across threads

property
streamChannels: keyof Channels | keyof Channels[]

Optional channels to stream. If not specified, all channels will be streamed. Can be a single channel key or an array of channel keys.

property
streamMode: StreamMode[]

The streaming modes enabled for this graph. Defaults to ["values"]. Supported modes:

  • "values": Streams the full state after each step
  • "updates": Streams state updates after each step
  • "messages": Streams messages from within nodes
  • "custom": Streams custom events from within nodes
  • "debug": Streams events related to the execution of the graph - useful for tracing & debugging graph execution
property
lc_aliases
property
lc_attributes
property
lc_id
property
lc_secrets
property
lc_serializable_keys
property
streamChannelsAsIs: keyof Channels | keyof Channels[]
property
streamChannelsList: keyof Channels[]

Methods

method
_batchWithConfig
method
_callWithConfig
method
_getOptionsList
method
_separateRunnableConfigFromCallOptions
method
_streamLog
method
_transformStreamWithConfig
method
assign
method
asTool
method
batch→ Promise<OperationResults<Op>>

Execute multiple operations in a single batch. This is more efficient than executing operations individually.

method
clearCache→ Promise<void>
method
getGraphAsync→ Promise<Graph>

Returns a drawable representation of the computation graph.

method
getName
method
getState→ Promise<StateSnapshot>

Gets the current state of the graph. Requires a checkpointer to be configured.

method
getStateHistory→ AsyncIterableIterator<StateSnapshot>

Gets the history of graph states. Requires a checkpointer to be configured. Useful for:

  • Debugging execution history
  • Implementing time travel
  • Analyzing graph behavior
method
getSubgraphsAsync→ AsyncGenerator<[string, Pregel<any, any, StrRecord<string, any>, any, any, any, any, unknown, CommandInstance<unknown, Record<string, unknown>, string>, any>]>

Gets all subgraphs within this graph asynchronously. A subgraph is a Pregel instance that is nested within a node of this graph.

method
invoke→ Promise<ExtractStateType<O, O>>

Run the graph with a single input and config.

method
pick
method
pipe→ PregelNode<RunInput, Exclude<NewRunOutput, Error>>

Create a new runnable sequence that runs each individual runnable in series, piping the output of one runnable into another runnable or runnable-like.

method
stream→ Promise<IterableReadableStream<StreamOutputMap<TStreamMode, TSubgraphs, ExtractUpdateType<I, ExtractStateType<I, I>>, ExtractStateType<O, O>, "__start__" | N, NodeReturnType, InferWriterType<WriterType>, TEncoding>>>

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:

  • "values": Emits complete state after each step
  • "updates": Emits only state changes after each step
  • "debug": Emits detailed debug information
  • "messages": Emits messages from within nodes
  • "custom": Emits custom events from within nodes
  • "checkpoints": Emits checkpoints from within nodes
  • "tasks": Emits tasks from within nodes
method
streamEvents→ IterableReadableStream<StreamEvent>
method
streamLog
method
toJSON→ __type
method
toJSONNotImplemented
method
transform
method
updateState→ Promise<RunnableConfig<Record<string, any>>>

Updates the state of the graph with new values. Requires a checkpointer to be configured.

This method can be used for:

  • Implementing human-in-the-loop workflows
  • Modifying graph state during breakpoints
  • Integrating external inputs into the graph
method
validate→ this

Validates the graph structure to ensure it is well-formed. Checks for:

  • No orphaned nodes
  • Valid input/output channel configurations
  • Valid interrupt configurations
method
withConfig→ CompiledStateGraph<S, U, N, I, O, C, NodeReturnType, InterruptType, WriterType>

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.

method
withFallbacks
method
withListeners
method
withRetry
method
isRunnable
deprecatedmethod
getGraph→ Graph

Returns a drawable representation of the computation graph.

deprecatedmethod
getSubgraphs→ Generator<[string, Pregel<any, any, StrRecord<string, any>, any, any, any, any, unknown, CommandInstance<unknown, Record<string, unknown>, string>, any>]>

Gets all subgraphs within this graph. A subgraph is a Pregel instance that is nested within a node of this graph.

View source on GitHub