AI Agent Memory and Skills: A Dual-Cycle Architecture in Practice
This article presents a practical architecture for AI agents built around two reinforcing cycles: a layered memory system and a governed skill pyramid. It explains why plugin-style capability integration leads to context ambiguity, behavioral drift, and poor reuse, then details a four-layer memory model, a constraint document system with a single hub, frequency-and-value skill tiers with quantitative promotion rules, and a P / non-P boundary table that turns user corrections into reusable decision limits. Readers will find concrete structures, JSON and Markdown examples, a four-step rollout sequence, and metrics for evaluating whether the architecture is actually working.
1. The Problem: From Plugin-Style Calls to a Native Execution Architecture
When many teams first build agents, they treat each newly added capability as a plugin attached to an existing main flow: the main program handles orchestration, and the new component plays a supporting role. This approach is quick to adopt, but it soon exposes three structural problems.
First, context ownership is unclear. Conversation history, execution traces, and distilled conclusions are scattered across different components. Anyone can write to them, and no one is responsible for organizing them, which eventually produces a large amount of duplicated and contradictory “memory garbage.”
Second, missing constraints cause behavioral drift. Without clear execution rules, the model tends to produce output that looks reasonable but does not match team conventions, and the cost of correcting it is far higher than the cost of writing the rules down once.
Third, capabilities cannot be reused. Every task assembles a temporary workflow, similar problems start from scratch again and again, and skills are neither measured nor tiered, let alone retired or upgraded.
The real turning point, therefore, is not switching to a stronger model but rebuilding the execution architecture itself: giving memory layers, giving rules a single entry point, giving skills a lifecycle, and letting boundaries accumulate over time. This is the central proposition of this article.
2. The Memory System: Four Layers and a “Few but Solid” Design Principle
A usable agent memory system must distinguish at least four kinds of information: raw interactions, process experience, semantic understanding, and executable capabilities. Stacking them into four layers significantly reduces retrieval noise.
- Raw layer: stores complete conversations and tool call records, applying only compression and indexing, and does not directly participate in decisions.
- Cluster layer: groups raw records by topic, folding “multiple attempts at the same class of problem” into a single entry.
- Insight layer: the model abstracts the clustered results into structured conclusions of “problem pattern - effective approach - failure cause.”
- Capability layer: turns repeatedly validated conclusions into skills or scripts that become assets callable directly next time.
The key design principles are “single entry, controlled writes, layered reads.” All memory writes must pass through a unified pipeline and carry source, timestamp, confidence, and applicable scope; on read, only upper-layer conclusions are loaded by default, and lower-layer details are traced back only when the conclusions are insufficient.
A schematic memory entry looks like this:
{"id": "mem_0421","layer": "insight","topic": "Build artifact size governance","pattern": "Unlocked dependencies cause size fluctuations","action": "Pin versions and enable on-demand bundling","failure": "Full imports slowed down first paint","confidence": 0.82,"scope": ["frontend engineering", "continuous integration"],"refs": ["raw_1180", "raw_1204"]}
The benefits are direct: context length stays bounded, retrieval is more accurate, and every conclusion can be traced back to raw evidence, which prevents the model from inventing its own memories.
3. The Core Constraint Document: Rules as an Executable Hub
At the architecture level, the constraint document matters as much as the skills themselves. Skills answer “can it be done”; the constraint document answers “by what standard, in what order, and what to do when something fails.” Maintain at least three documents, with one main document serving as the single hub.
The main document does the connecting work: it states the execution flow, rule priority, skill orchestration, reporting format, memory architecture, and fault-tolerance policy. It should be short enough to be loaded in full, with details linked out to sub-documents to avoid context bloat.
# Execution Main Document (Summary)1. Read constraints first, then upper-layer memory conclusions, then select skills.2. Before any write operation, restate the goal and the scope of impact.3. Retry failed steps at most 2 times; beyond that, degrade and escalate.4. Report in a fixed three parts: conclusion / evidence / risks and next steps.
The second document covers skill tiering and governance; the third covers decision boundaries. Their relationship should be “the main document defines call order, sub-documents provide the criteria for judgment,” not three overlapping piles of rules.
4. The Skill Pyramid: Dynamic Tiering by Frequency and Value
Skill management fears two things above all: unlimited growth, and never retiring anything. A workable approach is a pyramid based on call frequency and value, with explicit rules for movement between tiers.
- Foundational tier (~55%): high-frequency, stable capabilities such as file read/write, command execution, and network access.
- General tier (~30%): cross-project reusable capabilities such as troubleshooting, planning, and code review.
- Specialized tier (~15%): domain-specific processes such as data training, design output, and code hosting collaboration.
- Experimental tier (~5%): draft skills and newly validated ideas, where failure is allowed.
Promotion must be quantified so that “it feels useful” is not the only standard:
Experimental -> Specialized: called effectively >= 3 times within 30 days, with success rate meeting targetSpecialized -> General: reused in >= 3 different projects with no changes to core logicAny tier -> Retired: zero calls for 60 consecutive days, or maintenance cost exceeds benefit
The pyramid is a dynamic analytical view, not a static label. The same skill may sit in different tiers across projects, so tiers should be recomputed periodically from real call logs rather than archived once and for all.
5. The Yin-Yang Table: Turning Corrections into Queryable Decision Boundaries
What users state is usually “what I want” (recorded as P), while the more informative part is the implicit “what I do not want” (non-P). Recording the two as a pair produces a boundary table that keeps growing.
The working loop is: the user expresses P -> the agent infers non-P and boundary conditions -> the table is checked before execution -> if a correction occurs, the entry is updated in reverse. The point is semantic opposition rather than good versus bad: P and non-P have no positive or negative ranking. When a user explicitly prefers non-P on some occasion, the original entry can simply be queried in reverse, with no redundant record added.
| Scenario P | Non-P (boundary) | Trigger condition |
|---|---|---|
| Output a concise conclusion | No long background or repeated preamble | Reporting requests |
| Prioritize compatibility | No unlocked version dependencies | Changes on production branches |
| Keep raw logs | No silent rewriting of history | Troubleshooting and auditing |
The value of the boundary table is turning each correction into a one-time investment: correct once, avoid the mistake for good. It complements the insight layer of the memory system - the insight layer accumulates “how to do it,” while the boundary table constrains “what not to do.”
6. Rollout Order and Metrics
A four-step rollout avoids the uncontrollable risk of a one-time rewrite.
Step one, unify the memory write pipeline; even two layers alone will immediately cut noise. Step two, complete the execution main document, fixing the flow, reporting format, and retry limits. Step three, add skill tiering with promotion and retirement metrics, driven by real logs. Step four, introduce the boundary table so manual corrections are archived automatically.
Track four metrics: upper-layer memory hit rate, context consumption per task, distribution of skill reuse counts, and recurrence rate of the same error class after correction. If the recurrence rate does not drop, the boundary table is not actually being read, and the call order should be checked instead of appending more entries.
When you need elastic compute, logging services, monitoring and alerting, or object storage to hold memory and trace data, Baidu AI Cloud’s general cloud product categories can be evaluated first: a container platform can host execution sandboxes, and logging and monitoring capabilities can observe the call chain, giving the architecture’s evolution observability and scalability.
