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
    Pythonlanggraph

    langgraph

    Description

    LangGraph Logo LangGraph Logo

    Version Downloads Open Issues Docs

    Trusted by companies shaping the future of agents – including Klarna, Replit, Elastic, and more – LangGraph is a low-level orchestration framework for building, managing, and deploying long-running, stateful agents.

    Get started

    Install LangGraph:

    pip install -U langgraph
    

    Create a simple workflow:

    from langgraph.graph import START, StateGraph
    from typing_extensions import TypedDict
    
    class State(TypedDict):
        text: str
    
    def node_a(state: State) -> dict:
        return {"text": state["text"] + "a"}
    
    def node_b(state: State) -> dict:
        return {"text": state["text"] + "b"}
    
    graph = StateGraph(State)
    graph.add_node("node_a", node_a)
    graph.add_node("node_b", node_b)
    graph.add_edge(START, "node_a")
    graph.add_edge("node_a", "node_b")
    
    print(graph.compile().invoke({"text": ""}))
    # {'text': 'ab'}

    Get started with the LangGraph Quickstart.

    To quickly build agents with LangChain's create_agent (built on LangGraph), see the LangChain Agents documentation.

    Core benefits

    LangGraph provides low-level supporting infrastructure for any long-running, stateful workflow or agent. LangGraph does not abstract prompts or architecture, and provides the following central benefits:

    • Durable execution: Build agents that persist through failures and can run for extended periods, automatically resuming from exactly where they left off.
    • Human-in-the-loop: Seamlessly incorporate human oversight by inspecting and modifying agent state at any point during execution.
    • Comprehensive memory: Create truly stateful agents with both short-term working memory for ongoing reasoning and long-term persistent memory across sessions.
    • Debugging with LangSmith: Gain deep visibility into complex agent behavior with visualization tools that trace execution paths, capture state transitions, and provide detailed runtime metrics.
    • Production-ready deployment: Deploy sophisticated agent systems confidently with scalable infrastructure designed to handle the unique challenges of stateful, long-running workflows.

    LangGraph’s ecosystem

    While LangGraph can be used standalone, it also integrates seamlessly with any LangChain product, giving developers a full suite of tools for building agents. To improve your LLM application development, pair LangGraph with:

    • LangSmith — Helpful for agent evals and observability. Debug poor-performing LLM app runs, evaluate agent trajectories, gain visibility in production, and improve performance over time.
    • LangSmith Deployment — Deploy and scale agents effortlessly with a purpose-built deployment platform for long running, stateful workflows. Discover, reuse, configure, and share agents across teams — and iterate quickly with visual prototyping in LangGraph Studio.
    • LangChain – Provides integrations and composable components to streamline LLM application development.

    [!NOTE] Looking for the JS version of LangGraph? See the JS repo and the JS docs.

    Additional resources

    • Guides: Quick, actionable code snippets for topics such as streaming, adding memory & persistence, and design patterns (e.g. branching, subgraphs, etc.).
    • Reference: Detailed reference on core classes, methods, how to use the graph and checkpointing APIs, and higher-level prebuilt components.
    • Examples: Guided examples on getting started with LangGraph.
    • LangChain Forum: Connect with the community and share all of your technical questions, ideas, and feedback.
    • LangChain Academy: Learn the basics of LangGraph in our free, structured course.
    • Case studies: Hear how industry leaders use LangGraph to ship AI applications at scale.

    Acknowledgements

    LangGraph is inspired by Pregel and Apache Beam. The public interface draws inspiration from NetworkX. LangGraph is built by LangChain Inc, the creators of LangChain, but can be used without LangChain.

    Classes

    Class

    ErrorCode

    Class

    GraphRecursionError

    Raised when the graph has exhausted the maximum number of steps.

    Class

    InvalidUpdateError

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

    Class

    GraphBubbleUp

    Class

    GraphInterrupt

    Raised when a subgraph is interrupted, suppressed by the root graph.

    Class

    ParentCommand

    Class

    EmptyInputError

    Raised when graph receives an empty input.

    Class

    TaskNotFound

    Raised when the executor is unable to find a task (for distributed mode).

    Class

    ExecutionInfo

    Read-only execution info/metadata for the execution of current thread/run/node.

    Class

    Runtime

    Convenience class that bundles run-scoped context and other runtime utilities.

    Class

    ToolOutputMixin

    Class

    TaskPayload

    Payload for a task start event.

    Class

    TaskResultPayload

    Payload for a task result event.

    Class

    CheckpointTask

    A task entry within a CheckpointPayload.

    Class

    CheckpointPayload

    Payload for a checkpoint event.

    Class

    ValuesStreamPart

    Stream part emitted for stream_mode="values".

    Class

    UpdatesStreamPart

    Stream part emitted for stream_mode="updates".

    Class

    MessagesStreamPart

    Stream part emitted for stream_mode="messages".

    Class

    CustomStreamPart

    Stream part emitted for stream_mode="custom".

    Class

    CheckpointStreamPart

    Stream part emitted for stream_mode="checkpoints".

    Class

    TasksStreamPart

    Stream part emitted for stream_mode="tasks".

    Class

    DebugStreamPart

    Stream part emitted for stream_mode="debug".

    Class

    GraphOutput

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

    Class

    RetryPolicy

    Configuration for retrying nodes.

    Class

    CachePolicy

    Configuration for caching nodes.

    Class

    Interrupt

    Information about an interrupt that occurred in a node.

    Class

    StateUpdate

    Class

    PregelTask

    A Pregel task.

    Class

    CacheKey

    Cache key for a task.

    Class

    PregelExecutableTask

    Class

    StateSnapshot

    Snapshot of the state of the graph at the beginning of a step.

    Class

    Send

    A message or packet to send to a specific node in the graph.

    Class

    Command

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

    Class

    Overwrite

    Bypass a reducer and write the wrapped value directly to a BinaryOperatorAggregate channel.

    Class

    LangGraphDeprecationWarning

    A LangGraph specific deprecation warning.

    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

    LangGraphDeprecatedSinceV11

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

    Class

    Topic

    A configurable PubSub Topic.

    Class

    BaseChannel

    Base class for all channels.

    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().

    Class

    EphemeralValue

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

    Class

    AnyValue

    Stores the last value received, assumes that if multiple values are

    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

    BinaryOperatorAggregate

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

    Class

    UntrackedValue

    Stores the last value received, never checkpointed.

    Class

    StateGraph

    A graph whose nodes communicate by reading and writing to a shared state.

    Class

    CompiledStateGraph

    Class

    UIMessage

    A message type for UI updates in LangGraph.

    Class

    RemoveUIMessage

    A message type for removing UI components in LangGraph.

    Class

    StateNodeSpec

    Class

    MessagesState

    Class

    BranchSpec

    Class

    entrypoint

    Define a LangGraph workflow using the entrypoint decorator.

    Class

    final

    A primitive that can be returned from an entrypoint.

    Class

    FunctionNonLocals

    Get the nonlocal variables accessed of a function.

    Class

    NonLocals

    Get nonlocal variables accessed.

    Class

    SyncAsyncFuture

    Class

    NodeBuilder

    Class

    Pregel

    Pregel manages the runtime behavior for LangGraph applications.

    Class

    ChannelWriteEntry

    Class

    ChannelWriteTupleEntry

    Class

    ChannelWrite

    Implements the logic for sending writes to CONFIG_KEY_SEND.

    Class

    StreamMessagesHandler

    A callback handler that implements stream_mode=messages.

    Class

    PregelProtocol

    Class

    StreamProtocol

    Class

    PregelLoop

    Class

    SyncPregelLoop

    Class

    AsyncPregelLoop

    Class

    ChannelRead

    Implements the logic for reading state from CONFIG_KEY_READ.

    Class

    PregelNode

    A node in a Pregel graph. This won't be invoked as a runnable by the graph

    Class

    Submit

    Class

    BackgroundExecutor

    A context manager that runs sync tasks in the background.

    Class

    AsyncBackgroundExecutor

    A context manager that runs async tasks in the background.

    Class

    RemoteException

    Exception raised when an error occurs in the remote graph.

    Class

    RemoteGraph

    The RemoteGraph class is a client implementation for calling remote

    Class

    WritesProtocol

    Protocol for objects containing writes to be applied to checkpoint.

    Class

    PregelTaskWrites

    Simplest implementation of WritesProtocol, for usage with writes that

    Class

    Call

    Class

    LazyAtomicCounter

    Class

    Edge

    Class

    TriggerEdge

    Class

    FuturesDict

    Class

    PregelRunner

    Responsible for executing a set of Pregel tasks concurrently, committing

    Class

    IsLastStepManager

    Class

    RemainingStepsManager

    Class

    ManagedValue

    Class

    ReplayState

    Tracks which subgraphs have already loaded their pre-replay checkpoint.

    Class

    PregelScratchpad

    Class

    AsyncQueue

    Async unbounded FIFO queue with a wait() method.

    Class

    Semaphore

    Semaphore subclass with a wait() method.

    Class

    SyncQueue

    Unbounded FIFO queue with a wait() method.

    Class

    TypedDictLikeV1

    Protocol to represent types that behave like TypedDicts

    Class

    TypedDictLikeV2

    Protocol to represent types that behave like TypedDicts

    Class

    DataclassLike

    Protocol to represent types that behave like dataclasses.

    Class

    DeprecatedKwargs

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

    Class

    StrEnum

    A string enum.

    Class

    RunnableCallable

    A much simpler version of RunnableLambda that requires sync and async functions.

    Class

    RunnableSeq

    Sequence of Runnable, where the output of each is the input of the next.

    Class

    NodeInterrupt

    deprecated

    Raised by a node to interrupt execution.

    Class

    MessageGraph

    deprecated

    A StateGraph where every node receives a list of messages as input and returns one or more messages as output.

    Functions

    Function

    create_error_message

    Function

    get_runtime

    Get the runtime for the current graph run.

    Function

    get_config

    Function

    get_store

    Access LangGraph store from inside a graph node or entrypoint task at runtime.

    Function

    get_stream_writer

    Access LangGraph StreamWriter from inside a graph node or entrypoint task at runtime.

    Function

    ensure_valid_checkpointer

    Function

    interrupt

    Interrupt the graph with a resumable exception from within a node.

    Function

    push_ui_message

    Push a new UI message to update the UI state.

    Function

    delete_ui_message

    Delete a UI message by ID from the UI state.

    Function

    ui_message_reducer

    Merge two lists of UI messages, supporting removing UI messages.

    Function

    add_messages

    Merges two lists of messages, updating existing messages by ID.

    Function

    push_message

    Write a message manually to the messages / messages-tuple stream mode.

    Function

    task

    Define a LangGraph task using the task decorator.

    Function

    get_new_channel_versions

    Get subset of current_versions that are newer than previous_versions.

    Function

    find_subgraph_pregel

    Function

    get_function_nonlocals

    Get the nonlocal variables accessed by a function.

    Function

    is_xxh3_128_hexdigest

    Check if the given string matches the format of xxh3_128_hexdigest.

    Function

    identifier

    Return the module and name of an object.

    Function

    get_runnable_for_entrypoint

    Function

    get_runnable_for_task

    Function

    call

    Function

    empty_checkpoint

    Function

    create_checkpoint

    Create a checkpoint for the given channels.

    Function

    channels_from_checkpoint

    Get channels from a checkpoint.

    Function

    copy_checkpoint

    Function

    map_debug_tasks

    Produce "task" events for stream_mode=debug.

    Function

    is_multiple_channel_write

    Return True if the payload already wraps multiple writes from the same channel.

    Function

    map_task_result_writes

    Folds task writes into a result dict and aggregates multiple writes to the same channel.

    Function

    map_debug_task_results

    Produce "task_result" events for stream_mode=debug.

    Function

    rm_pregel_keys

    Remove pregel-specific keys from the config.

    Function

    map_debug_checkpoint

    Produce "checkpoint" events for stream_mode=debug.

    Function

    tasks_w_writes

    Apply writes / subgraph states to tasks to be returned in a StateSnapshot.

    Function

    get_colored_text

    Get colored text.

    Function

    get_bolded_text

    Get bolded text.

    Function

    validate_graph

    Function

    validate_keys

    Function

    DuplexStream

    Function

    gated

    A coroutine that waits for a semaphore before running another coroutine.

    Function

    next_tick

    A function that yields control to other threads before running another function.

    Function

    read_channel

    Function

    read_channels

    Function

    map_command

    Map input chunk to a sequence of pending writes in the form (channel, value).

    Function

    map_input

    Map input chunk to a sequence of pending writes in the form (channel, value).

    Function

    map_output_values

    Map pending writes (a sequence of tuples (channel, value)) to output chunk.

    Function

    map_output_updates

    Map pending writes (a sequence of tuples (channel, value)) to output chunk.

    Function

    run_with_retry

    Run a task with retries.

    Function

    arun_with_retry

    Run a task asynchronously with retries.

    Function

    should_interrupt

    Check if the graph should be interrupted based on current state.

    Function

    local_read

    Function injected under CONFIG_KEY_READ in task config, to read current state.

    Function

    increment

    Default channel versioning function, increments the current int version.

    Function

    apply_writes

    Apply writes from a set of tasks (usually the tasks from a Pregel step)

    Function

    prepare_next_tasks

    Prepare the set of tasks that will make up the next Pregel step.

    Function

    prepare_single_task

    Prepares a single task for the next Pregel step, given a task path, which

    Function

    prepare_push_task_functional

    Prepare a push task with an attached caller. Used for the functional API.

    Function

    prepare_push_task_send

    Function

    checkpoint_null_version

    Get the null version for the checkpoint, if available.

    Function

    task_path_str

    Generate a string representation of the task path.

    Function

    sanitize_untracked_values_in_send

    Pop any values belonging to UntrackedValue channels in Send.arg for safe checkpointing.

    Function

    draw_graph

    Get the graph for this Pregel instance.

    Function

    add_edge

    Add an edge to the graph.

    Function

    is_managed_value

    Function

    default_cache_key

    Default cache key function that uses the arguments and keyword arguments to generate a hashable key.

    Function

    get_field_default

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

    Function

    get_enhanced_type_hints

    Attempt to extract default values and descriptions from provided type, used for config schema.

    Function

    get_update_as_tuples

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

    Function

    get_cached_annotated_keys

    Return cached annotated keys for a Python class.

    Function

    recast_checkpoint_ns

    Remove task IDs from checkpoint namespace.

    Function

    patch_configurable

    Function

    patch_checkpoint_map

    Function

    merge_configs

    Merge multiple configs into one.

    Function

    patch_config

    Patch a config with new values.

    Function

    get_callback_manager_for_config

    Get a callback manager for a config.

    Function

    get_async_callback_manager_for_config

    Get an async callback manager for a config.

    Function

    ensure_config

    Return a config with all keys, merging any provided configs.

    Function

    chain_future

    Function

    run_coroutine_threadsafe

    Submit a coroutine object to a given event loop.

    Function

    apply_checkpointer_allowlist

    Function

    curated_core_allowlist

    Function

    build_serde_allowlist

    Function

    collect_allowlist_from_schemas

    Function

    set_config_context

    Set the child Runnable config + tracing context.

    Function

    is_async_callable

    Check if a function is async.

    Function

    is_async_generator

    Check if a function is an async generator.

    Function

    coerce_to_runnable

    Coerce a runnable-like object into a Runnable.

    Function

    get_fields

    Get the field names of a Pydantic model.

    Function

    create_model

    Create a pydantic model with the given field definitions.

    Function

    is_supported_by_pydantic

    Check if a given "complex" type is supported by pydantic.

    Function

    default_retry_on

    Modules

    Module

    langgraph

    Module

    version

    Exports package version.

    Module

    errors

    Module

    runtime

    Module

    config

    Module

    typing

    Module

    types

    Module

    warnings

    LangGraph specific warnings.

    Module

    constants

    Module

    channels

    Module

    topic

    Module

    base

    Module

    last_value

    Module

    ephemeral_value

    Module

    any_value

    Module

    named_barrier_value

    Module

    binop

    Module

    untracked_value

    Module

    graph

    Module

    state

    Module

    ui

    Module

    message

    Module

    utils

    Legacy utilities module, to be removed in v1.

    Module

    config

    Backwards compat imports for config utilities, to be removed in v1.

    Module

    runnable

    Backwards compat imports for runnable utilities, to be removed in v1.

    Module

    func

    Module

    pregel

    Module

    main

    Module

    debug

    Module

    protocol

    Module

    types

    Re-export types moved to langgraph.types

    Module

    remote

    Module

    managed

    Module

    is_last_step

    Module

    base

    Types

    Type

    Checkpointer

    Type of the checkpointer to use for a subgraph.

    Type

    AnyUIMessage

    Type

    StateNode

    Type

    Messages

    Type

    AnyFuture

    Type

    StateLike

    Type alias for state-like types.

    Type

    RunnableLike