Agent Memory Redesign: From a Three-Layer System to Four Layers

    This article explains why agent memory is hard to get right, how a common three-layer design falls short in long-term use, and how a fourth long-term memory layer plus a processing pipeline can turn raw conversations into structured knowledge and reusable skills. It also describes a dual-loop design and practical lessons for keeping memory compact without losing what matters.

    Agent Memory Redesign: From a Three-Layer System to Four Layers

    1. Background: Why Agent Memory Is Hard

    When building an agent system, memory management is easy to underestimate and yet has a large impact on long-term usability. An agent without a sound memory mechanism is essentially a conversation tool with a short memory span: after a session ends, it knows nothing about user preferences, past decisions, or tasks it has already completed. An agent that manages memory poorly falls into the opposite trap, stuffing every conversation record into the context unchanged. Token use then rises sharply, retrieval noise increases, and response quality can actually decline.

    A good memory system has to meet two goals that seem to conflict: remember little (use as little context and storage as possible) and remember well (keep key information accurate and easy to recall). This article shares a real architecture redesign: on top of an agent’s native three-layer memory system, a fourth long-term memory layer is added and connected with core documents and the skill system, forming a dual loop of memory and skills.

    2. Structure and Limits of the Native Three-Layer Memory System

    Common agent memory designs in the industry can usually be reduced to three layers:

    Layer 1: Working memory

    This is the context window of the current session, including the conversation history for the current task and intermediate reasoning results. It is immediate but limited in capacity, and it disappears when the session ends.

    Layer 2: Session / episodic memory

    These are summaries that span turns, usually stored as compressed conversation history, so multi-turn dialogue stays coherent.

    Layer 3: Semantic / knowledge memory

    This is long-term knowledge stored as documents or a knowledge base, typically recalled through vector retrieval (embeddings plus similarity search).

    This three-layer setup is enough for everyday tasks, but long-term use exposes two core problems:

    1. Memory is flat and has no processing pipeline. Raw dialogue is stored directly, without clustering, distillation, or semantic compression, so the system “stores a lot but does not retain what matters.”
    2. Memory and skills are disconnected. The agent accumulates a large amount of execution experience—such as the steps for a class of tasks and the pitfalls it has already hit—but that experience is not turned into reusable skills. The next similar task still starts from scratch.

    3. The Fourth Layer: Long-Term Memory and a Processing Pipeline

    To address those problems, this redesign adds a fourth memory layer and, with an open-source memory management plugin (similar approaches in the industry can be used as references), builds a full pipeline from raw conversation to usable knowledge.

    Under the new architecture, the memory pipeline can be summarized in four steps:

    1. Cluster conversation records → Distill the execution process → Deep understanding (LLM) → Settle into skills

    3.1 Clustering conversation records

    Historical sessions are grouped by topic and task type instead of being stacked linearly. Clustering helps in two ways:

    • Related records on the same topic are stored together, so retrieval can recall by category and noise drops significantly.
    • Later within-cluster summarization becomes easier, and the compression ratio is higher.

    3.2 Distilling the execution process

    While performing a task, an agent produces more than dialogue text. It also generates procedural information such as tool calls, parameter choices, failures, and retries. On their own these look like a running log, but once distilled they become valuable operational experience. This stage focuses on extracting the task goal, the key steps taken, the causes of failure, and how to avoid them.

    3.3 Deep understanding (LLM processing)

    The distilled execution fragments are passed to a large language model for a second pass, which produces structured semantic memory, for example:

    1. {
    2. "topic": "data export task",
    3. "insight": "The user prefers CSV and requires UTF-8 encoding; otherwise Chinese text is garbled",
    4. "evidence_sessions": ["sess_1024", "sess_1180"],
    5. "confidence": 0.92
    6. }

    Structure makes memories checkable, deduplicable, and eligible for retirement by confidence when they go stale.

    3.4 Settling experience into skills

    This is the key step in the pipeline. When similar execution experience reaches a threshold, the system automatically solidifies it into a skill that includes trigger conditions, recommended steps, and caveats. At that point memory is no longer only a passive archive; it becomes an active capability asset.

    4. A Dual Loop of Memory and Skills

    After the redesign, the system forms two loops that drive each other:

    Memory loop (inner loop): conversation → clustering → distillation → semantic memory → retrieval augmentation → better conversation.

    Skill loop (outer loop): execution experience → pattern recognition → skill generation → direct invocation → new experience flowing back in.

    The division of labor is clear:

    • The memory loop is responsible for understanding the user (preferences, background, and historical context).
    • The skill loop is responsible for improving execution (getting work done faster and more accurately).

    This directly meets the goals stated earlier. Because most information is heavily compressed during clustering and distillation, and frequently used experience has already been promoted into skills, the amount of persisted memory stays small—that is “remember little.” Key information has been processed by an LLM and structured, so recall precision is higher—that is “remember well.”

    5. Practical Advice and Pitfalls

    1. Do not skip clustering and summarize directly. Summaries over unordered data lose structural information. Clustering is a prerequisite for compression quality.
    2. Give memory a lifecycle. Decay and retire items based on confidence and access frequency so the long-term store does not become a new dumping ground.
    3. Skill generation needs a human review gate. Automatically solidified skills may include incorrect experience early on. A review mechanism helps prevent errors from being amplified in a loop.
    4. Layered retrieval beats a single retrieval pass. Match skills first (lowest cost, highest precision), then semantic memory, and only then the original session records.

    6. Conclusion

    The direction for agent memory is not to stack storage without limit, but to build a processing pipeline from raw records to structured knowledge to reusable capability. A four-layer architecture combined with a dual-loop design lets the system keep improving itself over long-running use while holding memory cost within an acceptable range. For developers building agent systems, this approach does not depend on any specific tool. The core is pipeline design and layered abstraction, and it is worth trying across different technology stacks.