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

    Functions

    Classes

    Type Aliases

    View source on GitHub
    attribute
    INTERRUPT
    attribute
    NS_END
    attribute
    NS_SEP
    attribute
    TASKS
    attribute
    EMPTY_SEQ: tuple[str, ...]
    attribute
    MISSING
    attribute
    END
    attribute
    START
    attribute
    TAG_HIDDEN
    attribute
    ManagedValueSpec: type[ManagedValue]
    attribute
    All: Literal['*']
    attribute
    ContextT
    attribute
    InputT
    attribute
    NodeInputT
    attribute
    OutputT
    attribute
    StateT
    attribute
    logger
    function
    get_cached_annotated_keys
    function
    get_field_default
    function
    get_update_as_tuples
    function
    create_model
    function
    coerce_to_runnable
    function
    create_error_message
    function
    is_managed_value
    function
    ensure_valid_checkpointer
    class
    DeprecatedKwargs
    class
    BaseChannel
    class
    BinaryOperatorAggregate
    class
    EphemeralValue
    class
    LastValue
    class
    LastValueAfterFinish
    class
    NamedBarrierValue
    class
    NamedBarrierValueAfterFinish
    class
    ErrorCode
    class
    InvalidUpdateError
    class
    ParentCommand
    class
    BranchSpec
    class
    StateNodeSpec
    class
    Pregel
    class
    ChannelRead
    class
    PregelNode
    class
    ChannelWrite
    class
    ChannelWriteEntry
    class
    ChannelWriteTupleEntry
    class
    CachePolicy
    class
    Command
    class
    RetryPolicy
    class
    Send
    class
    LangGraphDeprecatedSinceV05
    class
    LangGraphDeprecatedSinceV10
    class
    StateGraph
    class
    CompiledStateGraph
    typeAlias
    StateNode: TypeAlias
    typeAlias
    Checkpointer

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

    • INVALID_CONCURRENT_GRAPH_UPDATE
    • INVALID_GRAPH_NODE_RETURN_VALUE

    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:

    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.

    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.

    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.

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

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