The Four Types of AI Agent Memory and How to Engineer Them
A practical guide to the four types of AI agent memory—working, semantic, procedural, and episodic—covering why memory defines an agent's behavioral limits, how to store cross-session memory as a mountable file system, how offline memory consolidation works, and a minimal implementation path for coding agents.
1. Why Memory Separates Chatbots from Agents
A chatbot is essentially a stateless function: text goes in, text comes out, and the context disappears when the session ends. What allows an agent to take on long-running tasks is that it turns a one-off question-and-answer exchange into a continuously evolving execution process—and memory is the foundation that makes this evolution possible.
Put more precisely: memory defines an agent’s behavioral boundaries. An agent without memory starts from zero every time it launches. An agent with memory can turn the last failure, the user’s preferences, and the constraints of a codebase into inputs for its next decision. Memory is therefore not an add-on feature but a first-class citizen of the architecture.
2. A Layered Model of Four Memory Types
Agent memory is commonly divided into four types, each mapping cleanly onto a human memory mechanism:
| Memory type | Human analogy | Typical carrier | Lifecycle |
|---|---|---|---|
| Working memory | Short-term memory | Current context window | Single turn / single session |
| Semantic memory | Factual knowledge | Knowledge base, vector index | Long-term |
| Procedural memory | Learned skills | Tool definitions, workflow templates | Long-term |
| Episodic memory | Personal experience | Past session traces and reflection conclusions | Across sessions |
Working memory answers “what do I know right now.” Its capacity is hard-constrained by the context length and must be sustained through compression and summarization. Semantic memory answers “what are the facts here,” and is usually injected through retrieval augmentation. Procedural memory answers “what steps should I follow,” expressed as tool-calling conventions and task orchestration templates. Episodic memory answers “what have I run into before, and how did I solve it”—it is the only type that lets an agent accumulate experience across sessions.
3. The Real Bottleneck: Distilling Cross-Session Experience and Deciding What to Forget
Episodic memory is the hardest of the four, for two reasons.
The first is what to write. Raw traces are long and noisy, and saving them in full quickly degrades the signal-to-noise ratio of retrieval. Reflection and distillation must come first, compressing a trace into structured entries shaped as situation–action–result–conclusion.
The second is what to delete, which is often underestimated. Humans are good at forgetting; forgetting is itself an efficient reclaiming of cognitive resources. For an agent, forgetting is an engineering capability that must be designed explicitly. Without an eviction mechanism, the memory store grows monotonically and creates three risks: rising retrieval latency, the repeated recall of wrong experience, and sensitive data lingering indefinitely. Practical engineering measures include time-decay weights on entries, ranking by recency of use and hit effectiveness, conflict resolution between contradictory conclusions, and masking or expiry-based cleanup of sensitive fields.
4. Implementation Pattern One: Make Memory a Mountable File System
The most practical form of cross-session memory is not to make the model “remember,” but to externalize memory as a mountable storage layer: the session container mounts the directory at startup, and the model accesses it through ordinary file reads and writes, which naturally yields cross-session capability.
The benefit is a minimal and highly general interface:
/memory-store├── profile/user-preferences.md # User preferences (semantic)├── skills/deploy-checklist.md # Workflow templates (procedural)└── episodes/2026-08-27-auth.md # Past experience (episodic)
On the model side, three actions cover the vast majority of cases: list entries and search by keyword to locate candidates, read an entry in full, and write back a new entry or update an existing one. On the user side, the store can be browsed and inspected with ordinary command-line tools, giving observability that is far better than hiding memory behind a private interface. Three things still need to be added on the engineering side: locking and version numbers for concurrent writes, per-entry permission isolation, and structural validation before writing.
5. Implementation Pattern Two: An Offline Memory Consolidation Process
The second key mechanism is periodic consolidation: the system spawns a separate session that reads recent traces in batches in the background, performs deduplication, categorization, conflict resolution, and summarization, then writes the results back to the memory store. Because this process is itself a session, it is inspectable, replayable, and interruptible—developers can see directly how memory is being rewritten, which matters greatly for debugging and for building trust.
Compared with online retrieval, offline consolidation moves expensive inference off the critical path and keeps the main session low-latency. It also naturally provides a checkpoint for memory governance, where review and masking can be inserted before the write-back.
6. Recommendations for Coding Agents
Not every agent needs all four memory types, but coding tools genuinely need all of them: working memory holds the current code snippet, semantic memory holds codebase facts, procedural memory holds build and test workflows, and episodic memory holds past defects and review comments.
The recommended minimum viable path has three steps. First, implement only the externalized file-based memory store and get cross-session reads and writes working. Second, add a structured entry specification and retrieval ranking. Third, introduce offline consolidation and eviction policies. If the agent runs on a container platform, the memory directory can be placed on persistent storage, with logging and monitoring used to observe hit rates and store growth.
In related practice at Baidu AI Cloud, this kind of capability is typically carried by combinations of general product categories such as container platforms, object storage, and log monitoring, which developers can use to build their own continuously evolving agent memory system.
