An empty sequence of strings.
Unset sentinel value.
The last (maybe virtual) node in graph-style Pregel.
The first (maybe virtual) node in graph-style Pregel.
Tag to hide a node/edge from certain tracing/streaming environments.
Special value to indicate that graph should interrupt on all nodes.
Type variable used to represent graph run scoped context.
Defaults to None.
Type variable used to represent the input to a StateGraph.
Defaults to StateT.
Type variable used to represent the input to a node.
Type variable used to represent the output of a StateGraph.
Defaults to StateT.
Type variable used to represent the state in a graph.
Return cached annotated keys for a Python class.
Determine the default value for a field in a state schema.
Get Pydantic state update as a list of (key, value) tuples.
Create a pydantic model with the given field definitions.
Coerce a runnable-like object into a Runnable.
TypedDict to use for extra keyword arguments, enabling type checking warnings for deprecated arguments.
Base class for all channels.
Stores the result of applying a binary operator to the current value and each new value.
import operator
total = Channels.BinaryOperatorAggregate(int, operator.add)Stores the value received in the step immediately preceding, clears after.
Stores the last value received, can receive at most one value per step.
Stores the last value received, but only made available after finish(). Once made available, clears the value.
A channel that waits until all named values are received before making the value available.
A channel that waits until all named values are received before making the value ready to be made available. It is only made available after finish() is called.
Raised when attempting to update a channel with an invalid set of updates.
Troubleshooting guides:
Pregel manages the runtime behavior for LangGraph applications.
Pregel combines actors and channels into a single application. Actors read data from channels and write data to channels. Pregel organizes the execution of the application into multiple steps, following the Pregel Algorithm/Bulk Synchronous Parallel model.
Each step consists of three phases:
Repeat until no actors are selected for execution, or a maximum number of steps is reached.
An actor is a PregelNode.
It subscribes to channels, reads data from them, and writes data to them.
It can be thought of as an actor in the Pregel algorithm.
PregelNodes implement LangChain's
Runnable interface.
Channels are used to communicate between actors (PregelNodes).
Each channel has a value type, an update type, and an update function – which
takes a sequence of updates and
modifies the stored value. Channels can be used to send data from one chain to
another, or to send data from a chain to itself in a future step. LangGraph
provides a number of built-in channels:
LastValue: The default channel, stores the last value sent to the channel,
useful for input and output values, or for sending data from one step to the nextTopic: A configurable PubSub Topic, useful for sending multiple values
between actors, or for accumulating output. Can be configured to deduplicate
values, and/or to accumulate values over the course of multiple steps.Context: exposes the value of a context manager, managing its lifecycle.
Useful for accessing external resources that require setup and/or teardown. e.g.
client = Context(httpx.Client)BinaryOperatorAggregate: stores a persistent value, updated by applying
a binary operator to the current value and each update
sent to the channel, useful for computing aggregates over multiple steps. e.g.
total = BinaryOperatorAggregate(int, operator.add)Most users will interact with Pregel via a StateGraph (Graph API) or via an entrypoint (Functional API).
However, for advanced use cases, Pregel can be used directly. If you're not sure whether you need to use Pregel directly, then the answer is probably no
Here are some examples to give you a sense of how it works:
Implements the logic for reading state from CONFIG_KEY_READ. Usable both as a runnable as well as a static method to call imperatively.
A node in a Pregel graph. This won't be invoked as a runnable by the graph itself, but instead acts as a container for the components necessary to make a PregelExecutableTask for a node.
Implements the logic for sending writes to CONFIG_KEY_SEND. Can be used as a runnable or as a static method to call imperatively.
Configuration for caching nodes.
One or more commands to update the graph's state and send messages to nodes.
Configuration for retrying nodes.
A message or packet to send to a specific node in the graph.
The Send class is used within a StateGraph's conditional edges to
dynamically invoke a node with a custom state at the next step.
Importantly, the sent state can differ from the core graph's state, allowing for flexible and dynamic workflow management.
One such example is a "map-reduce" workflow where your graph invokes the same node multiple times in parallel with different states, before aggregating the results back into the main graph's state.
A specific LangGraphDeprecationWarning subclass defining functionality deprecated since LangGraph v0.5.0
A specific LangGraphDeprecationWarning subclass defining functionality deprecated since LangGraph v1.0.0
A graph whose nodes communicate by reading and writing to a shared state.
The signature of each node is State -> Partial<State>.
Each state key can optionally be annotated with a reducer function that
will be used to aggregate the values of that key received from multiple nodes.
The signature of a reducer function is (Value, Value) -> Value.
StateGraph is a builder class and cannot be used directly for execution.
You must first call .compile() to create an executable graph that supports
methods like invoke(), stream(), astream(), and ainvoke(). See the
CompiledStateGraph documentation for more details.