Why AI Agents Need a Memory Layer: Completing the Three-Layer Architecture

    This article explains why the common "thin framework, thick skills" design for AI agents needs a third layer: memory. It covers the limits of deterministic skill execution, a skeleton-muscle-nervous-system analogy for the three-layer architecture, a layered memory design with lifecycle management and interfaces, what experiences are worth writing, retrieval and fusion, evaluation and observability, and common anti-patterns. Readers will learn how a memory layer turns repeated execution into accumulated experience while keeping skills deterministic and testable.

    1. Introduction: The Achievements and the Ceiling of Determinism

    In agent engineering, “thin framework, thick skills” has become a widely discussed design principle. The core idea is to consolidate generic logic—scheduling, permissions, context management—into a lightweight runtime framework, and to capture business capabilities as reusable, testable skill modules. A common industry statement puts it this way: every skill you write is a permanent upgrade to the system. It does not degrade, and it does not forget.

    This statement points to the biggest advantage of engineered agents: determinism. The same input passing through the same skill should produce a stable output. Skills do not drift as the number of runs increases, and they do not lose critical steps as the context changes. Reliability, auditability, and regression testing are all built on this determinism.

    But determinism is also a ceiling. A system that never forgets is not the same as a system that learns. Human memory forgets, and forgetting is not a defect but a filtering mechanism: it distills frequent, critical information into intuition and craft, while letting occasional, low-value information fade. Skills do not forget, but they also do not distill. Each invocation is an independent execution, and no new tendency grows out of past tasks. As a result, when the number of skills grows from ten to one hundred, the system simply has one hundred isolated capabilities rather than the crystallization of one hundred experiences.

    This is the key missing piece in the common two-layer architecture: memory.

    2. Rethinking “Thin Framework, Thick Skills”

    2.1 The Responsibility Boundary of a Thin Framework

    A lightweight runtime framework should handle only work that is unrelated to the business but required on every run: task orchestration, tool invocation, permissions and sandboxing, context assembly, and logging and tracing. Its value lies in stability and replaceability. It should not carry concrete business judgment, or it will quickly swell into a hard-to-maintain “fat framework.”

    2.2 How Thick Skills Are Organized

    A skill encapsulates a class of tasks and typically includes trigger conditions, input/output contracts, execution steps, and validation rules. Skills should be small and clear, composable, and testable. A growing number of skills brings coverage, but it does not automatically bring quality, because there is no experience channel between skills.

    2.3 The Limits of Quantity-Based “Thickness”

    One hundred skills mean one hundred capabilities, but without a shared experience layer, every skill starts from zero. Information such as user preferences, scenario-specific pitfalls, and path costs is scattered across individual sessions and cannot settle into priors for the next execution. The system looks highly capable, yet it is still “repeating” rather than “accumulating.”

    3. Skeleton, Muscles, and Nerves: The Division of Labor in a Three-Layer Architecture

    The human body offers a useful analogy: the runtime framework is the skeleton, which determines structure and direction; skills are the muscles, which determine strength and movement; memory is the nervous system, which connects the two and makes movements more precise through repetition.

    • Skeleton (runtime framework): stable, lightweight, and replaceable; responsible for scheduling and constraints.
    • Muscles (skills): clear, testable, and composable; responsible for completing concrete actions.
    • Nerves (memory): connection and feedback; responsible for turning historical experience into priors for the current execution.

    Muscles undergo structural changes under repeated stimulation, which is why one hundred squats make you stronger. A skill executed one hundred times does not change itself. The memory layer performs exactly this kind of “structural change”: it extracts tendencies from task traces, such as a certain class of users preferring short conclusions, a certain workflow being most error-prone at step three, or a certain tool path having a lower average latency. These tendencies are not new skills; they are experiential corrections that grow on top of existing skills.

    4. The Opposite of “Never Forgetting” Is Not “Always Forgetting”

    Skills pursue the same output for the same input, which is the foundation of engineering reliability. What an agent truly needs is to do better on the same scenario than it did last time. The difference between the two can be expressed as:

    1. Skill execution: output = skill(input)
    2. Memory-enhanced: output = skill(input, recall(experience(input, context)))

    recall does not change the semantics of the skill. It injects filtered experiential context before the call and writes the new trace back to the candidate experience store after the call. Determinism is guaranteed by skills, while progressive improvement is provided by memory. The two are decoupled in separate layers and do not pollute each other.

    5. Memory Layer Design: Tiers, Lifecycle, and Interfaces

    5.1 Layered Memory

    • Working memory: the context and intermediate results of the current task; the shortest lifecycle.
    • Episodic memory: task traces, tool invocation sequences, and failure and repair processes.
    • Semantic memory: rules, preferences, and scenario knowledge distilled from multiple traces.
    • Procedural memory: skill invocation strategies and parameter selection tendencies, expressed as “how to do it more reliably.”

    5.2 Lifecycle Management

    Memory must have mechanisms for writing, updating, decay, and deletion. Low-value, one-off, and privacy-related information should not be retained for long. Confidence, hit count, last-used time, and conflict resolution strategies can be introduced to prevent incorrect experiences from being repeatedly amplified.

    5.3 Illustrative Interface

    1. class MemoryLayer:
    2. def before_run(self, task, context) -> list[Hint]:
    3. """Retrieve and inject experiential hints, ranked by confidence and relevance."""
    4. def after_run(self, task, trace, outcome) -> None:
    5. """Filter the trace and write candidate experience or update existing experience."""
    6. def consolidate(self) -> None:
    7. """Periodically distill multiple episodic memories into semantic rules and resolve conflicts."""

    The interface stays generic and is not bound to a specific storage or retrieval implementation, making it easy to deploy on common infrastructure such as container platforms, logging services, and object storage.

    6. Writing Experience: What Is Worth Remembering

    Not every trace should be stored. A useful filter is “reusability × confidence × cost-benefit”: do not write one-off incidents; prioritize writing paths that failed and were fixed; prioritize writing paths that are significantly more time- and compute-efficient; prioritize writing preferences the user has explicitly corrected. When writing, record scenario tags, preconditions, and the applicable scope so that experience is not misapplied to mismatched tasks.

    7. Experience Retrieval and Fusion

    Retrieval needs to consider semantic relevance, scenario match, and time decay at the same time. During fusion, treat experience as “hints and constraints” rather than hard-coded rules. When experience conflicts with current facts, the current input and validation results take precedence. Keeping a small number of diverse candidates can prevent the system from converging prematurely onto a single path.

    8. Evaluation and Observability

    The memory layer must be measurable; otherwise it degrades into an opaque implicit state. Recommended metrics include: experience hit rate, change in success rate attributable to experience, change in average steps and latency, number of conflicts and rollbacks, and the proportion of expired experience. Monitoring alerts and tracing logs help locate the source of “bad experience,” and support for a one-click fallback to a memory-free baseline enables controlled comparison.

    9. Common Anti-Patterns

    • Stuffing all historical conversations into the context verbatim, causing noise and cost to balloon.
    • Letting memory directly rewrite skill logic, breaking determinism and testability.
    • Lacking decay and deletion, so incorrect experience persists for a long time.
    • Recording only successes and not failures and repairs, losing the most valuable negative samples.
    • Evaluating only the final answer, without looking at step cost and stability.

    10. Conclusion

    “Thin framework, thick skills” solves the problem of capability supply and engineering determinism, while the memory layer solves the problem of compounding experience. Treat skills as functions that never forget, and memory as a nervous system that filters. Only then is the three-layer architecture complete: the framework schedules stably, skills execute reliably, and memory makes the same scenario better each time. If teams use general-purpose capabilities such as containers, logging, and monitoring from Baidu AI Cloud to carry memory lifecycle management, they can focus more on the experience filtering and evaluation mechanisms themselves, and build agent systems that genuinely mature with use.