LangChain Reference home pageLangChain ReferenceLangChain Reference
  • GitHub
  • Main Docs
Deep Agents
LangChain
LangGraph
Integrations
LangSmith
  • Overview
    • Overview
    • Graphs
    • Functional API
    • Pregel
    • Checkpointing
    • Storage
    • Caching
    • Types
    • Runtime
    • Config
    • Errors
    • Constants
    • Channels
    • Agents
    LangGraph CLI
    LangGraph SDK
    LangGraph Supervisor
    LangGraph Swarm
    ⌘I

    LangChain Assistant

    Ask a question to get started

    Enter to send•Shift+Enter new line

    Menu

    OverviewGraphsFunctional APIPregelCheckpointingStorageCachingTypesRuntimeConfigErrorsConstantsChannelsAgents
    LangGraph CLI
    LangGraph SDK
    LangGraph Supervisor
    LangGraph Swarm
    Language
    Theme
    Pythonlanggraphpregelmain
    Module●Since v0.6

    main

    Attributes

    attribute
    CACHE_NS_WRITES
    attribute
    CONF

    Functions

    Classes

    Type Aliases

    View source on GitHub
    attribute
    CONFIG_KEY_CACHE
    attribute
    CONFIG_KEY_CHECKPOINT_ID
    attribute
    CONFIG_KEY_CHECKPOINT_NS
    attribute
    CONFIG_KEY_CHECKPOINTER
    attribute
    CONFIG_KEY_DURABILITY
    attribute
    CONFIG_KEY_NODE_FINISHED
    attribute
    CONFIG_KEY_READ
    attribute
    CONFIG_KEY_RUNNER_SUBMIT
    attribute
    CONFIG_KEY_RUNTIME
    attribute
    CONFIG_KEY_SEND
    attribute
    CONFIG_KEY_STREAM
    attribute
    CONFIG_KEY_TASK_ID
    attribute
    CONFIG_KEY_THREAD_ID
    attribute
    ERROR
    attribute
    INPUT
    attribute
    INTERRUPT
    attribute
    NS_END
    attribute
    NS_SEP
    attribute
    NULL_TASK_ID
    attribute
    PUSH
    attribute
    TASKS
    attribute
    MISSING
    attribute
    END
    attribute
    ManagedValueSpec: type[ManagedValue]
    attribute
    DEFAULT_BOUND
    attribute
    StreamChunk: tuple[tuple[str, ...], str, Any]
    attribute
    DEFAULT_RUNTIME
    attribute
    All: Literal['*']
    attribute
    Durability: Literal['sync', 'async', 'exit']
    attribute
    StreamMode: Literal['values', 'updates', 'checkpoints', 'tasks', 'debug', 'messages', 'custom']
    attribute
    StreamPart
    attribute
    ContextT
    attribute
    InputT
    attribute
    OutputT
    attribute
    StateT
    function
    ensure_config
    function
    merge_configs
    function
    patch_checkpoint_map
    function
    patch_config
    function
    patch_configurable
    function
    recast_checkpoint_ns
    function
    create_model
    function
    coerce_to_runnable
    function
    get_config
    function
    create_error_message
    function
    apply_writes
    function
    local_read
    function
    prepare_next_tasks
    function
    identifier
    function
    channels_from_checkpoint
    function
    copy_checkpoint
    function
    create_checkpoint
    function
    empty_checkpoint
    function
    draw_graph
    function
    map_input
    function
    read_channels
    function
    get_new_channel_versions
    function
    validate_graph
    function
    validate_keys
    function
    get_bolded_text
    function
    get_colored_text
    function
    tasks_w_writes
    function
    ensure_valid_checkpointer
    class
    AsyncQueue
    class
    SyncQueue
    class
    RunnableSeq
    class
    DeprecatedKwargs
    class
    BaseChannel
    class
    Topic
    class
    ErrorCode
    class
    GraphRecursionError
    class
    InvalidUpdateError
    class
    PregelTaskWrites
    class
    AsyncPregelLoop
    class
    SyncPregelLoop
    class
    StreamMessagesHandler
    class
    PregelNode
    class
    RetryPolicy
    class
    PregelRunner
    class
    ChannelWrite
    class
    ChannelWriteEntry
    class
    PregelProtocol
    class
    StreamProtocol
    class
    Runtime
    class
    ServerInfo
    class
    CachePolicy
    class
    Command
    class
    GraphOutput
    class
    Interrupt
    class
    Send
    class
    StateSnapshot
    class
    StateUpdate
    class
    LangGraphDeprecatedSinceV10
    class
    NodeBuilder
    class
    Pregel
    typeAlias
    RunnableLike
    typeAlias
    Checkpointer

    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:

    • GRAPH_RECURSION_LIMIT

    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:

    • INVALID_CONCURRENT_GRAPH_UPDATE
    • INVALID_GRAPH_NODE_RETURN_VALUE

    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.

    Metadata injected by LangGraph Server. None when running open-source LangGraph without LangSmith deployments.

    Configuration for caching nodes.

    One or more commands to update the graph's state and send messages to nodes.

    Typed container returned by invoke() / ainvoke() with version="v2".

    Information about an interrupt that occurred in a node.

    Changed in version v0.4.0
    • interrupt_id was introduced as a property
    Changed in version v0.6.0

    The following attributes have been removed:

    • ns
    • when
    • resumable
    • interrupt_id, deprecated in favor of id

    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.

    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.

    Overview

    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:

    • Plan: Determine which actors to execute in this step. For example, in the first step, select the actors that subscribe to the special input channels; in subsequent steps, select the actors that subscribe to channels updated in the previous step.
    • Execution: Execute all selected actors in parallel, until all complete, or one fails, or a timeout is reached. During this phase, channel updates are invisible to actors until the next step.
    • Update: Update the channels with the values written by the actors in this step.

    Repeat until no actors are selected for execution, or a maximum number of steps is reached.

    Actors

    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

    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:

    Basic channels: LastValue and Topic

    • 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 next
    • Topic: 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.

    Advanced channels: Context and BinaryOperatorAggregate

    • 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)

    Examples

    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

    • you should use the Graph API or Functional API instead. These are higher-level interfaces that will compile down to Pregel under the hood.

    Here are some examples to give you a sense of how it works:

    Type of the checkpointer to use for a subgraph.

    • True enables persistent checkpointing for this subgraph.
    • False disables checkpointing, even if the parent graph has a checkpointer.
    • None inherits checkpointer from the parent graph.

    A discriminated union of all v2 stream part types.

    Use part["type"] to narrow the type:

    async for part in graph.astream(input, version="v2"):
        if part["type"] == "values":
            part["data"]  # OutputT — full state (pydantic/dataclass/dict)
        elif part["type"] == "messages":
            part["data"]  # tuple[BaseMessage, dict] — (message, metadata)
        elif part["type"] == "custom":
            part["data"]  # Any — user-defined

    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, previous, and execution_info.

    Accessing config

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

    Note

    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.'}
    1. Define a schema for the runtime context.
    2. Create a store to persist memories and other information.
    3. Use the runtime context to access the user_id.