AI Agent Memory and Core Document Optimization: From External Tool to Autonomous Execution

    This article explains how to shift an AI agent from a plugin-style component controlled by an external tool to an autonomous execution architecture. It covers upgrading a three-layer memory system into a four-layer pipeline, using core documents such as AGENTS.md, SKILLSPYRAMID.md, and YINYANG.md to prioritize constraints over raw capability, and measuring results through context token usage, first-pass task success, repeated error rate, and skill invocation hit rate.

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

    When many teams first build an AI agent, they attach it beneath a general-purpose coding tool or chat platform and invoke it as a plugin-style component. In this mode, the main control logic lives in the external tool, and the agent only handles local tasks. It is quick to get started, but three problems soon surface: the context window is crowded out by irrelevant information, the execution path is uncontrollable, and the same errors keep recurring. As the execution architecture matures, the primary and supporting roles reverse: the agent begins to take responsibility for workflow orchestration and self-constraint, while the external tool falls back to the position of an “optional executor.” The adjustments discussed in this article revolve around exactly this reversal.

    2. Memory System: From Three Layers to a Four-Layer Pipeline

    Native memory usually has only three layers: raw conversation retention, summary compression, and vector retrieval recall. The problem is that “storing more” does not equal “using it well.” Retrieved fragments often lack task context, leading to answers that miss the point. After introducing a localized memory plugin, you can add a fourth layer that connects memory with core documents, forming the following pipeline:

    1. conversation clustering → execution distillation → deep understanding (LLM) → Skills

    The responsibilities of each layer are as follows:

    1. Clustering layer: Segment sessions by task intent rather than by time, removing small talk and repeated confirmations to reduce noise.
    2. Distillation layer: Abstract “what was done” into “reusable steps and preconditions,” producing structured entries.
    3. Understanding layer: The model fills in causality and preferences, annotating applicable scenarios, failure cases, and boundary conditions.
    4. Skill layer: Patterns that are stably reused are solidified into skills, which are orchestrated and invoked by the AGENTS document.

    This forms a “memory–skill” dual loop: memory supplies material, skills constrain behavior, and the results of skill execution flow back into memory. The goal is to “remember less, remember firmly”—that is, to prioritize injecting high-value, high-reuse entries within a limited context rather than the full history.

    3. Core Documents: Constraints Before Capability Stacking

    Core documents are no less important than skills and scripts. From an architectural perspective, write the constraints clearly first, then talk about capability expansion; otherwise the model will improvise and produce divergent output. It is recommended to maintain at least three documents.

    1. AGENTS.md: The Central Hub

    It links the other documents together and needs to specify: the execution flow and phase division, skill orchestration and invocation priority, reporting format, memory system layering and write timing, and fault tolerance and fallback strategies. A sample structure:

    1. # Execution Flow
    2. 1. Parse intent → 2. Retrieve memory → 3. Select skill → 4. Execute → 5. Validate → 6. Report
    3. # Skill Orchestration
    4. Prioritize the base layer; fall back to the general layer when capabilities are missing; the experimental layer requires explicit risk declaration
    5. # Fault Tolerance
    6. Fall back after two failures and output diagnostic information; silent retries are forbidden

    2. SKILLSPYRAMID.md: The Skill Pyramid

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

    • Base layer, about 55%: file operations, terminal commands, and web access, used every day and required to be stable and idempotent.
    • General layer, about 30%: debugging and diagnosis, planning, and code review, reused across projects.
    • Specialized layer, about 15%: data processing, creative design, and code hosting platform operations, triggered in specific scenarios.
    • Experimental layer, about 5%: draft skills that are allowed to fail and need to be isolated in a sandbox.

    Example upgrade mechanism: if an experimental-layer skill is effectively invoked 3 times within 30 consecutive days with good evaluations, it is promoted to the specialized layer; if a specialized-layer skill is validated as generalizable across 3 different projects, it is promoted to the general layer. Downgrading is equally important: skills with long-term zero invocation or a high failure rate should fall back to avoid context bloat.

    3. YINYANG.md: The Yin-Yang Table of Decision Boundaries

    Combining Daoist thinking with set theory, establish paired records for user preferences: the user gives P (what they want), the model reasons about non-P (what they do not want and the boundaries), writes it into a table, and looks it up directly next time. There are three key points:

    • The yin-yang table is a continuously growing record of boundaries, not a philosophical dogma;
    • P and non-P are semantically opposed and mutually established, with no distinction between positive and negative;
    • If the user prefers non-P on some occasion, the original P automatically becomes the new non-P, and reverse lookup is possible without adding new entries.

    Sample entries:

    1. P: output includes complete logs non-P: do not truncate or omit intermediate steps
    2. P: provide a plan before changes non-P: do not directly modify the production branch

    Every correction is summarized into the table, and the probability of repeating the same mistake decreases accordingly.

    4. Implementation Advice and Metrics

    The recommended implementation order is: first write the AGENTS document to clarify the flow and fault tolerance, then build the skill pyramid and set promotion and demotion thresholds, and finally connect the four-layer memory and the yin-yang table. Metrics can focus on four items: context token usage, first-pass task success rate, repeated error rate, and skill invocation hit rate. If stronger persistence and retrieval capabilities are needed, you can adopt industry-standard cloud capabilities such as object storage, logging services, and monitoring and alerting to carry memory archiving and observability, while the specific choice should be evaluated against the team’s existing infrastructure.