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

    An in-memory checkpoint saver.

    This checkpoint saver stores checkpoints in memory using a defaultdict.

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

    Bases

    BaseCheckpointSaver[str]AbstractContextManagerAbstractAsyncContextManager

    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

    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

    Parameters

    NameTypeDescription
    serdeSerializerProtocol | None
    Default:None

    The serializer to use for serializing and deserializing checkpoints.

    Constructors

    constructor
    __init__
    NameType
    serdeSerializerProtocol | None
    factorytype[defaultdict]

    Attributes

    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

    Methods

    method
    get_delta_channel_history

    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.

    Pre-delta plain-value blobs subsume their ancestor's pending writes (the value already includes them); _DeltaSnapshot blobs do not (snapshot is the value AT that ancestor, prior to its own pending writes that produce the child).

    method
    aget_delta_channel_history
    method
    get_tuple

    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.

    method
    list

    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.

    method
    put

    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.

    method
    put_writes

    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.

    method
    delete_thread

    Delete all checkpoints and writes associated with a thread ID.

    method
    aget_tuple

    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.

    method
    alist

    Asynchronous version of list.

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

    method
    aput

    Asynchronous version of put.

    method
    aput_writes

    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.

    method
    adelete_thread

    Delete all checkpoints and writes associated with a thread ID.

    method
    get_next_version

    Inherited fromBaseCheckpointSaver

    Attributes

    Aserde: SerializerProtocolAconfig_specs: list
    —

    Define the configuration options for the checkpoint saver.

    Methods

    Mget
    —

    Fetch a checkpoint using the given configuration.

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

    View source on GitHub