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
    Pythonlanggraphgraphstate
    Module●Since v0.1

    state

    Attributes

    attribute
    INTERRUPT
    attribute
    NS_END
    attribute
    NS_SEP
    attribute
    TASKS
    attribute
    EMPTY_SEQ: tuple[str, ...]

    An empty sequence of strings.

    attribute
    MISSING

    Unset sentinel value.

    attribute
    END

    The last (maybe virtual) node in graph-style Pregel.

    attribute
    START

    The first (maybe virtual) node in graph-style Pregel.

    attribute
    TAG_HIDDEN

    Tag to hide a node/edge from certain tracing/streaming environments.

    attribute
    ManagedValueSpec: type[ManagedValue]
    attribute
    All: Literal['*']

    Special value to indicate that graph should interrupt on all nodes.

    attribute
    ContextT

    Type variable used to represent graph run scoped context.

    Defaults to None.

    attribute
    InputT

    Type variable used to represent the input to a StateGraph.

    Defaults to StateT.

    attribute
    NodeInputT

    Type variable used to represent the input to a node.

    attribute
    OutputT

    Type variable used to represent the output of a StateGraph.

    Defaults to StateT.

    attribute
    StateT

    Type variable used to represent the state in a graph.

    attribute
    logger

    Functions

    function
    get_cached_annotated_keys

    Return cached annotated keys for a Python class.

    function
    get_field_default

    Determine the default value for a field in a state schema.

    function
    get_update_as_tuples

    Get Pydantic state update as a list of (key, value) tuples.

    function
    create_model

    Create a pydantic model with the given field definitions.

    function
    coerce_to_runnable

    Coerce a runnable-like object into a Runnable.

    function
    create_error_message
    function
    is_managed_value
    function
    ensure_valid_checkpointer

    Classes

    class
    DeprecatedKwargs

    TypedDict to use for extra keyword arguments, enabling type checking warnings for deprecated arguments.

    class
    BaseChannel

    Base class for all channels.

    class
    BinaryOperatorAggregate

    Stores the result of applying a binary operator to the current value and each new value.

    import operator  total = Channels.BinaryOperatorAggregate(int, operator.add)
    class
    EphemeralValue

    Stores the value received in the step immediately preceding, clears after.

    class
    LastValue

    Stores the last value received, can receive at most one value per step.

    class
    LastValueAfterFinish

    Stores the last value received, but only made available after finish(). Once made available, clears the value.

    class
    NamedBarrierValue

    A channel that waits until all named values are received before making the value available.

    class
    NamedBarrierValueAfterFinish

    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.

    class
    ErrorCode
    class
    InvalidUpdateError

    Raised when attempting to update a channel with an invalid set of updates.

    Troubleshooting guides:

    • INVALID_CONCURRENT_GRAPH_UPDATE
    • INVALID_GRAPH_NODE_RETURN_VALUE
    class
    ParentCommand
    class
    BranchSpec
    class
    StateNodeSpec
    class
    Pregel

    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:

    class
    ChannelRead

    Implements the logic for reading state from CONFIG_KEY_READ. Usable both as a runnable as well as a static method to call imperatively.

    class
    PregelNode

    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.

    class
    ChannelWrite

    Implements the logic for sending writes to CONFIG_KEY_SEND. Can be used as a runnable or as a static method to call imperatively.

    class
    ChannelWriteEntry
    class
    ChannelWriteTupleEntry
    class
    CachePolicy

    Configuration for caching nodes.

    class
    Command

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

    class
    RetryPolicy

    Configuration for retrying nodes.

    class
    Send

    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.

    class
    LangGraphDeprecatedSinceV05

    A specific LangGraphDeprecationWarning subclass defining functionality deprecated since LangGraph v0.5.0

    class
    LangGraphDeprecatedSinceV10

    A specific LangGraphDeprecationWarning subclass defining functionality deprecated since LangGraph v1.0.0

    class
    StateGraph

    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.

    Warning

    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.

    class
    CompiledStateGraph

    Type Aliases

    typeAlias
    StateNode: TypeAlias
    typeAlias
    Checkpointer

    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.
    View source on GitHub