Agent Memory System Architecture: A Practical Four-Layer Design

    This article explains why AI agents need a dedicated memory system that goes beyond parameter updates, in-context learning, or history compression. It introduces a practical four-layer architecture spanning searchable session logs, memory notes, structured memory representations, and injected context, along with the core principle of layered placement and on-demand retrieval. You will also see how to capture observations during execution, run offline "dreaming" maintenance, and evaluate memory quality while avoiding common pitfalls.

    1. Why Agents Need a Dedicated Memory System

    LLM-powered agents perform well within a single session, but once the session ends, the context window is cleared. Earlier observations, decisions, and results cannot carry over naturally. The industry commonly uses three approaches, none of which is equivalent to “memory”:

    • Parameter updates: Changing the model’s internal weights belongs to training. It is costly and slow, making it unsuitable for task experience that changes at any time.
    • In-context learning: It only takes effect within the current conversation and expires when the window closes.
    • History compression: Older turns are summarized so execution can continue in a new window. This serves “continuity within the same task,” not knowledge accumulation across tasks.

    True agent memory is knowledge that an agent distills from user interactions and completed tasks, saves as files, directories, or other persistable context, and reloads in later sessions. Defining this boundary is the first step in designing a memory system. Otherwise, it is easy to mistake compressed summaries for long-term memory, leaving the knowledge structure increasingly messy.

    2. The Four-Layer Memory Architecture: From Raw Records to Injected Context

    A practical memory system can be abstracted into four layers, from bottom to top:

    1. Searchable session log layer: The bottom layer stores complete raw traces without modification, serving as the source of evidence.
    2. Memory note layer: Observations and conclusions written proactively by the model, organized as entries with source pointers.
    3. Memory representation layer: Structured, wiki-style knowledge aggregated by topic to support cross-document reasoning.
    4. Injected context layer: A small amount of high-value, high-stability information loaded automatically at the start of each new session.

    The key design principle is “layered placement, on-demand retrieval”: stable and important conclusions move up to the injection layer, while detailed material stays in lower layers and is retrieved when needed. This preserves complete, traceable records while avoiding overloading every turn with content that crowds out reasoning space. The four layers do not flow in one direction only; offline consolidation can move, merge, and revise information between layers.

    An illustrative directory structure could be:

    1. /memory
    2. /sessions/2026-11-01-session-03.log # Raw session record, read-only
    3. /notes/user-preferences.md # Memory notes with evidence references
    4. /wiki/architecture-overview.md # Structured memory representation
    5. /context/bootstrap.md # Context injected into every session

    3. Online Phase: Leave Traces While Executing

    Memory writes should happen during the task, not as an afterthought. Three practices help:

    • Flag important events immediately: Tag key observations that affect later decisions, similar to how the human brain marks important experiences more strongly.
    • Write observations directly to disk: Save conclusions to the memory directory instead of leaving them only in the conversation.
    • Keep evidence pointers: Attach a session identifier or document location to each note for later verification and correction.

    Note entries should stay structured, for example:

    1. - claim: The data export task must run in shards
    2. evidence: sessions/2026-11-01-session-03.log#L142
    3. confidence: 0.9
    4. updated_at: 2026-11-01T10:22:00Z

    4. Offline Phase: Dreaming-Style Consolidation

    During idle periods, extra compute can be used for offline consolidation, commonly called “dreaming” maintenance. Its responsibilities include correction, generalization, and structure maintenance:

    • Correction: Verify notes against raw records, flagging or retracting wrong conclusions.
    • Generalization: Merge scattered observations into topic-based knowledge that supports cross-document reasoning.
    • Maintenance: Update the injected context, remove outdated content, and control its size.

    Its costs must be recognized clearly: offline consolidation improves performance but consumes extra compute. Structured representations suit cross-document reasoning but are not necessarily better than direct search for single-document, location-based retrieval. Therefore, whether to enable it and how much to enable should depend on the task type.

    5. Evaluation and Common Pitfalls

    Evaluation should cover multiple task types: long-horizon benchmarks, interactive game-style tasks, large-scale internal document QA, and legal-document retrieval. Three core conclusions stand out:

    • Writing more does not mean better results; memory needs to filter important information.
    • Evidence must be preserved; otherwise, correction and accountability are impossible.
    • Organize memory into searchable structures by task; retrieval efficiency determines the actual value of memory.

    In summary, the competitiveness of an agent memory system lies not in capacity, but in whether the loop of “filter, keep evidence, correct, structure” runs reliably.