Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

AI Agents · Class

MemorySaver

MemorySaver is LangGraph.js's in-memory checkpointer for saving graph checkpoints by thread. It is useful for development and testing, but its state is lost when the process restarts.

How it works

MemorySaver is an in-memory implementation of LangGraph's checkpoint saver. Attach it during graph compilation so checkpoints are associated with thread IDs and can support state continuity during the process lifetime.

Syntax

new MemorySaver(serde?: SerializerProtocol): MemorySaver

Parameters

NameTypeDescription
serdeSerializerProtocolOptional serializer used to encode and decode checkpoint data.

Returns

A MemorySaver instance that implements the checkpoint-saver interface.

Key points

  • MemorySaver implements the checkpointer role, allowing a graph to save and retrieve execution state.
  • Using it can provide conversational continuity and support workflows that pause, resume, or inspect graph execution.
  • Every invocation that should use checkpointed thread state needs a configurable thread_id.
  • Saved checkpoints represent graph state snapshots rather than an unrestricted application database.
  • The class is part of the LangGraph.js API and is exposed as MemorySaver.

Example: Use MemorySaver with a graph

import { MemorySaver } from "@langchain/langgraph";
import { StateGraph, StateSchema, START, END } from "@langchain/langgraph";

const State = new StateSchema({ value: { reducer: (a: number, b: number) => b, default: () => 0 } });
const graph = new StateGraph(State)
  .addNode("increment", (state) => ({ value: state.value + 1 }))
  .addEdge(START, "increment")
  .addEdge("increment", END)
  .compile({ checkpointer: new MemorySaver() });

const config = { configurable: { thread_id: "demo" } };
console.log(await graph.invoke({ value: 0 }, config));

Creates an in-memory checkpointer, attaches it when compiling a graph, and invokes that graph with a thread identifier.

When to use it

Development-time thread memory

Keep short-term conversation or graph state available across invocations that use the same thread during one process lifetime.

Testing checkpoint behavior

Run graph tests that need checkpoint-backed state without provisioning a database.

Human-in-the-loop and time-travel workflows

Pause, resume, inspect, or replay graph execution using in-memory checkpoints.

Interview questions

QWhat is MemorySaver and how is it used?

MemorySaver is a checkpointer that stores graph checkpoints in memory. Pass an instance to the graph's compile configuration, then provide a thread_id when invoking the graph so state is associated with that thread.

Follow-up: How would you preserve state across deployments? Replace MemorySaver with a durable checkpointer backed by persistent storage, because in-memory checkpoints disappear when the process exits.

QWhat does a checkpointer enable?

A checkpointer records graph state at supersteps and enables thread-scoped capabilities such as conversational continuity and human-in-the-loop workflows. MemorySaver provides that behavior without external persistence, while the process remains alive.

Follow-up: What identifier is required for checkpoint lookup? Supply configurable.thread_id; checkpoint_id can additionally select a particular checkpoint when needed.

QHow does thread-scoped memory work with MemorySaver?

Compile the graph with a MemorySaver instance and invoke it using a consistent thread_id. Reusing that identifier lets separate invocations refer to the same in-memory thread state.

Follow-up: Can separate application replicas share this state? No. Process-local memory is not a shared or durable persistence layer, so use an external checkpointer for that requirement.

  • BaseCheckpointSaver
  • SerializerProtocol
  • Checkpoint
  • StateGraph
  • CompiledGraph
  • thread_id
  • checkpoint_id

Source: MemorySaver | LangGraph.js API Reference. Checked 2026-10-15.