# How AI Agent Memory Works: MemGPT & Memory Types | Stanford CS329Z Lecture 7 with Michael Ryan

## Executive summary

This lecture provides a deep dive into agent memory architectures, explaining why memory is crucial for long-running, multi-session AI agents. It details four types of memory (Working, Episodic, Semantic, Procedural) and explores advanced architectural patterns like MemGPT and Agent Workflow Memory. The discussion covers various storage mechanisms—including file systems, vector databases, and knowledge graphs—and concludes with benchmarks and open challenges related to memory management, privacy, and over-personalization.

## Key takeaways

- Four Core Memory Types: Agents utilize four distinct memory types: Working Memory (the current context window), Episodic Memory (raw logs/trajectories of past actions), Semantic Memory (general facts and user preferences), and Procedural Memory (skills/rules on how to complete tasks).
- MemGPT Architecture: The MemGPT architecture allows the LLM to manage its own memory using tools, implementing a tiered system: a FIFO queue for conversation history, a Recall Storage (for exact string lookups), and an Archival Storage (a vector database for long-term facts).
- Procedural Memory via Skill Files: Procedural memory is best implemented by storing skills (e.g., brand guidelines, complex procedures) in structured files (like `skill.md`) and loading them into the context window, allowing the agent to execute defined actions.
- Memory Arena Benchmarking: The Memory Arena benchmark evaluates memory agents on solving realistic, diverse problems (e.g., group travel planning) by requiring the agent to continuously update its memory and adapt its actions over long trajectories.

## Technical details

- Memory Types Distinction: Working memory is functionally equivalent to the context window. Semantic memory stores general facts (e.g., Wikipedia data, user preferences). Episodic memory stores raw logs of past interactions or trajectories. Procedural memory stores actionable knowledge or skills (e.g., 'how to craft an iron pickaxe').
- Knowledge Graph Utilization: Knowledge graphs (e.g., Zep) are highly effective for storing semantic memory by extracting entities and relationships from conversations. Querying involves traversing these relationships (Graph RAG), which is useful for offloading complex lookup intelligence from the LLM.
- Memory Management Tools: Advanced agents can use tools to manage memory, allowing them to write and read from external stores. This process is critical for maintaining state across sessions and preventing context window overflow.
- Memory Maintenance (Sleep Time Compute): This technique involves the agent performing offline reasoning over stored memories (e.g., semantic facts) during periods of inactivity to consolidate and rewrite the information into a more useful, condensed format for future retrieval.

## Practical implications

- For build engineers designing agent systems, implementing a robust memory layer is critical for achieving statefulness and long-term coherence.
- The choice of memory backend (file system, vector DB, or knowledge graph) should be dictated by the required lookup speed and the nature of the data (e.g., KGs for relationships, Vector DBs for semantic similarity).
- Implementing memory management tools (like those in MemGPT) allows the agent to autonomously decide what information is important enough to persist, mitigating context window limitations.
- When designing for dynamic environments, memory maintenance strategies (like 'Sleep Time Compute') must be incorporated to prevent stored knowledge from becoming outdated.

## Topics

Agentic AI, Memory Architectures, Natural Language Processing, Knowledge Graphs, State Management, Stanford CS329Z: Engineering AI Agents, Voyager, MemGPT, Memory Arena

Source: https://www.youtube.com/watch?v=qh5tP6PBZ6U
