AI Agent Memory and Core Document Architecture: A Practical Guide

    This guide explains how to move an AI agent from a host-dependent, plugin-based setup to an agent-centric execution architecture. It covers a four-layer memory system, core constraint documents such as AGENTS.md, a dynamic skill pyramid, and a decision boundary table that turns corrections into reusable constraints. Readers will learn a practical rollout order, common anti-patterns, and how to judge whether the architecture is healthy. The cloud infrastructure section stays vendor-neutral, so teams can map it to their own cloud capabilities.

    1. Background: From External Plugin Calls to an Autonomous Execution Architecture

    Many teams start by integrating an agent as an add-on component of an existing platform: the platform owns the main workflow, and the agent is only invoked when needed. This approach is quick to set up, but it soon exposes two structural problems.

    First, capability boundaries are constrained by the host. Once the host platform changes its scheduling logic, context length, or plugin protocol, the agent’s behavior changes passively, and the team cannot optimize at the architecture level.

    Second, there are no execution assets that can be accumulated. All experience is scattered across chat logs. Switch to a new session or a different machine, and behavior quality immediately regresses.

    Therefore, when the execution architecture itself becomes the bottleneck, shifting the focus from “host plus plugins” to “agent as the core” is a reasonable choice. This article does not review any specific tool. Instead, it presents a general set of agent architecture engineering practices: memory layering, core constraint documents, tiered skill governance, and decision boundary accumulation.

    2. Memory System: Integrating Three Layers into Four

    2.1 The Number of Layers Is Not the Point; the Closed Loop Is

    Native memory can usually be abstracted into three layers: short-term session context, mid-term summaries, and long-term vector retrieval. The problem is that it stores a lot but uses little: retrieved fragments are isolated from one another, and there is no step that distills execution processes into reusable methodology.

    Adding a local memory management plugin introduces a “methodology layer,” forming a four-layer structure:

    1. L1 Conversation clustering — group raw interactions by task intent to reduce noise
    2. L2 Execution distillation — extract what was done and why it succeeded or failed
    3. L3 Deep understanding (LLM) — summarize preferences, constraints, and transferable conclusions
    4. L4 Skills — solidify outputs into callable skills and scripts

    What matters is not the plugin itself, but connecting this layer to the core documents: L3 outputs must be written back into the constraint documents, and L4 outputs must be registered in the skill inventory. Otherwise, memory is just a log and will not change the next behavior.

    2.2 The Dual Loop Between Memory and Skills

    • Outer loop (memory to skills): recurring execution patterns are promoted to skills, reducing token and reasoning costs.
    • Inner loop (skills to memory): skill invocation results and correction records flow back, triggering skill revision or retirement.

    Together, the two loops support one goal: remember less, but remember firmly. “Less” means the resident context keeps only high-value constraints. “Firmly” means key conclusions are solidified into documents and skills, rather than depending on session luck.

    3. Core Documents: Constraint Quality Determines Execution Quality

    From an architecture perspective, writing good constraint documents is often more important than adding new skills. Skills expand the upper limit of capability; documents determine the lower limit of behavior. Maintain at least three documents.

    3.1 AGENTS.md: The Central Hub

    It is the entry point that connects the other documents and should specify the execution workflow and phase breakdown, skill orchestration and invocation priority, reporting format, memory system layer structure, and fault tolerance and fallback mechanisms. Example skeleton:

    1. # Execution rules
    2. 1. Read the constraint documents before touching code
    3. 2. Present the plan and impact scope before changes; execute after confirmation
    4. 3. Output a structured report at the end of each phase
    5. # Skill orchestration
    6. Retrieval order: foundation layer → general layer → specialized layer → experimental layer
    7. # Fault tolerance
    8. Stop fine-tuning after two failures; switch approaches or request confirmation

    3.2 The Skill Pyramid: A Dynamic View, Not Static Labels

    Skills are tiered by invocation frequency and value, forming a pyramid. The emphasis is on managing them through dynamic analysis rather than assigning labels once.

    • Foundation layer (about 55%): file operations, terminal commands, and web access. Used daily; stability is required.
    • General layer (about 30%): debugging and root-cause analysis, planning, and code review. Reused across projects.
    • Specialized layer (about 15%): data modeling, creative design, and code hosting platform operations. Used in specific scenarios.
    • Experimental layer (about 5%): draft skills; instability is allowed.

    A promotion mechanism keeps the tiers fluid:

    1. Experimental → Specialized: invoked at least 3 times within 30 days and results are accepted
    2. Specialized → General: validated in 3 different projects and generalizable
    3. Any layer → Archived: zero invocations for two consecutive cycles or repeated failures

    3.3 The Decision Boundary Table: Turning Corrections into Constraints

    Inspired by the idea of yin and yang being mutually rooted, build a continuously growing boundary table: the user provides P (what is wanted), the agent reasons about not-P (what is not wanted and where the boundaries are), records it in the table, and looks it up directly next time.

    There are three key points: P and not-P hold as a pair, with semantic opposition but no inherent superiority; if the user prefers not-P on a given occasion, the original P automatically becomes the new not-P, which can be handled through reverse lookup without adding a new entry; every correction is automatically summarized and written back into the table.

    Sample structure:

    1. - id: B012
    2. P: Output complete, runnable code
    3. notP: Provide only pseudocode or fragments
    4. updated: 2026-08-22
    5. reverse_of: null

    4. Rollout Order and Common Anti-Patterns

    Recommended order: first write AGENTS.md to define the workflow and reporting format → then build the skill pyramid and complete one full inventory → then integrate memory layering and write distillation results back into the documents → finally enable the boundary table for continuous correction.

    Common anti-patterns include: writing documents as declarations rather than executable rules; only adding skills and never removing them, which increases retrieval noise; storing memory without using it and lacking a write-back channel; and letting boundary table entries expand indefinitely without consolidation. A simple standard for judging whether the architecture is healthy is whether the problem corrected last time still occurs this time.

    When you need to store memory indexes, skill artifacts, and execution logs, you can use object storage for artifacts, a message queue to decouple asynchronous tasks, a container platform to run execution environments, and logging and monitoring services for observability. These are general cloud product categories, and you can select based on your cloud provider’s capabilities.