Skip to main content

Understanding Agent Memory

Discover why memory is fundamental to agent intelligence and explore the evolution from stateless to stateful AI systems

Introduction

Understanding Agent Memory

Welcome to the world of agent memory systems! In this module, we'll discover why memory is the key difference between simple chatbots and truly intelligent agents.

Let's start with a simple chatbot to see the problem:

A Forgetful Chatbot

typescript

This chatbot has no memory. Every conversation starts fresh:

The Forgetting Problem

typescript

The Issue: The chatbot forgot Alice's name immediately after she introduced herself.

🔍

Richmond's Key Insight

"If AI or AGI is meant to mimic human intelligence, and what determines intelligence in humans is their ability to recall—it's their memory—then it's a no-brainer that we need memory within the agents we're building." - Richmond Alake, MongoDB

Richmond Alake outlined the evolution we've seen:

2022: Simple Chatbots

  • No memory between conversations
  • Basic Q&A functionality
  • Limited context understanding

2023: RAG Systems

  • Static knowledge bases
  • Better domain-specific answers
  • Still no conversational memory

2024: Tool-Using Agents

  • Function calling capabilities
  • Can take actions
  • But still stateless between sessions

Now: Memory-Enabled Agents

  • Remember conversations
  • Learn user preferences
  • Build relationships over time

According to Richmond, an AI agent is:

"A computational entity with awareness of its environment through perception, cognitive abilities through an LLM, and can take action through tool use. But the most important bit is there is some form of memory—short-term or long-term."

Let's build this step by step.

Basic Memory Storage

typescript

Step 2: Add Memory Retrieval

Retrieving Memories

typescript

Step 3: Create a Memory-Enabled Agent

Now let's build an agent that can remember:

Memory-Enabled Chatbot

typescript

Helper function to extract names:

Name Extraction Helper

typescript

Step 4: Test the Memory-Enabled Agent

Testing Memory

typescript

Let's compare the two approaches:

Without Memory:

  • Every interaction starts from scratch
  • No personalization possible
  • Cannot build relationships
  • Limited context understanding

With Memory:

  • Conversations have continuity
  • Personalized responses
  • Relationship building over time
  • Rich context from history

Memory Transforms AI

Memory is what transforms a simple chatbot into an intelligent agent that can be "believable, capable, and reliable"—Richmond's three key goals for agent systems.

In the next module, we'll explore different types of memory that agents need:

  • Conversational Memory: What was said in past conversations
  • Entity Memory: Information about people, places, and things
  • Persona Memory: The agent's personality and behavior patterns
  • Toolbox Memory: Which tools to use in different situations

Richmond emphasized the connection to human intelligence:

graph TB
    subgraph "Human Brain"
        A[Short-term Memory] --> B[Working Memory]
        C[Long-term Memory] --> D[Semantic Knowledge]
        E[Episodic Memory] --> F[Personal Experiences]
        G[Procedural Memory] --> H[Skills & Routines]
    end
    
    subgraph "Agent Memory"
        I[Conversation Buffer] --> J[Active Context]
        K[Knowledge Base] --> L[Facts & Concepts]
        M[Episode Store] --> N[Past Interactions]
        O[Skill Registry] --> P[Tools & Actions]
    end
    
    A -.-> I
    C -.-> K
    E -.-> M
    G -.-> O

Just as humans have specialized memory systems, our agents need different types of memory for different purposes.

1. What is the main problem with stateless AI chatbots?

  • A)They are too slow to respond
  • B)They forget everything between conversations
  • C)They consume too much memory
  • D)They can't access the internet
Show Answer

Correct Answer: B

Stateless chatbots have no memory between conversations, so they can't build relationships or provide personalized experiences.

2. According to Richmond Alake, what makes an entity an AI agent?

  • A)Just having an LLM and tools
  • B)Being connected to the internet
  • C)Having perception, cognition, action capability, AND memory
  • D)Being able to write code
Show Answer

Correct Answer: C

Richmond defined agents as having environment awareness (perception), cognitive abilities (LLM), action capability (tools), AND some form of memory.

3. Why did Richmond say memory is essential for AGI?

  • A)Memory makes agents faster
  • B)Human intelligence is fundamentally tied to memory and recall ability
  • C)Memory reduces computational costs
  • D)Memory makes agents more secure
Show Answer

Correct Answer: B

Richmond argued that since human intelligence is determined by the ability to recall (memory), AI systems aiming to mimic human intelligence must have memory.

Try enhancing our simple memory agent:

  1. Add Preference Memory: Let users tell the agent they prefer bullet points or paragraphs
  2. Add Mood Tracking: Remember if the user seems happy, frustrated, etc.
  3. Add Topic Interest: Track what topics the user asks about most

Hint for Preference Memory

typescript

In this module, we learned:

  1. The Problem: Stateless AI can't build relationships or learn from interactions
  2. The Solution: Memory enables agents to be believable, capable, and reliable
  3. The Evolution: From simple chatbots to memory-enabled agents
  4. The Implementation: Basic memory storage and retrieval in under 30 lines
  5. The Connection: Agent memory mirrors human memory systems

In the next module, we'll explore the different types of memory agents need, starting with simple implementations of each type. We'll see how Richmond's team at MongoDB models these memories as flexible documents that can adapt to any structure.

💡

Remember This

Memory isn't just about storage—it's about organizing information so the right memories surface at the right time. That's what we'll build in the coming modules.