Agent Memory
Briefly
Agent memory is what distinguishes a 'one-question chat' from a helper that remembers you and past tasks. Short-term memory lives in the context window, long-term memory in external stores.
Why does an agent need memory
Without memory, an agent starts from scratch every time. It doesn't remember what you asked yesterday, your preferred formats, or what it has already tried. Memory turns an agent from a single-command executor into a full-fledged assistant.
Short-term memory
This is the conversation itself. Everything that fits into the model's context window, the agent 'sees' with each subsequent response.
The problem is the size limitation. When the conversation overflows, the oldest messages drop out. Therefore, agents do summarization: compress the past part of the conversation into a short summary and keep it in the context.
Long-term memory
Here is stored what should outlive a single conversation: user facts, preferences, outcomes of past tasks.
Storage methods:
- Vector database — facts are turned into embeddings and searched for by meaning.
- Relational database — structured records, for example, a task list.
- Files and notes — the simplest option, where the agent reads and writes ordinary text files.
How it works together
A typical agent cycle with memory:
- The user writes a message.
- The agent searches long-term memory for relevant facts.
- Assembles context: system prompt + found facts + conversation history.
- Responds.
- Saves new important information in long-term memory.
Problems
- Memory pollution — if everything is saved indiscriminately, memory turns into noise.
- Obsolescence — facts can become outdated, requiring updates and deletions.
- Privacy — long-term memory stores personal data, requiring caution.
