AI

Long Term Memory

AI Agents

Long-term memory is what an agent retains after the session ends: facts about the user, lessons from completed tasks, and domain knowledge built up over weeks of use. It lives outside the model — in databases, vector stores, or files — and survives restarts, new conversations, and even model upgrades. Where short-term memory is the context window itself, long-term memory is a persistence layer with two deliberate operations: writing (deciding what is worth keeping) and recall (retrieving the right memories back into context later).

This is the layer that makes an agent feel like it knows you. A coding agent that remembers your stack and conventions, a support agent that recalls last month’s incident, an assistant that stops re-asking your timezone — all of that is long-term memory doing its job. It is also how agents improve: persisting “approach X failed for task Y” turns yesterday’s mistakes into tomorrow’s shortcuts, something no context window can provide on its own.

In practice you will implement it as a store plus two hooks. After a session (or mid-session when something notable happens), an extraction step — often an LLM call — pulls out durable facts and writes them with metadata like user_id and timestamps. Before each new session or turn, a recall step queries the store, usually via embedding search the way a RAG pipeline retrieves documents, and injects the top matches into the prompt. Tools like LangGraph’s memory store, Mem0, or a plain Postgres-plus-pgvector setup all follow this pattern.

Resources

0/5 completed