Agent Memory and Core Document Architecture: A Practical Guide

    This article presents a product-agnostic methodology for optimizing general-purpose agent execution architectures. It explains why expanding the context window alone does not improve agent performance, then shows how to combine a four-layer memory system, a core document as the central control hub, a tiered skill pyramid, and a decision boundary table into a dual-loop engineering framework. Readers will find concrete implementation order, structural examples, and metrics for verifying whether memory governance is working.

    1. Background: Why Agents “Forget” and “Wander Off”

    In real engineering practice, many teams notice a counterintuitive pattern: context windows keep growing, but agent performance does not improve proportionally. The cause is usually not the model itself, but two things that were never engineered: the write and recall strategy for memory, and the form in which behavioral constraints are carried. The first determines whether an agent can reuse experience across sessions and projects; the second determines whether it converges toward the intended direction instead of improvising freely.

    This article uses “optimizing a general-purpose agent execution architecture” as its thread and abstracts a methodology that is independent of any specific product: core documents as the central control hub, layered memory as accumulated experience, tiered skills as capability orchestration, and a decision boundary table as the correction loop. These four parts interlock and form a dual-loop system.

    2. Memory System: Consolidating Three Layers into Four

    2.1 Limits of the Native Three-Layer Structure

    The memory built into most agent frameworks falls into three layers: short-term context within a session, historical summaries across sessions, and long-term knowledge entries written to external storage. The problem with this structure is that short-term context is noisy, historical summaries drift semantically, and long-term entries lack any basis for deciding when they should be recalled. The result: a lot is remembered, it is scattered, and recall is inaccurate.

    2.2 The Fourth Layer: Stitching Plugin Capability to Core Documents

    Introducing a local memory plugin (a common industry approach is to expose memory read and write capability through a local service) is only the first step. What actually produces results is binding it to the core documents to form an explicit pipeline:

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

    The responsibility of each stage must be written into the documents rather than left to the model’s improvisation:

    • Clustering layer: split by task intent rather than by time, so unrelated topics do not get merged into one memory.
    • Distillation layer: keep only “decisions and outcomes”; discard small talk and intermediate state logs.
    • Understanding layer: the model outputs structured entries (trigger conditions, applicable scenarios, lessons from failures).
    • Skill layer: only when the same pattern repeats three or more times is it allowed to be solidified into a skill.

    2.3 The Dual Loop and “Remember Less, Remember Solidly”

    The memory loop accumulates inward; the skill loop reuses outward; the two exchange information through the core documents. The key to controlling recall volume is to give each memory entry searchable fields and expiry conditions instead of appending endlessly. A schematic structure in engineering terms:

    1. {
    2. "trigger": "deployment script fails and logs contain a permission error",
    3. "lesson": "verify the execution account's permissions first, then retry",
    4. "scope": "Project A/CI pipeline",
    5. "expires": "2026-01-01"
    6. }

    3. Core Documents: The First Priority of the Execution Architecture

    An often underestimated conclusion: writing good core documents is worth more than adding new skills. When constraints are missing, more capability means wandering further off course.

    3.1 The Master Control Document (AGENTS-type Files)

    It carries the hub role and should state at least six things: the execution flow and phase breakdown, hard rules and prohibitions, skill orchestration and invocation order, reporting format and minimum information set, the memory system’s layers and write timing, and fault tolerance and fallback strategy. Keep it short enough to read in one sitting, and link details out to sub-documents.

    3.2 The Skill Pyramid Document

    Skills are tiered by “invocation frequency × value” rather than by technology stack:

    • Foundation layer (about 55%): file read/write, terminal commands, web access — high frequency in daily work and stable in behavior.
    • General layer (about 30%): debugging and root-cause analysis, planning, code review — reusable across projects.
    • Specialized layer (about 15%): data modeling, creative design, code hosting platform operations — enabled for specific scenarios.
    • Experimental layer (about 5%): draft skills and new attempts, where failure is allowed.

    The key is that this is a dynamic view: tiering is based on real invocation statistics from the last 30 days, not a one-time label. Example promotion thresholds: experimental → specialized requires 3 hits within 30 days plus a human judgment that it is usable; specialized → general requires validation in 3 different projects and the ability to be abstracted. Demotion needs rules too, otherwise the pyramid inflates in reverse.

    3.3 The Yin-Yang Decision Boundary Table

    Borrowing the idea of yin-yang and complementary sets, record user preferences as paired boundaries: the user gives P (what they want), the agent derives not-P (what they do not want, where the boundary lies), and once recorded, the next time it is a direct table lookup hit. Three points matter:

    1. P and not-P are semantic opposites of each other, with no right or wrong side — just two sides of the same dimension.
    2. If a user preference falls on the not-P side, the original P automatically becomes the new not-P, and reverse lookup is used; no new entry is needed, which avoids table bloat.
    3. After each correction, the agent summarizes and writes back on its own, forming a continuously growing but auditable decision boundary.

    Schematic structure:

    1. - dimension: output detail
    2. P: provide complete, runnable code
    3. notP: omit key implementation and give only pseudocode
    4. - dimension: change strategy
    5. P: small commits, each step revertible
    6. notP: one large-scale refactor all at once

    4. Rollout Order and Metrics

    A four-step progression is recommended: first write the master control document and freeze the rules, then connect the memory plugin to complete the four-layer pipeline, then build the skill pyramid with promotion and demotion statistics, and finally introduce the yin-yang table to close the correction loop. Metrics can include: first-attempt success rate for cross-session tasks, number of repeated mistakes, skill hit rate, and average context length. If context gets shorter while success rate rises, memory governance is working.

    If cloud hosting is needed, generic category capabilities can be used: object storage to hold documents and memory snapshots, a message queue to decouple memory writes, a container platform to run the local memory service, and logging plus monitoring and alerting to track recall hit rate and failure patterns. The overall approach is independent of any specific vendor; the point is to turn “constraint — memory — skill — correction” into a verifiable engineering loop.