LangChain Reference home pageLangChain ReferenceLangChain Reference
  • GitHub
  • Main Docs
Deep Agents
LangChain
LangGraph
Integrations
LangSmith
  • Overview
  • LangGraph Checkpoint
    LangGraph Store
    Checkpoint Postgres
    Store Postgres
    Checkpoint SQLite
    LangGraph Prebuilt
    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

    LangGraph Checkpoint
    LangGraph Store
    Checkpoint Postgres
    Store Postgres
    Checkpoint SQLite
    LangGraph Prebuilt
    LangGraph CLI
    LangGraph SDK
    LangGraph Supervisor
    LangGraph Swarm
    Language
    Theme
    Pythonlanggraph.checkpointmemoryInMemorySaver
    Class●Since v2.0

    InMemorySaver

    Copy
    InMemorySaver(
      self,
      *,
      serde: SerializerProtocol | None = None,
      factory: type[defaultdict] = defaultdict

    Bases

    BaseCheckpointSaver[str]AbstractContextManagerAbstractAsyncContextManager

    Used in Docs

    • Build a multi-source knowledge base with routing
    • Build a personal assistant with subagents
    • Build a SQL assistant with on-demand skills
    • Build a voice agent with LangChain
    • Build customer support with handoffs

    Constructors

    Attributes

    Methods

    Inherited fromBaseCheckpointSaver

    Attributes

    Aserde: SerializerProtocolAconfig_specs: list
    —

    Define the configuration options for the checkpoint saver.

    Methods

    Mget
    —

    Fetch a checkpoint using the given configuration.

    View source on GitHub
    )
    M
    delete_for_runs
    —

    Delete all checkpoints and writes associated with the given run IDs.

    Mcopy_thread
    —

    Copy all checkpoints and writes from one thread to another.

    Mprune
    —

    Prune checkpoints for the given threads.

    Maget
    —

    Asynchronously fetch a checkpoint using the given configuration.

    Madelete_for_runs
    —

    Asynchronously delete all checkpoints and writes for the given run IDs.

    Macopy_thread
    —

    Asynchronously copy all checkpoints and writes from one thread to another.

    Maprune
    —

    Asynchronously prune checkpoints for the given threads.

    Mwith_allowlist
    —

    Return a shallow clone with a derived msgpack allowlist.

    Parameters

    NameTypeDescription
    serdeSerializerProtocol | None
    Default:None
    constructor
    __init__
    NameType
    serdeSerializerProtocol | None
    factorytype[defaultdict]
    attribute
    storage: defaultdict[str, dict[str, dict[str, tuple[tuple[str, bytes], tuple[str, bytes], str | None]]]]
    attribute
    writes: defaultdict[tuple[str, str, str], dict[tuple[str, int], tuple[str, str, tuple[str, bytes], str]]]
    attribute
    blobs: dict[tuple[str, str, str, str | int | float], tuple[str, bytes]]
    attribute
    stack
    method
    get_delta_channel_history
    method
    aget_delta_channel_history
    method
    get_tuple
    method
    list
    method
    put
    method
    put_writes
    method
    delete_thread
    method
    aget_tuple
    method
    alist
    method
    aput
    method
    aput_writes
    method
    adelete_thread
    method
    get_next_version

    An in-memory checkpoint saver.

    This checkpoint saver stores checkpoints in memory using a defaultdict.

    Note:

    Only use InMemorySaver for debugging or testing purposes. For production use cases we recommend installing langgraph-checkpoint-postgres and using PostgresSaver / AsyncPostgresSaver.

    If you are using LangSmith Deployment, no checkpointer needs to be specified. The correct managed checkpointer will be used automatically.

    Example:

    import asyncio
    
    from langgraph.checkpoint.memory import InMemorySaver
    from langgraph.graph import StateGraph
    
    builder = StateGraph(int)
    builder.add_node("add_one", lambda x: x + 1)
    builder.set_entry_point("add_one")
    builder.set_finish_point("add_one")
    
    memory = InMemorySaver()
    graph = builder.compile(checkpointer=memory)
    coro = graph.ainvoke(1, {"configurable": {"thread_id": "thread-1"}})
    asyncio.run(coro)  # Output: 2

    The serializer to use for serializing and deserializing checkpoints.

    Override: walk the parent chain ONCE for all requested channels.

    Each channel terminates independently at the nearest ancestor whose stored blob is non-empty. Other channels keep walking until they find their own terminator or hit the root.

    A blob is the value AT its ancestor, prior to the writes stored under that same ancestor (those writes produce its child, which is on the path to the target). This holds for _DeltaSnapshot blobs and for pre-delta plain values alike, so the seed ancestor's own writes are always collected. Writes at ancestors older than the seed are subsumed by the seed value and are never reached — the walk terminates there.

    Get a checkpoint tuple from the in-memory storage.

    This method retrieves a checkpoint tuple from the in-memory storage based on the provided config. If the config contains a checkpoint_id key, the checkpoint with the matching thread ID and timestamp is retrieved. Otherwise, the latest checkpoint for the given thread ID is retrieved.

    List checkpoints from the in-memory storage.

    This method retrieves a list of checkpoint tuples from the in-memory storage based on the provided criteria.

    Save a checkpoint to the in-memory storage.

    This method saves a checkpoint to the in-memory storage. The checkpoint is associated with the provided config.

    Save a list of writes to the in-memory storage.

    This method saves a list of writes to the in-memory storage. The writes are associated with the provided config.

    Delete all checkpoints and writes associated with a thread ID.

    Asynchronous version of get_tuple.

    This method is an asynchronous wrapper around get_tuple that runs the synchronous method in a separate thread using asyncio.

    Asynchronous version of list.

    This method is an asynchronous wrapper around list that runs the synchronous method in a separate thread using asyncio.

    Asynchronous version of put.

    Asynchronous version of put_writes.

    This method is an asynchronous wrapper around put_writes that runs the synchronous method in a separate thread using asyncio.

    Delete all checkpoints and writes associated with a thread ID.

    Advertisement
    Advertisement