lolspider / notes
Clipping · 5 分钟

AI Agent Memory Types Explained

x.com Unknown

How AI Agents Remember? Why AI Agents Forget?

A raw language model processes each request in complete isolation. The moment a response is generated, everything is wiped. For a simple chatbot, that’s fine. For an autonomous agent that needs to complete tasks across hours or days it’s a fatal flaw. Memory architecture is what bridges the gap between a stateless model and a thinking, adaptive agent.

There are four distinct memory systems, each serving a different cognitive purpose

1. Short-term memory — the agent’s working desk

Think of short-term memory as the surface of a developer’s desk right now. Every document, sticky note, and open browser tab visible at this moment. It’s immediately accessible, but the desk has a finite surface area. If you pile too much on, things start falling off the edge.

In technical terms, short-term memory is the context window itself a sequential list of messages, tool outputs, and in-progress reasoning that gets bundled into every inference call. The agent can see everything on that list simultaneously. The problem is this list grows with every exchange, and every LLM has a maximum token limit. When you approach that limit, the model begins to suffer what’s called the “lost in the middle” phenomenon: it fixates on the beginning and end of the prompt, effectively going blind to everything buried in the middle.

There are three strategies to manage this, each with clear tradeoffs:The most sophisticated approach is MemGPT, which applies the operating system metaphor directly: the context window is treated as physical RAM, and external databases are the hard drive. When the “RAM” fills up, the agent itself calls internal tools to evict stale data to disk and page in what’s relevant. The key insight is that the LLM actively manages this it’s not an external script doing the cleanup.

2. Episodic memory — the agent’s diary

Where short-term memory is volatile and session-bound, episodic memory is durable and timestamped. It’s the agent’s autobiographical record: what it did, what happened as a result, and when. Unlike semantic memory (covered next), episodic memory keeps the temporal context attached it cares not just what is true, but what happened and when.

The most valuable episodes to store are failures. An agent that remembers “the last time I ran this migration without taking a backup, there was data loss” is dramatically more reliable than one that has to rediscover this lesson every time.The Stanford Generative Agents research introduced a powerful idea on top of this: a background “Reflection” process. Periodically, the agent queries its own episodic log, clusters related events, and asks the LLM to synthesize them into a higher-level insight. Three separate observations of “Alice was studying” become one lasting semantic belief: “Alice is academically motivated.” This is how episodic memory feeds into and enriches semantic memory over time.

3. Semantic memory — the agent’s knowledge base

Semantic memory holds generalised, atemporal facts. It doesn’t matter when the knowledge was acquired — only that it’s true and retrievable. This is where user preferences live, where domain expertise is stored, and where the agent accumulates a persistent model of the world it operates in.

The critical storage choice for semantic memory is one of the most important architectural decisions in agentic systems: vector database versus knowledge graph. Each is the right tool for a fundamentally different type of question.The production solution that reconciles both is GraphRAG a hybrid pipeline that uses vector search to find the right entry points into a knowledge graph, then switches to deterministic graph traversal to extract exact relational context. The vector DB handles the “find something in the neighborhood of this concept” problem. The graph handles the “now give me the precise facts connected to it” problem.

4. Procedural memory — the agent’s muscle memory

Procedural memory encodes the “how” multi-step workflows, tool orchestration sequences, and learned behavioral routines. Knowing what a database migration is (semantic) is entirely different from knowing the precise sequence of steps to execute one safely (procedural).

In most current agents, procedural memory is hardcoded: the developer writes the tools, defines the tool-calling logic, and embeds behavioral rules in the system prompt. But advanced architectures are moving toward adaptive procedural memory, where agents learn and refine their own procedures through experience.The critical danger here is catastrophic drift. When an agent evaluates its own outputs and updates its own procedures autonomously (known as RLAIF Reinforcement Learning from AI Feedback), a single incorrect self-assessment can propagate. The agent judges a bad action as good, encodes it as a preferred procedure, and now repeats the mistake with increasing confidence across hundreds of future tasks. Production systems guard against this with a human-in-the-loop QA gate: self-reflection generates candidate procedure updates, but a human engineer reviews and approves them before they’re written to permanent storage.

How all four memory layers work together

The real power emerges when all four memory types operate in concert. Here’s how they interplay during a single agent task:When a new task arrives, the agent doesn’t start from scratch. It simultaneously pulls from its live conversational context (short-term), queries its diary for relevant past experiences (episodic), fetches facts and user preferences from its knowledge base (semantic), and is guided by its trained instincts for how to approach the task (procedural). All four streams converge into a single assembled prompt, which the LLM then reasons over. After execution, the outcome is written back as a new episode feeding the cycle for next time.

The progression from a stateless LLM to a truly capable agent is essentially the story of building out these four layers, one by one, until the agent has the same cognitive infrastructure a skilled human professional relies on every day.

If you like this article, forward it, share it with others and follow me for more!