Lesson 4

Agent Memory

Short-term, Long-term, RAG

The Problem: Every time you start a new chat, AI forgets everything. It doesn't remember your preferences, past conversations, or important context. It's like talking to someone with amnesia every single time.

The Solution: Give AI a Notebook

Agent memory is like giving an assistant a notebook where they write down important things. Next time you talk, they can check their notes. Short-term memory lives inside the context window, while long-term memory is often stored in a vector database and retrieved on demand using RAG.

Think of it like a personal assistant with a notebook:

  • 1. Short-term memory: "You mentioned 3 items earlier in this conversation"
  • 2. Long-term memory: "Last month you said you prefer morning meetings"
  • 3. Episodic memory: "Remember when we worked on Project X together?"
  • 4. Semantic memory: "Your company uses React and TypeScript"

Types of Agent Memory

  • Conversation buffer: Keep the whole chat history (simple but limited)
  • Summary memory: Compress old conversations into summaries
  • Vector store: Search through past conversations by meaning
  • Entity memory: Track facts about specific people, projects, etc.

Fun Fact: Human memory isn't perfect either! We summarize, forget details, and sometimes misremember. AI memory systems often mimic these patterns — keeping what's important and compressing the rest. The goal isn't perfect recall, it's useful recall.

Try It Yourself!

Explore the interactive demo below to see how different memory types work. Watch how the agent retrieves and uses stored information to maintain context across conversations.

Try it yourself

Interactive demo of this technique

Technique Comparison
Demo Mode
Pre-recorded responses
TaskBeginnerAnalysis

Answer a question about a previous conversation: "What budget did I mention earlier?"

Without technique
Without technique
Prompt
User asks: "What budget did I mention earlier?" Context of previous messages is not available.
Response

Unfortunately, I don't have information about your previous messages. Could you clarify which budget you mean?

Tokens:35/32
Time:380ms
Quality:
With Agent Memory
With technique
Prompt
Agent with memory. Available: - short_term_memory: last 5 messages - long_term_memory: key facts from all conversations From long_term_memory: { "budget": "$50,000", "project": "website redesign", "date_mentioned": "2 days ago" } User: "What budget did I mention earlier?"
Response

Yes, I remember! Two days ago, while discussing the website redesign project, you mentioned a budget of $50,000. Would you like to discuss allocating this budget or update the amount?

🧠Query requires information from past conversations
👁️Accessing long_term_memory: budget fact found
👁️Context restored: $50K budget, redesign project, 2 days ago
Response includes context and offers conversation continuation
Tokens:95/52
Time:820ms
Quality:
Why this works

An agent with memory persists key facts across sessions. Without memory an LLM cannot reference previous conversations — every request starts from scratch.

1 / 2

Lesson Quiz

1 of 3

1.What is the primary difference between short-term and long-term memory in LLM agents?

Practice Challenges

Create a free account to solve challenges

3 AI-verified challenges for this lesson

Related lessons:ReactArchitectures

This lesson is part of a structured LLM course.

My Learning Path