The Four Types of Agent Memory and How to Implement Them

    Agent memory is what separates a chatbot from an AI agent. This article breaks down the four types of agent memory—working, semantic, procedural, and episodic—explains why cross-session episodic memory and forgetting decisions are the real engineering bottleneck, and walks through a proven implementation pattern: memory as a mountable file system, plus an observable consolidation step. You will also find a practical design checklist for taking agent memory from demo to production.

    1. Why Memory Is the Dividing Line Between Chatbots and Agents

    As the industry discusses agent architecture, a consensus is emerging: what truly separates a chatbot from an agent is not model size, nor the number of tool calls, but memory. A chatbot is stateless—each session is an isolated mapping where input goes in, output comes out, and the information evaporates when the session ends. An agent, by contrast, must maintain an internal state that evolves continuously across turns and across sessions. It needs to remember a constraint the user set three months ago, a failed attempt from last week, and the name of a function it once wrote.

    Humans are actually very good at forgetting. Although forgetting is often frustrating, from a cognitive-efficiency standpoint it is extremely useful: it keeps the brain holding only information relevant to the current goal and prevents it from being drowned in noise. For an agent, however, forgetting is a purely engineering problem—because the default behavior of engineering systems is “append-only.” Logs grow without bound, vector stores keep expanding, yet the context window is always finite. Designing a mechanism where “what should be remembered is retained, and what should be forgotten is dropped” is the core challenge of an agent memory system.

    2. The Four Types of Agent Memory

    Agent memory is commonly divided into four types, each with a clear correspondence to human memory structures.

    1. Working Memory
    This corresponds to human short-term memory. It is a temporary buffer in the current task context that holds intermediate results being processed, tool return values, and hypotheses awaiting verification. Its capacity is bounded by the context window, and its lifecycle is extremely short—it should be released once the task ends. In engineering terms, it usually appears as the sequence of messages within a session plus a task-state summary that can be rewritten at any time.

    2. Semantic Memory
    This corresponds to factual knowledge. It stores stable facts about the user, project, and environment: tech-stack preferences, coding conventions, deployment environments, and domain glossaries. Semantic memory is characterized by low update frequency and high reuse frequency. It is well suited to being persisted as structured documents or key-value entries and injected on demand at the start of a session.

    3. Procedural Memory
    This corresponds to acquired skills. It is not “knowing what” but “knowing how”: the execution steps for a class of tasks, the correct call order for a given tool, and the fix patterns for a class of errors. Procedural memory typically exists as reusable process descriptions, checklists, or script snippets. It is the key that takes an agent from “being able to converse” to “being able to do work.”

    4. Episodic Memory
    This corresponds to personal experience. It records “did a certain thing at a certain time and place, and here is how it turned out,” including both successful paths and lessons from failures. Episodic memory is the hardest of the four and is the part that lets an agent distill experience across sessions. It is inherently time-series, context-laden, and the largest in volume, which makes it the hardest to retrieve, the hardest to compress, and the hardest to judge for retention value.

    One important engineering conclusion: not every agent needs all four types of memory at once. An agent that only performs single-turn text summarization needs just working memory plus a little semantic memory. A task-oriented agent like an AI coding tool—one that requires long cycles, multiple rounds of iteration, and continuity across sessions—genuinely needs all four layers in place.

    3. The Real Bottleneck: Cross-Session Episodic Memory and Forgetting Decisions

    Episodic memory has become the current engineering bottleneck for three reasons.

    First, writing is easy; distilling is hard. Storing the complete trace of a session verbatim has almost no technical barrier, but a raw trace has a very low signal-to-noise ratio. What is truly valuable is the conclusion distilled from it: “the test command in this repository requires starting the local dependency service first.” Distillation requires extra inference overhead, and a wrong distillation will contaminate all subsequent decisions.

    Second, retrieval precision is insufficient. Pure vector-similarity retrieval is good at finding “semantically similar” content but struggles with queries that are “time-related,” “causal,” or “version-related.” When a user asks “why did we abandon that approach last time,” what is needed is a timeline and a decision chain, not a pile of semantically similar fragments.

    Third, forgetting lacks criteria. There is currently no universal standard for what to delete, what to downgrade, and what to merge. Viable directions include: hot/cold tiering based on access frequency and last-access time; conflict detection that lets new facts override old ones; and confidence decay that automatically invalidates unverified speculation.

    4. A General Implementation Pattern: Memory as a Mountable File System

    The engineering pattern proven effective today is to implement “memory storage” as a file system that can be mounted into the session runtime environment. Compared with stuffing memory into an interface that can only be read or written as a whole, a file system brings three decisive advantages.

    First, a universal interface. Models naturally understand concepts like directories, files, and append writes, with no need to learn a proprietary call protocol. Second, tool reuse. On the user side, the directory structure can be browsed with ordinary command-line tools; on the model side, keyword search can locate relevant fragments, which are then read precisely from a specific file. This forms a two-stage “search first, then read closely” access pattern that significantly reduces context consumption. Third, governability. Files naturally carry metadata such as path, size, and timestamp, making tiering, archiving, quotas, and auditing straightforward.

    A sample directory organization could look like this:

    1. /memory
    2. /semantic # stable facts: environment, conventions, glossary
    3. project.md
    4. conventions.md
    5. /procedural # reusable processes and checklists
    6. build-and-test.md
    7. rollback.md
    8. /episodic # experiences archived by time
    9. 2026-08-01-auth-refactor.md
    10. 2026-08-19-cache-incident.md
    11. /working # current task state, rewritable at any time
    12. task-state.json
    13. /index.md # memory index for quick lookup

    The corresponding read/write logic can be abstracted as:

    1. def recall(query: str, top_k: int = 3) -> str:
    2. # Stage 1: low-cost retrieval that returns only paths and summaries
    3. hits = search_index(query, limit=top_k)
    4. # Stage 2: read closely on demand to avoid flooding the context at once
    5. return "\n".join(read_file(h.path) for h in hits)
    6. def remember(path: str, content: str) -> None:
    7. # Run conflict detection and deduplication before writing to avoid unbounded growth
    8. merged = merge_or_replace(path, content)
    9. append_file(path, merged)
    10. update_index(path)

    5. “Dreaming”: Making Memory Consolidation Observable

    Memory storage alone is not enough; memory keeps piling up and gradually distorts, so a periodic consolidation step is needed—something the industry vividly calls “dreaming.” The key design here is not the consolidation algorithm itself but observability: the consolidation process creates its own independent session, and you can open that session to see exactly which memories it read, what it merged, what it discarded, and why it discarded them.

    This design turns the memory system from a black box into a white box and directly addresses three long-standing pain points: memory contamination becomes traceable, consolidation strategies become evaluable, and forgetting decisions become auditable. In engineering terms, the consolidation task usually runs asynchronously during off-peak hours, outputs a change list, and keeps version snapshots of the original files for rollback.

    At the implementation level, this kind of capability is typically carried by general cloud services: object storage holds memory files and snapshots, a container platform hosts the session runtime environment and mounts the storage volumes, a message queue triggers asynchronous consolidation tasks, and logging and monitoring/alerting services track consolidation results and anomalies. Baidu AI Cloud offers corresponding capabilities across these general categories and can serve as the foundation for building a memory system.

    6. Design Checklist

    • Tier first, then choose: determine which task category the agent belongs to and bring in the four memory layers as needed, avoiding over-engineering.
    • Memory is the interface: prefer a file-system-style universal interface that separates search from close reading.
    • Govern every write: route every write through deduplication, conflict detection, and confidence labeling.
    • Make forgetting explicit: define hot/cold tiering and expiration policies for memory, and design forgetting as a first-class citizen.
    • Make consolidation visible: make the memory consolidation process itself replayable, auditable, and rollback-capable.

    The difficulty of memory has never been “storing it,” but “retrieving the right one at the right moment and forgetting the rest.” Making memory a system that is mountable, searchable, consolidatable, and observable is the dividing line that takes an agent from demo to production.