Agent Memory and Skills: A Practical Guide to the Dual-Cycle Architecture

    This guide explains how to move from an external-tool-first agent setup to a self-controlled execution architecture. It covers a four-layer memory system, three core documents (an execution contract, a dynamic skill pyramid, and a decision-boundary table), and a four-step rollout with clear acceptance criteria for reducing output variance, improving memory recall, and enforcing high-risk safeguards.

    1. The Starting Problem: Why Agents Become “Less Obedient” Over Time

    Many developers begin by using an external AI coding tool as the main entry point, plugging their in-house agent in as a callable component. This “primary–secondary” structure works well during validation, but as task chains grow longer, the problems surface all at once: context gets truncated by the outer tool, execution paths become uncontrollable, memory writes are scattered, and reporting formats drift as the outer framework changes.

    The architectural focus therefore needs to shift: from “the outer tool orchestrates me” to “I define the execution contract.” This is not a debate about which tool is better; it is a question of who owns control. Once you own the execution architecture, optimization comes down to three things: how memory is layered, how rules are front-loaded, and how skills are invoked correctly.

    2. A Four-Layer Memory System: From a Running Log to Reusable Cognition

    Native memory usually has only three layers and tends to stay at “recording what happened.” After adding a localized memory plugin, you can consolidate it into four layers and bind it tightly to core documents to form a closed loop:

    1. Conversation clustering: group scattered sessions by task goal and remove duplicate noise.
    2. Execution distillation: extract steps, failure points, and corrective actions into searchable entries.
    3. Deep understanding: have the model summarize entries into “preferences–constraints–counterexamples.”
    4. Skills consolidation: turn stable conclusions into skills or script entry points.

    The result is a dual cycle between memory and skills: memory feeds skills, and skill execution results feed back into memory. The key metric is not “how much is stored” but “whether recall is accurate.” It is recommended to attach a task domain, a time-decay weight, and a hit count to each memory entry, so that outdated preferences are not treated as hard rules during retrieval.

    3. Core Documents: The Foundation of the Execution Architecture

    Core documents matter as much as skills and scripts, and arguably take higher priority. If constraints are poorly written, the model will improvise; if constraints are clear, output converges reliably. At minimum, maintain three documents.

    3.1 Main Entry Document (Execution Contract)

    This is the hub that links the other documents and modules. It should include the execution flow, hard rules and soft preferences, the skill orchestration mechanism, the reporting format, the memory architecture, and fault-tolerance and rollback strategies. Example structure:

    1. Execution flow: parse goal -> select skill -> execute -> validate -> report
    2. Hard rules: do not delete unknown files; high-risk operations require a second confirmation
    3. Reporting format: conclusion / changes / risks / next steps
    4. Fault tolerance: after two failures, switch approach and request confirmation

    3.2 Skill Pyramid Document (Dynamic Layering)

    Skills are layered by “invocation frequency × value” rather than static labels:

    • Base layer, about 55%: file operations, terminal commands, web access; high-frequency and stable.
    • General layer, about 30%: debugging, planning, code review; reused across projects.
    • Specialized layer, about 15%: domain-specific tasks; low-frequency but high-value.
    • Experimental layer, about 5%: draft skills where trial and error is allowed.

    The promotion mechanism must be quantifiable: moving from the experimental layer to the specialized layer can require 3 uses within 30 days with verified effectiveness; moving from the specialized layer to the general layer can require reuse across 3 different projects and abstraction into a general interface. This keeps the skill library from bloating into a “favorites folder.”

    3.3 Yin-Yang Table Document (Decision Boundaries)

    Borrowing the idea of sets and opposing semantics, it records “want P” and “do not want not-P.” When the user requests P, the model reasons about the boundary not-P, and after execution writes the correction back into the table. Its defining trait is that entries hold in pairs and can be queried in reverse: if the user prefers not-P on some occasion, the original P automatically becomes the new not-P, with no need to add a new entry. It is essentially a continuously growing decision-boundary library that turns every correction into prevention for the next time.

    4. Rollout Order and Acceptance Criteria

    A four-step approach is recommended: first write the main entry document, then integrate the four-layer memory, then establish skill layering and promotion rules, and finally complete the yin-yang table. Acceptance is judged on three points: whether output variance drops when the same task is repeated; whether the memory recall hit rate improves; and whether high-risk operations are reliably blocked by rules. If these three improve, the architecture has moved from “it runs” to “controllable, reusable, and evolvable.”