Agent Memory and Skills: Implementing a Dual-Cycle Architecture

    This article explains why agent engineering is shifting from a host-controlled "calling component" model to an agent-as-executor architecture, and the three pieces of infrastructure that shift requires: a memory system, core constraint documents, and a skill governance system. It covers the limits of the native three-layer memory structure (recall noise and no experience consolidation), the four-layer integration that adds an external memory store and a core document layer, the processing pipeline from raw conversation to executable skill, the three documents to maintain with separated responsibilities, a dynamic skill pyramid with quantified promotion and demotion rules, and the resulting dual-cycle loop with its observable metrics and three implementation recommendations.

    Agent Memory and Skills: Implementing a Dual-Cycle Architecture

    1. Background: From “External Invocation” to “Autonomous Execution”

    In the early stages of agent engineering, a common pattern was to build an agent with reasoning and execution capabilities as a callable component of some general-purpose tool or coding assistant. The host program handled scheduling, and the agent was responsible only for local tasks. This “primary-and-auxiliary” structure works well during validation, but once the task chain grows longer and involves multi-file changes and multiple rounds of verification, problems surface quickly: context gets crowded out by irrelevant information, execution paths become unpredictable, the same class of error recurs, and reporting formats stay inconsistent.

    So the architectural focus began to shift: let the agent itself become the execution主体, with the host environment degrading into a runtime foundation that provides basic capabilities such as files, a terminal, and network access. The core of this article is the three pieces of infrastructure that must be completed during this migration — the memory system, the core constraint documents, and the skill governance system — and how they form a “memory–skill” dual cycle.

    2. Memory System: Integrating Four Layers Instead of Three

    2.1 Capability Boundaries of the Native Three-Layer Structure

    The memory that ships with most agent frameworks is a three-layer structure, usually abstracted as:

    1. L1 Session buffer: raw messages within the current conversation window
    2. L2 Summary memory: compression and rolling summarization of past sessions
    3. L3 Vector retrieval: historical fragments recalled by semantic similarity

    This structure solves “nothing lost in the short term, everything searchable in the long term,” but it has two inherent flaws. The first is recall noise: semantic similarity does not equal relevance to the current task, and the retrieved fragments often require the model to make a second judgment, which adds to the reasoning burden instead of reducing it. The second is experience that never settles: the pitfalls already encountered and the approaches already validated in a conversation exist only as “text fragments,” so they cannot be reused directly as executable constraints in the next task.

    2.2 Four-Layer Integration with an External Memory Layer

    On top of the three layers, connect an independent memory storage and retrieval layer (a common industry practice is to deploy a localized memory service plugin that integrates with the agent over a standard protocol), forming four layers:

    1. L1 Session buffer → L2 Summary memory → L3 External memory store → L4 Core documents

    The key point is not “one more storage layer,” but connecting L4 with L3 to rebuild a processing pipeline from raw conversation to executable skill:

    1. Conversation clustering: merge scattered turns into “events” by task intent, rather than stacking them by time.
    2. Execution distillation: extract a four-element tuple of “goal–action–result–failure cause” from each event, discarding pleasantries and redundant reasoning.
    3. Deeper understanding: have the model attribute the distilled results, judging whether success came from a correct method or merely from a simple sample.
    4. Skill solidification: only the parts judged as “method correct and reusable” are written into the skill layer, becoming structured capabilities that can be invoked directly next time.

    The output of this pipeline is bidirectional: upward it supplements memory (fewer entries, higher information density), downward it generates skills (explicit trigger conditions and execution steps). This is the first half of the “memory + skill” dual cycle.

    3. Core Documents: Constraints Before Capabilities

    A counterintuitive but repeatedly validated conclusion: at the architecture level, writing good constraint documents matters more than adding new skills. Skills determine “what can be done”; documents determine “how to do it, in what order, and how to report when done.” When constraints are missing, the model improvises in ways that look reasonable, producing a large amount of rework.

    Maintain at least three documents, with strictly separated responsibilities:

    3.1 Main Entry Document (AGENTS-style Convention File)

    As the single hub, it links the other documents and should cover:

    • Execution flow and stage gates (when code must be read before acting)
    • Skill orchestration mechanism (serial/parallel, fallback on failure)
    • Unified reporting format (conclusion first, change list, verification evidence)
    • Memory system architecture description (read/write permissions for each of the four layers)
    • Fault tolerance and termination conditions (two consecutive failures of the same class must trigger a route change or a request for help)

    Illustrative snippet:

    1. ## Execution gates
    2. 1. Do not modify code before locating the relevant files
    3. 2. After every change, run the project's existing validation commands
    4. 3. Same error twice in a row → stop tweaking, switch approach and escalate
    5. ## Reporting format
    6. - Conclusion:
    7. - Files changed:
    8. - Verification method and result:
    9. - Unresolved risks:

    3.2 Skill Index Document

    It only describes “which skills exist, when to use them, and what the entry point is,” without implementation details, avoiding the drift caused by maintaining the same content twice in both docs and code.

    3.3 Project Context Document

    It records stable facts such as directory conventions, dependency management, and coding standards. Its difference from memory: memory is “what has happened,” while the context document is “how things should be done here.”

    4. The Skill Pyramid: Dynamic Tiering, Not Static Labels

    Once the number of skills grows, the biggest cost is not storage but selection difficulty and context bloat. The essence of pyramid tiering is dynamic governance by “invocation frequency × value”:

    Tier Reference share Content examples Characteristics
    Foundation ~55% File read/write, terminal commands, web access High frequency, stable, almost no dispute
    General ~30% Troubleshooting and localization, planning, code review Reusable across projects
    Specialized ~15% Data processing, creative generation, repository collaboration Specific scenarios
    Experimental ~5% Draft skills, approaches pending validation Failure allowed

    It must be emphasized that tiering is a dynamic analytical view, not a one-time classification label. The basis for judgment is recent real invocation logs, not subjective impression. The accompanying promotion and demotion mechanisms should be quantified:

    1. Experimental → Specialized: invoked effectively ≥ 3 times within 30 days, and the execution result was adopted
    2. Specialized → General: reused successfully in ≥ 3 different projects, with no project-specific changes required
    3. Any tier → Experimental: 3 consecutive invocation failures or bypassed manually

    The demotion channel is as important as the promotion channel; otherwise the pyramid degrades into a flat list that keeps expanding.

    5. Closing the Dual Cycle and the Engineering Payoff

    Putting the two lines together, the loop looks like this:

    1. Task execution → process logging → clustering and distillation → deeper attribution ┐
    2. ↑ ↓
    3. Skill invocation ← skill index ← promotion/demotion ←──────── memory writes

    Each turn of the loop should produce three observable changes: fewer context entries injected per task, a lower recurrence rate for the same class of error, and a higher proportion of skills directly reusable across projects. If these three metrics do not improve, it usually means the distillation step is too coarse and “anecdotal experience” has been mistaken for a “general method.”

    Three practical recommendations for implementation: first, memory writes must have an admission threshold — better fewer than too many; second, put constraint documents under version control and review them as rigorously as code; third, retain human veto power, allowing any memory entry or skill to be sent back to the experimental tier at any time.

    The final answer of this architecture is “remember less, and remember it well” — replacing uncontrolled context accumulation with strict processing and governance. If you need to host capabilities such as the memory store, logs, and monitoring alerts, you can use general-purpose cloud categories such as object storage, container platforms, and logging services, without binding to a specific implementation.