AI / A CONCEPT NOTE

Memory Systems

giving agents short-term and long-term recall beyond the context window

~80 sec read

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

  1. Short-term memory

    the last N turns of conversation are kept in the prompt context — the agent remembers what you just said.

  2. Summarization

    when the conversation exceeds the context window, older turns are summarized and compressed to preserve key facts while freeing space.

  3. Long-term store

    important facts ('user prefers Python', 'project uses Terraform') are extracted and saved to a vector DB or key-value store.

  4. 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.

EXAMPLE 01 · REFERENCE

add conversation memory with LangChain

python -c "from langchain.memory import ConversationBufferMemory; memory = ConversationBufferMemory(); memory.save_context({'input': 'hi'}, {'output': 'hello'})"

EXAMPLE 02 · REFERENCE

persist long-term memory with Mem0

python -c "from mem0 import Memory; m = Memory(); m.add('User prefers dark mode', user_id='supraj')"

Explore command anatomy in the CLI lab