Skip to main content

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:

  1. Short-Term Memory: RAM. This is the conversation you are currently exchanging in the open tab. When you close the chat, it clears.
  2. 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.

/ Frequently Asked QuestionsSchema.org FAQPage

FAQ: Short-Term and Long-Term Memory of Agents

Firstly, it's too costly: sending 100,000 words of past conversations with each new 'Hello' will burn through your API balance in a day. Secondly, it slows down the response. Thirdly, the model suffers from attention dilution and starts to confuse outdated facts.
/ Internal links
All terms