AI Agent Architecture: Adding the Missing Memory Layer

    A practical look at why deterministic capability modules alone cannot improve across sessions, and how a memory layer turns repeated task execution into accumulated expertise. The article covers the three-layer division of labor across orchestration framework, capability modules, and memory, formalizes stateless versus memory-dependent call semantics, defines four memory types with lifecycle metadata, and explains write and recall gating, eventual consistency, evaluation metrics, common anti-patterns, and a staged rollout path.

    AI Agent Architecture: Adding the Missing Memory Layer

    1. A Widely Misread Design Principle

    A common claim in the industry is that capability modules should be “unable to forget.” In an engineering context, this points to determinism: the same input produces the same output, so behavior is testable, rollback-able, and reproducible. But treating that as the entire goal of agent design walks into a subtle trap. Determinism solves “get it right every time,” while the capability that is genuinely scarce in an agent is “get better at the same scenario than last time.”

    These are different categories in engineering. The first is a pure function property; the second is stateful iterative optimization. Conflating them produces a typical symptom: the capability library keeps growing, entry counts swell from a dozen to over a hundred, yet the task success rate curve rises early and then flattens quickly. The reason is not mysterious. Growth in count buys coverage, not proficiency.

    2. Forgetting Is Not a Defect but a Distillation Mechanism

    Human memory decays, but the decay itself performs a filtering function: high-frequency, high-value, repeatedly validated information is retained and consolidated into dispositions, intuitions, and craft; low-frequency, noisy, one-off details fade. You do not need to remember the angle of every body tilt when you first learned to ride a bike. You only need to “know how to ride.” That “knowing how” is exactly the compression and abstraction that forgetting completes for you.

    By contrast, every invocation of a capability module is a clean execution with no state passed from the previous invocation. It does not deposit dispositions from use; it only repeats. So a “thick” capability set is thick in entry count only: one hundred modules equal one hundred capabilities, but there is no linkage between them, no accumulation, and no preferences or shortcuts grown out of real usage.

    This is precisely the layer missing from the common three-layer breakdown: memory.

    3. Skeleton, Muscle, and Nerves: Redrawing Layer Responsibilities

    A single metaphor can clarify the boundaries:

    • The orchestration framework is the skeleton: it determines structure, posture, and direction of movement, and handles session orchestration, task decomposition, tool selection, and failure fallback.
    • Capability modules are the muscle: they determine strength, speed, and concrete movement, and handle the conversion from one clear input to one clear output.
    • Memory is the nervous system: it connects skeleton and muscle, converting past stimuli into fine-tuning signals for the next action.

    Muscle without nerves contracts in isolation every time. Doing one hundred squats in a gym grows muscle because the tissue undergoes structural change under repeated stimulus; a capability module executing one hundred similar tasks undergoes no structural change of its own. The memory layer takes on exactly this “structural change” work: extracting dispositions from each task, for example that a certain class of users prefers minimal replies, that errors in a certain scenario cluster at step three, or that one execution path has historically been about thirty percent faster than another. These dispositions are not new capabilities; they are experiential fine-tuning grown on top of existing capabilities.

    4. A Formal Comparison of Two Invocation Semantics

    The difference can be written as clear semantics:

    1. Capability module: out = f(input) # stateless, constant result
    2. Memory-aware call: out = g(input, M_t) # depends on current memory snapshot
    3. Memory update: M_{t+1} = Update(M_t, input, out, feedback)

    Here M_t is the memory snapshot at the t-th invocation, and feedback can be any observable signal such as an explicit rating, whether a human adopted the result, execution latency, or retry count. Two points matter. First, g remains deterministic given M_t, so testability is not sacrificed. Second, randomness is confined to Update alone, which makes auditing and rollback straightforward.

    This yields a practical engineering principle: keep uncertainty inside memory updates rather than scattering it across the execution path.

    5. Four Types of Memory Content and Their Lifecycles

    In practice, split memory into four types, each with its own lifecycle and confidence:

    1. Factual memory: environment topology, directory conventions, dependency versions, interface contracts. Changes slowly, can be retained long term, but needs version markers.
    2. Preference memory: reply length, code style, glossary, output format. Medium cycle, requires conflict resolution.
    3. Procedural memory: effective step sequences for a class of tasks, common pitfalls, verification checklists. This is the part closest to “craft.”
    4. Episodic memory: the trace and result of one specific task, used for retrospection and as material for retraining, usually with a shorter retention period.

    Each memory entry should carry metadata so it does not degrade into unstructured piles of text:

    1. {
    2. "type": "procedural",
    3. "scope": "task:release-checklist",
    4. "content": "Step three must validate configuration before running the migration",
    5. "confidence": 0.82,
    6. "support": 17,
    7. "created_at": "2026-05-01",
    8. "last_used_at": "2026-08-20",
    9. "ttl_days": 180
    10. }

    support records how many times the entry has been validated, confidence is determined jointly by success rate and human adoption rate, and ttl_days provides an automatic forgetting channel. Forgetting here is not loss; it moves low-support entries out of the recall set and, when necessary, archives them to cold storage.

    6. Write and Recall: Two Key Decisions in the Memory Layer

    The write decision answers “is this experience worth recording.” Three gates can filter it: is it reusable (still valuable across sessions), is it verifiable (backed by objective signals), and is it non-redundant (sufficient semantic distance from existing entries). If any one is missing, the item stays only in short-term episodic memory and does not rise to a long-term disposition.

    The recall decision answers “what should be remembered this time.” A hybrid of three retrieval paths is recommended: semantic similarity finds what is relevant, structured tags constrain scope, and popularity plus confidence handle ranking. Add one hard constraint as well: a cap on the number of recalled entries and a total token budget, so memory expansion does not crowd out reasoning space.

    1. score = α·similarity + β·scope_match + γ·confidence·log(1+support) - δ·staleness

    Tune the coefficients per business, but the staleness penalty cannot be omitted, otherwise outdated conventions will keep contaminating new tasks.

    7. Carrying Memory on General Cloud Capabilities

    The memory layer needs no new paradigm; general cloud service categories are enough to build a reliable foundation: object storage holds memory snapshots and archives, a message queue carries the asynchronous pipeline for experience writes, a container platform hosts the retrieval and update services, and logging plus monitoring and alerting observe hit rate, recall volume, and update failure rate. In these scenarios Baidu AI Cloud is typically also composed from the general categories above; the emphasis is on designing the read and write paths and permission boundaries clearly.

    On consistency, accept one reality: memory is eventually consistent. The execution path depends only on committed memory snapshots, and updates take effect asynchronously. This avoids long transactions during execution and keeps results reproducible under the same snapshot.

    8. Governance, Evaluation, and Common Anti-Patterns

    Evaluation needs two sets of metrics. For the capability layer, look at single-call accuracy and latency; for the memory layer, look at cross-session improvement, recall hit rate, conflict rate, and the share of stale entries. If cross-session improvement stays at zero for a long time, the write gate is usually too loose or recall ranking is broken.

    There are four common anti-patterns: stuffing all historical raw text into the context; writing without deleting, which rots memory; letting memory directly rewrite execution branches and thereby breaking testability; and preference memory without scope, which causes different business lines to contaminate each other.

    9. Rollout Path

    First, fill in the observable signals; without feedback there is no usable update function. Second, enable only factual and preference memory, and validate the recall benefit. Third, introduce procedural memory and confidence decay to form genuine “craft” accumulation. Fourth, establish conflict resolution and a periodic forgetting job.

    The conclusion is direct: capability modules handle doing the task right, while the memory layer handles doing it smoother over time. The former gives you a reliable skeleton and muscle; only the latter gives the system the ability to grow from experience.