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

AI Agents · Const

Long-term Memory

Long-term memory stores user- or application-specific data across sessions and conversational threads. LangGraph saves it as JSON documents in a store, addressed by a custom namespace and key.

How it works

Long-term memory stores JSON documents in a LangGraph store so agents can retain and recall user- or application-specific information across conversations. Memories are organized by a custom namespace and key, allowing data to be shared across threads rather than tied to one conversation.

Syntax

store.put(namespace, key, value)
store.get(namespace, key)

Key points

  • Long-term memory supports durable user or application data that remains available across sessions and threads.
  • A stored memory is not limited to the conversation that created it; any thread can retrieve it.
  • Applications can choose a scope such as a user, tenant, or application instead of relying only on thread identifiers.
  • Memory values use JSON-document storage, making structured application data suitable for persistence.

Common mistakes

  • Do not use thread-scoped state when information must persist across conversations; long-term data belongs in a custom namespace.
  • A namespace and key together identify a memory, so changing either can cause reads to miss previously stored data.

Example: Store and recall long-term memory

const store = new InMemoryStore();
const namespace = ["memories", userId];
await store.put(namespace, "preferences", {
  food: "vegetarian",
});
const memory = await store.get(namespace, "preferences");
console.log(memory?.value);

Stores and retrieves a JSON memory in a user-specific namespace.

When to use it

User preferences

Persisting a user's preferences so later conversations can personalize responses.

Cross-thread application data

Sharing facts or knowledge across multiple conversational threads in an application.

Custom-scoped memory

Keeping durable records scoped to a tenant, user, or other custom namespace.

Interview questions

QWhat distinguishes long-term memory from short-term memory?

Long-term memory persists user-specific or application-level data across conversations and sessions. Unlike short-term memory, it is shared across conversational threads and can be recalled in any thread.

Follow-up: How is long-term memory organized? It is stored as JSON documents in a store, with each document addressed by a custom namespace and distinct key.

QWhere does LangGraph keep long-term memories?

LangGraph stores long-term memories as JSON documents in a store. The store provides the persistence mechanism for saving and recalling those documents.

Follow-up: What should identify a memory? Use a stable custom namespace and key that represent the intended scope and record.

QHow are long-term memories addressed?

Namespaces define the scope for long-term memories, and keys distinguish individual records within that scope. This structure supports user-, application-, or other custom-scoped data.

Follow-up: Why not scope everything by thread ID? Thread scope is appropriate for short-term conversational state, while long-term memory must be available across threads.

  • short-term memory
  • stores
  • namespace
  • key
  • checkpointers
  • cross-thread persistence

Source: Memory overview. Checked 2026-10-15.