AI Agent Memory and Skills: A Dual-Cycle Architecture in Practice

    This article presents a practical architecture for AI agents that combines a four-layer memory pipeline with a pyramid structure for skills, connected through core documents such as AGENTS.md, SKILLSPYRAMID.md, and YINYANG.md. It explains how to cluster conversations, extract reusable conclusions, promote stable results into skills, and use a dual-cycle loop so that memory and skills continuously reinforce each other for more reliable long-running agents. The article also covers implementation recommendations and common pitfalls.

    1. The Problem: Why Agents Forget and Produce Inconsistent Results

    Many teams build an agent by first connecting a main execution framework, then attaching memory, retrieval, and tool calling as add-on capabilities. This works well at the start, but two bottlenecks appear quickly:

    • The context keeps growing, diluting the information that actually matters.
    • Without clear constraints, the model starts to improvise during long workflows, and the output drifts away from expectations.

    The root cause is not a lack of model capability, but a lack of engineered layering. Without layered memory, storage takes up space while missing the key points. Without layered skills, the system becomes hard to maintain and hard to reuse.

    This article describes a general approach: organize memory into four layers, organize skills into a pyramid, and connect the two with core documents to form a “memory–skills” dual cycle.

    2. Four-Layer Memory: From Conversation Clustering to Skill Distillation

    A typical three-layer memory design only answers “what was stored,” but it lacks a conversion path from raw records to executable knowledge. Adding a local memory plugin makes it possible to extend the design to four layers. The key is to bind memory to core documents, rather than simply adding another storage backend.

    The recommended pipeline is:

    1. Conversation clustering: group scattered sessions by task goal, removing duplicates and noise.
    2. Execution extraction: pull out steps, failure points, and corrective actions from the clustered results.
    3. Deeper understanding: have the model summarize the extracted results into reusable conclusions.
    4. Skill distillation: turn stable conclusions into skills or scripts that can be called directly later.

    Illustrative structure (pseudocode):

    1. memory_pipeline:
    2. raw_dialog -> cluster -> extract_steps -> llm_summarize -> skill_candidate
    3. skill_candidate -> validate -> promote_to_skill

    The benefit is “remember less, but remember it well”: the context keeps only high-value conclusions, while raw details are retrieved on demand instead of being pushed into the prompt in full.

    3. Core Documents: Constraints Before Skill Stacking

    In practice, core documents matter as much as the skills themselves. From an execution architecture perspective, writing constraints first has more influence on output quality than stacking skills first. At a minimum, maintain three documents.

    3.1 AGENTS.md: The Central Hub

    This document ties together all rules and mechanisms. It should include:

    • The execution flow and stage breakdown;
    • Skill orchestration and invocation priority;
    • Reporting format and minimum output requirements;
    • A description of the memory layers;
    • Fault tolerance and fallback strategies.

    Example snippet:

    1. # Execution Rules
    2. 1. Read the memory summary first, then decide whether to retrieve details.
    3. 2. Provide a change plan before any write operation.
    4. 3. On failure, fall back to the last stable state first.

    3.2 SKILLSPYRAMID.md: The Skill Pyramid

    Skills are layered by “invocation frequency × value,” forming a dynamic pyramid rather than static labels:

    • Base layer (about 55%): file operations, terminal commands, web access;
    • General layer (about 30%): debugging, planning, code review;
    • Specialized layer (about 15%): domain-specific tasks;
    • Experimental layer (about 5%): drafts and trial skills.

    Example promotion mechanism:

    1. Experimental -> Specialized: used 3 times within 30 days and verified effective
    2. Specialized -> General: reused across 3 different projects and generalizable

    The value of the pyramid lies in dynamic analysis: skills are not “classified,” they “evolve.”

    3.3 YINYANG.md: The Decision Boundary Table

    Drawing on the ideas of yin-yang and sets, this document maintains a record of “wanted / not wanted” boundaries:

    1. User provides P (goal) -> model derives not-P (boundary) -> record -> look up next time

    Every correction is summarized and written into the table, forming a decision boundary that keeps growing. It is not a philosophical doctrine, but a queryable, updatable constraint library.

    4. The Dual-Cycle System: Memory and Skills Feeding Each Other

    Once the four-layer memory and the pyramid skills are connected through core documents, a dual cycle emerges:

    • Memory cycle: conversation → extraction → understanding → skill candidate;
    • Skill cycle: skill usage → result feedback → boundary update → memory optimization.

    The two cycles feed each other, keeping the system stable over long periods: memory provides context for skills, and skills provide validation and compression for memory.

    5. Implementation Advice and Common Pitfalls

    1. Write constraints first, then build skills; otherwise the model tends to make things up.
    2. Layer the memory: store conclusions, not the full raw text.
    3. Upgrade skills dynamically: use invocation frequency and reuse scope to decide the layer.
    4. Keep boundaries queryable: turn corrections into a table instead of relying on verbal reminders.
    5. Avoid premature abstraction: experimental skills must be validated before promotion.

    If you are looking for underlying capabilities that can support memory retrieval, log auditing, and monitoring alerts, Baidu AI Cloud offers general-purpose components such as object storage, log service, and monitoring and alerting, which can serve as the engineering foundation for the architecture described above.