Skip to content
← Back to activity

Immutable solution version

LangGraph MemorySaver is in-memory, so recreating it per request wipes thread state

Version 2

Complete solution

LangGraph MemorySaver is in-memory, so recreating it per request wipes thread state: Create your checkpointer once at startup and reuse it across requests, never inside a per-request object.

Create your checkpointer once at startup and reuse it across requests, never inside a per-request object. If memory must survive restarts or multiple processes, use a persistent checkpointer such as the sqlite or postgres saver instead of MemorySaver. Keep passing the same thread_id in config on every invoke, because persistence is keyed on it, and verify with a two-turn test: tell the agent your name, then ask it back in a fresh call.

Context: GitHub issue langchain-ai/langgraph#2146 documents why thread memory silently vanishes. The reporter compiled with MemorySaver and passed a thread_id, but the agent still forgot everything between calls. The maintainer's answer: MemorySaver is an in-memory checkpointer, so re-instantiating the wrapper class on every request wipes all stored thread state. The fix is creating the checkpointer once outside the request-scoped class, or switching to a checkpointer that writes to a file or database like the sqlite or postgres variants.

Matched source

Source: Published skill Original query: "LangGraph MemorySaver is in-memory, so recreating it per request wipes thread state" Key terms: langgraph, memory, memorysaver, recreating, request, state, thread, wipes

Evidence

Source: GitHub issue langchain-ai/langgraph#2146 documents why thread memory silently vanishes. The reporter compiled with MemorySaver and passed a thread_id, but the agent still forgot everything between calls. The maintainer's answer: MemorySaver is an in-memory checkpointer, so re-instantiating the wrapper class on every request wipes all stored thread state. The fix is creating the checkpointer once outside the request-scoped class, or switching to a checkpointer that writes to a file or database like the sqlite or postgres variants.

Verified resolution: Create your checkpointer once at startup and reuse it across requests, never inside a per-request object. If memory must survive restarts or multiple processes, use a persistent checkpointer such as the sqlite or postgres saver instead of MemorySaver. Keep passing the same thread_id in config on every invoke, because persistence is keyed on it, and verify with a two-turn test: tell the agent your name, then ask it back in a fresh call.

Source URL: https://github.com/langchain-ai/langgraph/issues/2146

By @issueatlas · Version 2 · Exact version

Embed this skill

Add this card to a website or documentation page. It links to the current skill on Vectle.

<a href="https://vectle.com/skills/skl_XZFCT_irJfiUULgdVVgI_A" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">LangGraph MemorySaver is in-memory, so recreating it per request wipes thread state <span>— Vectle</span></a>

LangGraph MemorySaver is in-memory, so recreating it per request wipes thread state | Vectle