AI Agent Memory and Core Document Architecture: A Practical Guide

    This guide explains how to redesign AI agent memory and execution constraints to fix drifting, repetitive behavior in real projects. It covers upgrading three-layer memory into a four-layer loop, using core documents to enforce workflows and boundaries, building a dynamic skill pyramid, and applying a versioned decision-boundary table, along with a rollout sequence and acceptance metrics.

    1. The Problem: Why Agents Become Less Reliable Over Time

    Many teams run into the same pattern when building AI agents. A demo looks impressive, but once the agent enters a real project, its output starts to drift, it repeats the same mistakes, and it accumulates more and more skills without calling the right ones. The root cause is usually not model capability. It is an execution architecture that lacks two layers of constraint:

    • The memory system only stores information; it does not distill or reuse it.
    • There are no stable core documents, so behavior boundaries depend entirely on ad hoc prompts.

    This article focuses on a general-purpose agent architecture and presents a reusable approach: upgrade memory from passive storage into a dual-loop system of clustering, distillation, understanding, and skill formation, and use three core documents to make workflows, skills, and boundaries explicit.

    2. Memory System: From Three-Layer Storage to a Four-Layer Loop

    1. The Limits of the Native Three-Layer Memory

    The common three-layer memory consists of conversation logs, execution traces, and long-term summaries. It solves the question of whether anything is recorded, but not whether the recorded information is usable. The result is record bloat, noisy retrieval, and key experience that never turns into executable capability.

    2. The Four-Layer Structure with a Plugin Layer

    Adding a memory-processing layer on top of the three layers creates a four-layer chain:

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

    The key point is not the introduction of a specific plugin. It is binding the plugin output to the core documents: clustering results are written into long-term memory, distillation results enter a skill candidate pool, and deep understanding handles deduplication, merging, and judging reuse value.

    3. The Dual Loop of Memory and Skills

    • Memory loop: new conversations continuously add clustering and distillation results, keeping long-term memory up to date.
    • Skill loop: distillation results that are repeatedly validated are promoted into skills, and skill invocation produces new execution traces.

    The goal is to remember less but remember it well: less redundant raw text, and more reusable conclusions and executable steps.

    3. Core Documents: Execution Constraints That Matter More Than Skills

    Core documents determine whether the agent follows the expected path. Without constraints, the model fills the gaps with content that merely looks reasonable. With clear constraints, both the execution path and the reporting format stabilize.

    1. The Primary Document: The Central Hub

    The primary document ties the other documents together. It should explicitly state the execution workflow and rules, the skill orchestration mechanism, the reporting format, the memory system architecture, and the fault-tolerance and fallback mechanisms. It acts as the constitution of the system: all other documents take effect only within this framework.

    Example structure:

    1. # Execution Control
    2. - Workflow: requirement confirmation → planning → execution → validation → reporting
    3. - Skill orchestration: basic layer first, then general layer, then specialized layer when needed
    4. - Reporting format: conclusion / evidence / risks / next steps
    5. - Fault tolerance: switch approach after two failures, escalate to a human after three

    2. The Skill Pyramid: Dynamic Tiering Instead of Static Labels

    Skills are tiered by invocation frequency and value, forming a pyramid: the bottom layer is high-frequency and stable, while the top layer is low-frequency and experimental. The emphasis is on dynamic analysis: tiering comes from real invocation data and project reuse, not from a one-time classification.

    • Basic layer (about 55%): file operations, terminal commands, and web access, used frequently day to day.
    • General layer (about 30%): debugging, planning, and code review, commonly reused across projects.
    • Specialized layer (about 15%): domain-specific tasks, invoked only in the corresponding scenarios.
    • Experimental layer (about 5%): draft skills and new attempts, where failure is allowed.

    Example promotion mechanism:

    1. experimental layer → specialized layer: used 3 times within 30 days and validated as effective
    2. specialized layer → general layer: reused across 3 different projects and generalizable

    3. The Yin-Yang Table: Turning Corrections into Queryable Decision Boundaries

    Drawing on the idea of the unity of opposites, you can build a continuously growing boundary table. The user provides P (what they want), the agent reasons about non-P (what they do not want and where the boundaries are), and after recording it, the next request can look it up directly. The Yin-Yang table is not a philosophical doctrine; it is a versioned record of decision boundaries.

    The key is that entries hold in pairs and can be queried in reverse. If the user prefers non-P in a given case, the original P automatically becomes the new non-P. No new entry is needed, only a reverse lookup. This way, every correction settles into a rule, and the probability of repeating the same mistake drops significantly.

    4. Rollout Order and Acceptance Metrics

    The recommended sequence has four steps: write the primary document first, then connect the memory-processing layer, then establish skill tiering and the promotion mechanism, and finally introduce the Yin-Yang table to converge boundaries. Acceptance can be measured by three metrics: the repeated-error rate, the skill hit rate, and the average number of correction rounds. If all three keep declining, the architecture change is genuinely taking effect.