Optimizing Autonomous Agent Architecture: A Dual-Loop Design from Memory to Skills

    This article explores architectural optimization practices for autonomous execution agents, focusing on transitioning from plugin-style invocations to a self-driven architecture. It details a dual-loop design that integrates a four-tier memory system with skill sedimentation, introduces core constraint documents (AGENTS.md, Skill Pyramid, YINYANG.md) for defining behavioral boundaries, and emphasizes dynamic mechanisms for memory, skill evolution, and decision constraints to build a continuously evolving agent system.

    Optimizing Autonomous Agent Architecture: A Dual-Loop Design from Memory to Skills

    1. Background: From “Plugin Invocations” to “Autonomous Architecture”

    When developers first encounter autonomous agents, they often treat them as mere components within an orchestration framework or toolchain—the main program handles scheduling, and the agent executes only a specific step. In this model, the agent’s capabilities are severely underestimated.

    As practices deepen, a trend emerges: rather than treating the agent as a called “plugin,” it is more effective to make it the backbone of the execution architecture, treating external tools as its capability peripherals. This shift in perspective brings a series of architectural adjustments and optimizations. This article explores three core modules: the memory system, core documentation, and decision boundaries.

    2. Memory System: From Three Tiers to Four, Key in “Integration”

    2.1 The Basic Logic of Layered Memory

    An agent’s memory system is typically divided into three tiers:

    1. Conversation Record Layer: Raw interaction logs, high information volume but noisy;
    2. Execution Process Layer: Intermediate task states, tool invocation results, error and retry traces;
    3. Semantic Understanding Layer: Knowledge refined and summarized from historical information by Large Language Models (LLMs) for reuse.

    The problem with the three-tier structure is that the layers are “stacked” rather than “flowing.” As memory accumulates, retrieval noise increases, diluting critical information.

    2.2 Introducing the Fourth Tier: Skill Sedimentation

    The key to optimization is not adding another storage layer, but building a transformation pipeline from memory to skills:

    1. Conversation Record Clustering -> Execution Process Extraction -> Deep Understanding (LLM) -> Crystallization into Skills

    Specifically:

    • Clustering: Grouping similar conversations and task patterns to identify high-frequency scenarios;
    • Extraction: Extracting “what works and what fails” from execution traces;
    • Understanding: Having the model summarize generalizable methodologies;
    • Crystallization: Structuring the methodology into a Skill that can be directly invoked in the next execution cycle.

    This forms a dual-loop system: the memory loop is responsible for “learning from experience,” and the skill loop is responsible for “executing with learned outcomes.” Invoked skills generate new execution records, which feed back into the memory layer. The ultimate goal is to remember less, but remember firmly—no need to retain full raw records because critical experiences have been sedimented as high-density skills.

    3. Core Documents: The Agent’s “Operating System Capabilities Match Its Code”

    An often-overlooked fact: constraint documents are no less important than skills and scripts themselves. From the execution architecture perspective, writing good core documents is even more crucial than creating skills. The reason is simple: documents define the agent’s behavioral boundaries. Well-constrained, it heads in your desired direction; poorly constrained, it improvises and misses the point.

    3.1 Master Document (AGENTS.md): The Global Hub

    This is the primary document, functioning like the kernel configuration of an operating system, linking all other documents. It should explicitly define:

    • Execution Process and Rules: The standard chain of Task Reception -> Analysis -> Planning -> Execution -> Reporting;
    • Skill Orchestration Mechanism: How skills are discovered, how invocation order is determined, and how conflicts are resolved;
    • Reporting Format: Unified output structure to avoid wildly varying result styles;
    • Memory System Architecture: Read/write rules and eviction policies for each memory layer;
    • Fault Tolerance Mechanism: Downgrade and retry paths for tool invocation failures, network anomalies, and result exceptions.

    3.2 Skill Pyramid Document: Dynamic Layering over Static Tags

    Skills should be layered based on invocation frequency and business value, forming a pyramid structure:

    • Base Layer (approx. 55%): File operations, terminal commands, web access—used daily, requiring extreme stability;
    • General Layer (approx. 30%): Debugging, task planning, code review—commonly used, requiring generalization;
    • Specialized Layer (approx. 15%): Machine learning, creative design, repository collaboration—triggered in specific scenarios;
    • Experimental Layer (approx. 5%): New and draft skills—a sandbox for trial and error.

    It is crucial to emphasize that the pyramid is a perspective for dynamic analysis, not a one-time static classification. The associated upgrade mechanism is as follows:

    1. Experimental Layer -> Specialized Layer: Used >=3 times within 30 days + subjectively verified as usable
    2. Specialized Layer -> General Layer: Reused in >=3 different projects + abstractable for generalization

    Conversely, skills not invoked for a long time should be downgraded or eliminated to prevent the skill library from bloating and degrading retrieval efficiency.

    3.3 Decision Boundary Document (YINYANG.md): The Yin-Yang Table

    This is the most notable design, combining Daoist philosophy with mathematical set theory. The core idea can be formalized as:

    1. User expresses P (what they want)
    2. -> Agent infers not-P (what they do not want / boundaries)
    3. -> Recorded as a pair
    4. -> Next time, direct table lookup match

    Key design points:

    1. Paired Existence: P and not-P are semantic opposites; each record in the table is naturally a pair;
    2. No Positive/Negative Distinction: Yin and Yang are merely semantic opposites, not value judgments;
    3. Reversible Query: If a user actually prefers not-P in a given instance, there is no need to add a new entry—simply reverse-query the original P. The table structure remains unchanged, only the query direction shifts;
    4. Continuous Growth: Whenever a user makes a correction, the agent summarizes and writes it into the table. Over time, this table becomes a continuously growing record of decision boundaries, rather than a static list of dogmas.

    4. Conclusion

    Building a long-term evolving agent system essentially involves doing three things:

    1. Connecting the transformation pipeline between memory and skills, allowing experiences to automatically sediment into capabilities;
    2. Defining the behavioral skeleton with core documents—the master document governs the global scope, the pyramid governs skills, and the boundary table governs preferences;
    3. Maintaining the dynamism of all mechanisms—layers must be able to upgrade and downgrade, boundary tables must grow, and memories must be evicted.

    The philosophy behind this architecture is pragmatic: rather than piling more parameters and tools onto the agent, it is better to spend time designing “how it remembers, how it is constrained, and how it grows.” This is also the direction verified by current enterprise-level agent platforms—memory management, workflow orchestration, and behavioral constraints are becoming critical benchmarks for measuring the engineering maturity of AI agents.