Short-Term and Long-Term Memory of Agents
The architecture of multi-tier memory for autonomous agents. It distinguishes between Short-Term Memory (active context window of the current session) and Long-Term Memory (vector databases, user profile files, and episodic diaries).
1. Concept Overview & Systemic Problem
Humans do not keep every second of their lives in active working memory. You don't think about what you had for breakfast on May 14 last year, but if asked about your school teacher's name, your brain can instantly retrieve that fact from memory.
For an AI agent to become a true personal assistant or reliable business partner, it requires a similar multi-tiered system.
The memory architecture of an agent is divided into two levels:
- Short-Term Memory: RAM. This is the conversation you are currently exchanging in the open tab. When you close the chat, it clears.
- Long-Term Memory: SSD. This is a persistent knowledge base where your habits, preferences, contacts, and results of completed projects are stored.
A practical analogy: the difference between what you hold in your head right now and your personal diary in your desk drawer.
2. How the Agent Distributes Information Between Memory Levels
┌─────────────────────────────────────────────────────────────┐
│ TWO-TIER MEMORY ARCHITECTURE │
├─────────────────────────────────────────────────────────────┤
│ ⚡ SHORT-TERM MEMORY (LLM Context Window): │
│ - Current dialogue ('Show line #42 in the file') │
│ - Thought draft (<scratchpad>) │
│ - Recent compiler errors (lives until chat is closed) │
├─────────────────────────────────────────────────────────────┤
│ 💾 LONG-TERM MEMORY (External Database / Vector DB): │
│ ├── User Profile: 'Name is Elena, designer, Mac' │
│ ├── Company Rules: 'Brand colors: #00FF55, #111111' │
│ └── Episodic Experience: 'This client requests receipts in PDF' │
└─────────────────────────────────────────────────────────────┘
3. Four Types of Knowledge in the Mind of an Intelligent Agent
- Working Memory: the current task for the next 2 minutes.
- Episodic Memory: the chronology of previous actions (what was done yesterday).
- Semantic Memory: dry facts about the world and you (favorite technologies, office address).
- Procedural Memory: instructions and action algorithms (how to properly deploy a release to the server).
4. Production Engineering Scenarios
01. Memory Management in Conversational Agents
Implement a robust mechanism for managing both Short-Term and Long-Term Memory to ensure efficient dialogue flow and context retention.
02. User Profile Updates
Utilize Long-Term Memory to store user preferences and past interactions, allowing the agent to personalize responses and recommendations effectively.
03. Error Logging and Learning
Incorporate Episodic Memory to track past errors and successes, enabling the agent to learn from previous experiences and avoid repeating mistakes.
5. Pitfalls, Common Mistakes & Security
Avoid overloading the context window with excessive historical data, as this can lead to performance degradation and increased costs. Ensure that Long-Term Memory is securely managed to protect sensitive user information. Regularly audit memory storage to prevent outdated or irrelevant data from influencing current interactions.
FAQ: Short-Term and Long-Term Memory of Agents
Related terms
ChatGPT Memory (Storing Facts Between Dialogues)
The ChatGPT Memory feature enables the AI to retain your name, profession, favorite technologies, response formats, and personal details across entirely different chats, enhancing user experience and personalization.
Context Window Size (Current Conversation Memory)
The maximum amount of text (in tokens) that a language model can simultaneously retain in memory during an ongoing conversation. It determines the length of documents that can be loaded at once without loss of content.
Vector Databases (Vector DBs & ANN Search)
Specialized DBMS and extensions (Qdrant, pgvector, Milvus, Chroma, Turso) optimized for storing millions of high-dimensional vectors and ultra-fast Approximate Nearest Neighbors (ANN) search.