Unset sentinel value.
The last (maybe virtual) node in graph-style Pregel.
Special value to indicate that graph should interrupt on all nodes.
Durability mode for the graph execution.
'sync': Changes are persisted synchronously before the next step starts.'async': Changes are persisted asynchronously while the next step executes.'exit': Changes are persisted only when the graph exits.How the stream method should emit outputs.
"values": Emit all values in the state after each step, including interrupts.
When used with functional API, values are emitted once at the end of the workflow."updates": Emit only the node or task names and updates returned by the nodes or tasks after each step.
If multiple updates are made in the same step (e.g. multiple nodes are run) then those updates are emitted separately."custom": Emit custom data using from inside nodes or tasks using StreamWriter."messages": Emit LLM messages token-by-token together with metadata for any LLM invocations inside nodes or tasks."checkpoints": Emit an event when a checkpoint is created, in the same format as returned by get_state()."tasks": Emit events when tasks start and finish, including their results and errors."debug": Emit "checkpoints" and "tasks" events for debugging purposes.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 output of a StateGraph.
Defaults to StateT.
Type variable used to represent the state in a graph.
Return a config with all keys, merging any provided configs.
Merge multiple configs into one.
Patch a config with new values.
Remove task IDs from checkpoint namespace.
Create a pydantic model with the given field definitions.
Coerce a runnable-like object into a Runnable.
Apply writes from a set of tasks (usually the tasks from a Pregel step) to the checkpoint and channels, and return managed values writes to be applied externally.
Function injected under CONFIG_KEY_READ in task config, to read current state. Used by conditional edges to read a copy of the state with reflecting the writes from that node only.
Prepare the set of tasks that will make up the next Pregel step.
Return the module and name of an object.
Get channels from a checkpoint.
Create a checkpoint for the given channels.
Get the graph for this Pregel instance.
Map input chunk to a sequence of pending writes in the form (channel, value).
Get subset of current_versions that are newer than previous_versions.
Get bolded text.
Get colored text.
Apply writes / subgraph states to tasks to be returned in a StateSnapshot.
Async unbounded FIFO queue with a wait() method.
Subclassed from asyncio.Queue, adding a wait() method.
Unbounded FIFO queue with a wait() method. Adapted from pure Python implementation of queue.SimpleQueue.
Sequence of Runnable, where the output of each is the input of the next.
RunnableSeq is a simpler version of RunnableSequence that is internal to
LangGraph.
TypedDict to use for extra keyword arguments, enabling type checking warnings for deprecated arguments.
Base class for all channels.
A configurable PubSub Topic.
Raised when the graph has exhausted the maximum number of steps.
This prevents infinite loops. To increase the maximum number of steps,
run your graph with a config specifying a higher recursion_limit.
Troubleshooting guides:
Examples:
graph = builder.compile()
graph.invoke(
{"messages": [("user", "Hello, world!")]},
# The config is the second positional argument
{"recursion_limit": 1000},
)
Raised when attempting to update a channel with an invalid set of updates.
Troubleshooting guides:
Simplest implementation of WritesProtocol, for usage with writes that don't originate from a runnable task, eg. graph input, update_state, etc.
A callback handler that implements stream_mode=messages.
Collects messages from: (1) chat model stream events; and (2) node outputs.
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.
Configuration for retrying nodes.
Responsible for executing a set of Pregel tasks concurrently, committing their writes, yielding control to caller when there is output to emit, and interrupting other tasks if appropriate.
Implements the logic for sending writes to CONFIG_KEY_SEND. Can be used as a runnable or as a static method to call imperatively.
Convenience class that bundles run-scoped context and other runtime utilities.
This class is injected into graph nodes and middleware. It provides access to
context, store, stream_writer, and previous.
configRuntime does not include config. To access RunnableConfig, you can inject
it directly by adding a config: RunnableConfig parameter to your node function
(recommended), or use get_config() from langgraph.config.
ToolRuntime (from langgraph.prebuilt) is a subclass that provides similar
functionality but is designed specifically for tools. It shares context, store,
and stream_writer with Runtime, and adds tool-specific attributes like config,
state, and tool_call_id.
Example:
from typing import TypedDict
from langgraph.graph import StateGraph
from dataclasses import dataclass
from langgraph.runtime import Runtime
from langgraph.store.memory import InMemoryStore
@dataclass
class Context: # (1)!
user_id: str
class State(TypedDict, total=False):
response: str
store = InMemoryStore() # (2)!
store.put(("users",), "user_123", {"name": "Alice"})
def personalized_greeting(state: State, runtime: Runtime[Context]) -> State:
'''Generate personalized greeting using runtime context and store.'''
user_id = runtime.context.user_id # (3)!
name = "unknown_user"
if runtime.store:
if memory := runtime.store.get(("users",), user_id):
name = memory.value["name"]
response = f"Hello {name}! Nice to see you again."
return {"response": response}
graph = (
StateGraph(state_schema=State, context_schema=Context)
.add_node("personalized_greeting", personalized_greeting)
.set_entry_point("personalized_greeting")
.set_finish_point("personalized_greeting")
.compile(store=store)
)
result = graph.invoke({}, context=Context(user_id="user_123"))
print(result)
# > {'response': 'Hello Alice! Nice to see you again.'}
user_id.Configuration for caching nodes.
One or more commands to update the graph's state and send messages to nodes.
Information about an interrupt that occurred in a node.
interrupt_id was introduced as a propertyThe following attributes have been removed:
nswhenresumableinterrupt_id, deprecated in favor of idA 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.
Snapshot of the state of the graph at the beginning of a step.
A specific LangGraphDeprecationWarning subclass defining functionality deprecated since LangGraph v1.0.0
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: