User preferences
Persisting a user's preferences so later conversations can personalize responses.
AI Agents · Const
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.
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.
store.put(namespace, key, value)
store.get(namespace, key)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.
Persisting a user's preferences so later conversations can personalize responses.
Sharing facts or knowledge across multiple conversational threads in an application.
Keeping durable records scoped to a tenant, user, or other custom namespace.
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.
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.
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 memorystoresnamespacekeycheckpointerscross-thread persistence