Agent Memory Layer Design: The Missing Piece in the Three-Layer Architecture
This article explains why a thin orchestration framework plus thick skills is not enough for AI agents, and how a dedicated memory layer turns one-off executions into reusable assets. It covers the three-layer analogy of skeleton, muscle, and nerves, four practical categories of memory content, write strategies that treat forgetting as a filtering mechanism, read strategies that inject minimal context, common pitfalls, and metrics for proving that memory actually improves pass rate, cost, and interaction rounds. A closing section outlines how to deploy the layered design on Baidu AI Cloud.
1. Where the Problem Starts: Plenty of Capabilities, No Growth
A common design choice in agent engineering is to keep the orchestration framework (the harness) thin and the capability modules (skills) thick. The harness handles intent recognition, task orchestration, context assembly, and execution control. Skills compete on coverage: retrieval, computation, code execution, format conversion, business validation, and so on. This “thin framework, thick capabilities” combination works well in practice: boundaries are clear, testing is straightforward, and results are reproducible.
Push it to the extreme, however, and a structural gap appears: the number of capabilities keeps growing while system performance stays flat. The hundredth invocation is no different from the first. The agent has not become better at understanding the user, nor does it make fewer mistakes. It has a large set of executable actions but lacks the dispositions that grow out of execution history.
That is exactly what a memory layer is for.
2. Rethinking “Never Forgets”: Determinism Is a Strength, Not Growth
“Never forgets” is often sold as a capability-module feature. What it really means is determinism: the same input produces the same output, with no random drift. This matters for reliability, especially in billing, permissions, and data validation, where reproducibility is auditability.
The catch is that an agent’s objective function is not “always return the same result.” It is “in the same class of scenarios, be steadier, more accurate, and cheaper this time than last time.” Determinism alone cannot deliver that. It needs an additional mechanism that distills useful signals from execution history into reusable preferences.
The difference can be written as pseudocode:
# Skill module: pure functional executiondef run_skill(input, skill):return skill.execute(input) # output depends only on input and implementation# With a memory layer: execution plus accumulated experiencedef run_with_memory(input, skill, memory):ctx = memory.retrieve(input) # fetch relevant historical preferences and constraintsresult = skill.execute(input, ctx) # same capability, tuned through parametersmemory.write(input, result, ctx) # feedback flows back, closing the loopreturn result
Note that memory does not rewrite the skill implementation. It changes the invocation context. Skills stay testable and rollback-safe, while optimization happens on the data side.
3. The Three-Layer Architecture: Skeleton, Muscle, Nerves
The human body makes the responsibility boundaries obvious:
- The orchestration framework is the skeleton: it determines structure, posture, and direction of movement, and it decomposes tasks, selects capabilities, and controls rounds and termination conditions.
- Capability modules are the muscle: they determine strength, speed, and the concrete action, completing one well-defined thing per invocation.
- The memory layer is the nervous system: it connects skeleton and muscle, feeding the feedback from the last movement into the next one.
Muscle growth comes from structural change under repeated stimulus, not from repetition itself. Muscle without nerves means a hundred squats are just four independent contractions stacked together. Likewise, a hundred identical task invocations produce no structural change in the system. Engineering that structural change is precisely the memory layer’s job: converting one-off executions into an accumulating asset.
4. What Memory Actually Stores: Four Actionable Categories
Memory is not an archive of full conversation transcripts; that only adds retrieval noise and context bloat. Actionable content usually falls into four categories:
- Preference memory: output length, language style, glossary, banned expressions, delivery format. For example, “this user prefers conclusions first, body text under 300 words.”
- Process memory: successful paths and failure traps for a class of tasks. For example, “data cleaning tasks often break at the field type conversion step, so validate beforehand.”
- Cost memory: differences in path cost. For example, “for the same query, cache hits and full scans differ significantly in latency, so reuse intermediate results first.”
- Fact memory: stable, verifiable entity information such as project structure, API contracts, and the meaning of environment variables. This category must carry a source and a validity period.
The first two determine “do it better,” the third determines “do it cheaper,” and the fourth determines “no need to ask again.”
5. Write Strategy: Forgetting Is a Filtering Mechanism
What makes human memory reliable is not capacity but selection. The engineering equivalent is a gate on writes, so incidental noise is not frozen into a long-term preference:
- Significance: only information that affects result quality or cost is worth writing.
- Repetition: a single event is recorded as a candidate; consistent recurrence promotes it to a stable preference.
- Verifiability: guesses that cannot be confirmed by results do not enter the long-term layer.
- Conflict resolution: when new evidence conflicts with old memory, weight by time decay and confidence rather than overwriting outright.
- Lifecycle: give every memory an expiry and a review cycle; downgrade or evict it once expired.
A simplified filtering rule:
def should_promote(candidate, stats):return (candidate.significance >= 0.6and stats.occurrences >= 3and stats.consistency >= 0.8and candidate.verifiable)
6. Read Strategy: Getting Memory into Context at Minimal Cost
The core tension at read time is “enough information” versus “context does not explode.” The common approach is layered recall: coarse filtering by task type and scenario tags, then fine ranking by semantic similarity, then injecting only the top few entries, presented as structured fields rather than long text.
{"scene": "data_cleaning","preference": {"style": "concise", "format": "table"},"pitfall": ["validate_dtype_before_cast"],"confidence": 0.86,"updated_at": "2026-08-20"}
Two more engineering constraints apply. First, memory injection must be traceable, so it is possible to reconstruct why a given output was produced. Second, provide switches and priorities: high-determinism tasks can skip injection to preserve pure functional behavior.
7. Common Pitfalls
- Treating memory as long context. Context is a workspace; memory is filtered long-term assets. Neither substitutes for the other.
- Letting memory rewrite skill implementations. This costs the system its testability; optimization belongs in invocation parameters and policy.
- Recording only successes. Failure paths are often more valuable to reuse because they directly prevent repeated mistakes.
- Missing governance. A memory layer without permission isolation, redaction, and audit spreads sensitive information into scenarios where it does not belong.
8. Evaluation and Evolution: Proving Memory Works
The value of a memory layer must be demonstrated with metrics, not intuition. Observable dimensions include first-pass rate for the same class of tasks, average interaction rounds, manual rework rate, average latency and invocation cost, and preference hit rate. In practice, run the same batch of tasks under two configurations, with and without memory, compare the deltas on those metrics, and check whether the gap widens as batches progress.
If the metrics do not improve across batches, the filtering gate is usually too loose or recall is imprecise. Fix data quality first, then talk about models and frameworks.
9. Deployment Approach on Baidu AI Cloud
When building this kind of system on Baidu AI Cloud, the work can be split along general capability lines: host the orchestration framework on a container platform for elasticity and isolation; implement capability modules as function-based services or task queues for asynchronous execution; place the memory layer on object storage and databases, with logging and monitoring plus alerting for tracing and quality observation; and consolidate permissions, redaction, and audit through unified identity and key management. Keeping the layering of “thin framework, thick capabilities, governable memory” preserves the reliability of deterministic execution while letting the system improve with use.
10. Closing
“Thin framework, thick capabilities” solves whether an agent can get work done. The memory layer solves whether it gets better at it. Design forgetting as filtering, settle preferences into data, and feed experience back as context, and the agent stops being a machine that restarts every time and becomes an executor that accumulates craft.
