Agent Memory and Core Document Architecture: A Practical Guide for Autonomous Execution Systems
This article explains how to evolve an AI agent from a host-dependent add-on into a self-contained execution architecture. It covers a four-layer memory pipeline, three core documents that act as the system's rule layer, a dynamic skill pyramid with promotion and retirement criteria, and a staged rollout strategy for building stable, reproducible, and auditable agent behavior.
1. Where the Problem Starts: From “Pluggable Add-On” to “Autonomous Execution Architecture”
Many teams start by attaching an agent to a general-purpose coding tool, using it as an extension component that the host can invoke. The division of labor is clear: the host tool handles interaction and scheduling, while the agent handles local tasks. The upside is low integration cost and fast validation, but the ceiling is just as obvious — the agent’s behavioral boundary is decided by the host, and memory, skills, and workflows are fragmented, making a closed loop hard to achieve.
Once the execution chain grows longer and tasks move from “single-turn Q&A” to “multi-step delivery,” this supporting role quickly exposes three problems: context loss causes repeated work, lack of constraints causes divergent output, and skill pile-up causes invocation chaos. So the architectural center of gravity inevitably shifts: from “depending on a host” to “building your own execution kernel.” This article covers the three most critical pieces of that migration — the memory system, core documents, and skill layering.
To be clear, this is not a manual for one specific implementation, but a general engineering paradigm. Any in-house agent, open-source execution framework, or enterprise agent platform can apply the same approach.
2. Memory System: Integrating Three Layers into Four
2.1 Capabilities and Gaps of the Native Three Layers
Most agents ship with three layers of memory by default: short-term context within a session, rolling summaries across sessions, and long-term notes written to local files. This solves “what was just said,” but not “how was this kind of task done before.” The gap is that raw conversations are low-structure and high-noise, so direct retrieval often recalls a pile of similar but useless fragments.
2.2 The Fourth Layer: Coupling an External Memory Plugin with Core Documents
After introducing a localized memory extension plugin (a common industry practice, usually exposing retrieval and write capabilities as a local service), the real qualitative change is not “one more storage layer” but connecting it with the core documents to form a four-stage pipeline:
Conversation clustering → Execution distillation → Deep understanding (LLM) → SkillsRaw layer Structured layer Semantic layer Behavior layer
- Clustering layer: split conversations by task intent rather than time, and drop small talk and failed attempts;
- Distillation layer: compress the “process” into “step — decision — result” triples;
- Understanding layer: have the model summarize applicable conditions and failure modes into natural-language entries;
- Skill layer: when a category of entries is hit repeatedly, solidify it into an invocable skill.
2.3 The Dual Loop Between Memory and Skills
This creates a dual loop: memory accumulates experience inward, skills solidify behavior outward; skill execution produces new conversations, and new conversations feed back into memory. There is only one criterion — remember less, but remember it solidly. In practice, set hard constraints: a single memory entry must fit within one screen, must carry applicable conditions, and must be traceable to its source task, with periodic deduplication and expiration cleanup.
3. Core Documents: The “Constitution Layer” of the Execution Architecture
A counterintuitive but important conclusion: at the architecture level, writing good core documents usually takes priority over adding new skills. Skills are “capabilities”; documents are “constraints.” Without constraints, the stronger the capability, the more easily it drifts.
3.1 The Hub Document: Global Linkage
The first document is the master outline, responsible for linking all other documents. It should always contain six sections: execution workflow and hard rules, skill orchestration and invocation priority, reporting format, memory system architecture, fault tolerance and fallback, and change log. It must be the shortest, most stable, and first-loaded document.
# AGENTS Master Outline (illustrative)1. Workflow: understand → plan → execute → self-check → report2. Rules: ask first when unsure; confirm before high-risk operations3. Orchestration: check the skill index first, then decide to create or reuse4. Reporting: conclusion first + changes + verification method + remaining risks5. Fault tolerance: switch paths after two failures, and write it to memory
3.2 The Skill Pyramid Document: A Dynamic View, Not Static Labels
The second document describes skill layering. The key point is that layering is a dynamic analytical view based on invocation frequency and value, not a one-time labeling exercise. A usable baseline ratio is: foundation layer about 55% (file operations, terminal commands, web access), general layer about 30% (debugging and root-cause location, planning, code review), specialized layer about 15% (data training, creative design, code hosting collaboration), experimental layer about 5% (draft and trial skills).
A companion promotion mechanism keeps the pyramid flowing:
- Experimental layer → specialized layer: invoked effectively 3 or more times within 30 days with good retrospective reviews;
- Specialized layer → general layer: reused successfully across 3 different projects, with project-specific parameters already abstracted away;
- Any layer → retirement: zero hits for two consecutive cycles, or already covered by a higher-layer skill.
3.3 The Yin-Yang Table Document: Turning “What Not to Do” into a Queryable Asset
The third document borrows from the Daoist concept of yin and yang and set complementarity: the user provides P (what they want), the agent reasons about non-P (what they do not want, where the boundaries are), records the result in a table, and hits the table directly next time. It is essentially a cache of negative constraints, and it significantly reduces repeated clarification.
| Scenario | P (want) | non-P (do not want) |
|---|---|---|
| Log troubleshooting | Locate the root cause with minimal changes | Do not refactor along the way, do not upgrade dependencies |
| Document generation | Conclusion first, actionable | No vague background, no marketing tone |
4. Evolution Path and Engineering Recommendations
The recommended rollout order is: first write the master outline document and freeze the rules, then connect the memory plugin to complete the four-layer pipeline, and finally do skill layering with promotion and demotion. Change only one thing per iteration, and validate with regression testing against a fixed task set.
If you need to scale, put memory and the skill index in object storage for persistence, use a message queue to decouple asynchronous distillation tasks, run the memory service on a container platform, and connect logging and monitoring with alerting to observe hit rate and failure rate. With the general capabilities of cloud platforms such as Baidu AI Cloud, this architecture can move smoothly from a single machine to team-wide sharing.
The end goal is not to make the agent “know more,” but to let it make stable, reproducible, and auditable decisions under limited memory — that is the real moat of an execution architecture.
