AI / A CONCEPT NOTE
Memory Systems
giving agents short-term and long-term recall beyond the context window
Overview · mechanism
pitfall · examples
01 / THE SHORT VERSION
The idea in a few sentences.
LLMs have no inherent memory — each request starts from scratch. Memory systems solve this by maintaining state across interactions. Short-term memory (conversation buffer, sliding window) keeps recent turns in the context. Long-term memory (vector stores, key-value databases) persists facts, preferences, and past interactions that can be retrieved when relevant. Together they let an agent remember who you are, what you discussed last week, and what your preferences are.
02 / FOLLOW THE MECHANISM
How memory is stored and recalled
Short-term memory
the last N turns of conversation are kept in the prompt context — the agent remembers what you just said.
Summarization
when the conversation exceeds the context window, older turns are summarized and compressed to preserve key facts while freeing space.
Long-term store
important facts ('user prefers Python', 'project uses Terraform') are extracted and saved to a vector DB or key-value store.
Retrieval
on each new query, the memory system searches long-term storage for relevant past context and injects it into the prompt.
04 / COMMAND NOTES
Read the command, then the result.
Inspect the flags and arguments before trying an example. Snippets can need local setup, replacement values, or resources in your own environment.
add conversation memory with LangChain
python -c "from langchain.memory import ConversationBufferMemory; memory = ConversationBufferMemory(); memory.save_context({'input': 'hi'}, {'output': 'hello'})"persist long-term memory with Mem0
python -c "from mem0 import Memory; m = Memory(); m.add('User prefers dark mode', user_id='supraj')"05 / CHECK YOURSELF
Could you explain Memory Systems to a teammate?
Try it out loud in two sentences: what it is, and the one detail that changes the picture. If you stall, the gap is the part to reread.
Up next in AI engineeringTokens & Contextwhat the model can 'see'