Skip to main content
>_ supraj.dev
TOPIC AI
Memory Systems giving agents short-term and long-term recall beyond the context window
IN 10 SECONDS

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.

GOTCHA Memory retrieval is only as good as what was stored. If the extraction step misses an important fact or stores it with bad metadata, it'll never be recalled. Regularly audit your memory store for stale, duplicated, or contradictory entries — memory pollution degrades agent quality over time.
HOW MEMORY IS STORED AND RECALLED
01 Short-term memory the last N turns of conversation are kept in the prompt context — the agent remembers what you just said.
02 Summarization when the conversation exceeds the context window, older turns are summarized and compressed to preserve key facts while freeing space.
03 Long-term store important facts ('user prefers Python', 'project uses Terraform') are extracted and saved to a vector DB or key-value store.
04 Retrieval on each new query, the memory system searches long-term storage for relevant past context and injects it into the prompt.
POKE IT YOURSELF
python -c "from langchain.memory import ConversationBufferMemory; memory = ConversationBufferMemory(); memory.save_context({'input': 'hi'}, {'output': 'hello'})" — add conversation memory with LangChain
python -c "from mem0 import Memory; m = Memory(); m.add('User prefers dark mode', user_id='supraj')" — persist long-term memory with Mem0