LangChain Reference home pageLangChain ReferenceLangChain Reference
  • GitHub
  • Main Docs
Deep Agents
LangChain
LangGraph
Integrations
LangSmith
LangGraph
  • Web
  • Channels
  • Pregel
  • Prebuilt
  • Remote
  • Stream
LangGraph SDK
  • Client
  • Auth
  • React
  • Logging
  • React Ui
  • Server
LangGraph Checkpoint
LangGraph Checkpoint MongoDB
LangGraph Checkpoint Postgres
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
WebChannelsPregelPrebuiltRemoteStream
LangGraph SDK
ClientAuthReactLoggingReact UiServer
LangGraph Checkpoint
LangGraph Checkpoint MongoDB
LangGraph Checkpoint Postgres
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 v1.0

Pregel

Copy
class Pregel

Bases

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

Properties

Methods

View source on GitHub

Example 1

Example 2

property
autoValidate: boolean
property
cache: BaseCache<unknown>
property
channels: Channels
property
checkpointer: boolean | BaseCheckpointSaver<number>
property
config: LangGraphRunnableConfig<Record<string, any>>
property
debug: boolean
property
inputChannels: keyof Channels | keyof Channels[]
property
interruptAfter: keyof Nodes[] | "*"
property
interruptBefore: keyof Nodes[] | "*"
property
lc_kwargs: SerializedFields
property
lc_runnable: boolean
property
lc_serializable: boolean
property
name: string
property
nodes: Nodes
property
outputChannels: keyof Channels | keyof Channels[]
property
retryPolicy: RetryPolicy
property
stepTimeout: number
property
store: BaseStore
property
streamChannels: keyof Channels | keyof Channels[]
property
streamMode: StreamMode[]
property
streamTransformers: TStreamTransformers
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[]
method
_batchWithConfig
method
_callWithConfig
method
_getOptionsList
method
_separateRunnableConfigFromCallOptions
method
_streamLog
method
_transformStreamWithConfig
method
assign
method
asTool
method
batch→ Promise<OperationResults<Op>>
method
clearCache→ Promise<void>
method
getGraphAsync→ Promise<Graph>
method
getName
method
getState→ Promise<StateSnapshot>
method
getStateHistory→ AsyncIterableIterator<StateSnapshot>
method
getSubgraphsAsync→ AsyncGenerator<[string, Pregel<any, any, StrRecord<string, any>, any, any, any, any, unknown, CommandInstance<unknown, Record<string, unknown>, string>, any, []>]>
method
invoke→ Promise<OutputType>
method
pick
method
pipe→ PregelNode<RunInput, Exclude<NewRunOutput, Error>>
method
stream→ Promise<IterableReadableStream<StreamOutputMap<TStreamMode, TSubgraphs, StreamUpdatesType, StreamValuesType, keyof Nodes, NodeReturnType, StreamCustom, TEncoding>>>
method
streamEvents→ Promise<IterableReadableStream<Uint8Array<ArrayBufferLike>>>
method
streamLog
method
toJSON→ __type
method
toJSONNotImplemented
method
transform
method
updateState→ Promise<RunnableConfig<Record<string, any>>>
method
validate→ this
method
withConfig→ Pregel<Nodes, Channels, ContextType, InputType, OutputType, StreamUpdatesType, StreamValuesType, NodeReturnType, CommandType, StreamCustom, readonly [TStreamTransformers, TTransformers]>
method
withFallbacks
method
withListeners
method
withRetry
method
isRunnable
deprecatedmethod
getGraph→ Graph
deprecatedmethod
getSubgraphs→ Generator<[string, Pregel<any, any, StrRecord<string, any>, any, any, any, any, unknown, CommandInstance<unknown, Record<string, unknown>, string>, any, []>]>

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

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

Optional cache for the graph, useful for caching tasks.

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

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.

The 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 array of node names or "all" to interrupt after executing these nodes. Used for implementing human-in-the-loop workflows.

Optional 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 retry policy for handling failures in node execution

Optional timeout in milliseconds for the execution of each superstep

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

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

  • "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
  • "tools": Streams tool-call lifecycle events (on_tool_start, on_tool_event, on_tool_end, on_tool_error) from LLM tool execution
  • "debug": Streams events related to the execution of the graph - useful for tracing & debugging graph execution

Stream reducer factories registered at compile time. These run automatically for every streamEvents(..., { version: "v3" }) call, before any call-site transformers.

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

Gets a drawable representation of the graph structure. This is an async version of getGraph() and is the preferred method to use.

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

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

  • Debugging execution history
  • Implementing time travel
  • Analyzing graph behavior

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

Run the graph with a single input and config.

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

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

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

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

  • No orphaned nodes
  • Valid input/output channel configurations
  • Valid interrupt configurations

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.

Returns a drawable representation of the computation graph.

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

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);
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]