Agent Execution Architecture Evolution: Memory and Documentation as Dual Drivers
This article explains how to evolve an AI agent execution architecture from a fragmented, tool-dependent setup into a self-governed system driven by a four-layer memory model and a core documentation layer. It covers the structural problems of mounting agents under external tools, the design of memory clustering and skill distillation with metadata-based governance, the role of core documents as the behavioral baseline, a dynamic skill pyramid with promotion and retirement rules, and a positive/negative boundary table for encoding implicit preferences. Practical rollout order, common pitfalls, and measurement metrics are included.
1. Background: Why Agents Become Fragmented Over Time
Many teams initially build an agent by attaching it to a general-purpose coding tool or workflow engine, where it is invoked as a subordinate component. This approach starts fast, but it soon exposes three structural problems.
First, misplaced control. The main flow is owned by the external tool, so the agent’s reasoning and execution are broken into a series of passive responses, making it hard to maintain a continuous task context.
Second, fragmented memory. Conversation history, execution logs, and lessons learned are scattered across different places and never consolidate into reusable capability.
Third, missing constraints. Without explicit rule documents, the model tends to improvise, producing output that looks reasonable but is not executable.
The core direction of the architecture evolution is therefore to take execution sovereignty back into the agent itself: use the memory system to decide “what to remember,” use core documents to decide “how to act,” and use skill layering to decide “what it can do.”
2. A Four-Layer Memory System: From Conversation Clustering to Skill Distillation
Native memory usually has only three layers: short-term conversation cache, mid-term summaries, and long-term vector retrieval. The problem with this structure is that it “remembers a lot but holds little”: retrieval hit rates are high, but executability is low.
After introducing a localized memory plugin, the system can be extended to four layers and connected to the core documents:
Layer 1: Conversation clustering —— merge long sessions by intent, remove repetitive noiseLayer 2: Execution distillation —— extract tool calls, failure causes, repair pathsLayer 3: Deep understanding (LLM) —— generate structured conclusions: goals, constraints, counterexamplesLayer 4: Skills —— solidify stable conclusions into callable skills
The key design is the feedback loop between Layer 4 and Layer 1: new conversations produced by skill execution re-enter clustering, forming a dual cycle of “memory -> skill -> memory again.” As a result, the number of long-term memory entries the system holds goes down, while the executable density of each entry goes up, which means “remember less, and remember it well.”
In engineering practice, it is recommended to attach metadata to each memory entry for governance:
{"id": "mem_0421","layer": "execution_distill","intent": "Troubleshoot build script failure","constraints": ["Do not modify production configuration", "Keep a rollback point"],"confidence": 0.82,"reuse_count": 3,"ttl_days": 90}
Here, reuse_count and ttl_days are the basis for the eviction mechanism, preventing the memory store from growing without limit.
3. Core Documents: The “Constitution Layer” of the Execution Architecture
In terms of execution hierarchy, core documents matter as much as skills and scripts. Skills determine the upper bound of capability; documents determine the lower bound of behavior.
3.1 Main Entry Document
As the primary document, it acts as the hub and needs to define: the execution flow and phase breakdown, the skill orchestration mechanism, the reporting format, the memory system architecture, and fault tolerance and rollback strategies. A recommended structure:
# Execution Principles- Task decomposition: goal -> subtasks -> acceptance criteria- Orchestration order: read-only investigation first, then write changes, then verify- Reporting format: conclusion / evidence / risks / next steps- Fault tolerance: switch approach and escalate after two consecutive failures
3.2 Skill Pyramid Document
Skills are layered by invocation frequency and value, forming a dynamic pyramid rather than static labels:
- Base layer (~55%): file operations, terminal commands, web access; high frequency and stable
- General layer (~30%): debugging and localization, planning, code review
- Specialized layer (~15%): data modeling, creative design, code hosting platform operations
- Experimental layer (~5%): draft skills, failure allowed
Example promotion mechanism:
Experimental -> Specialized: invoked >= 3 times within 30 days with positive human feedbackSpecialized -> General: reused across 3 different projects without modificationAny layer -> Retirement: zero invocations for 60 consecutive days, or failure rate > 40%
The value of the pyramid view is that it drives resource investment by the “actual current usage distribution” rather than by subjective importance ranking.
3.3 Yin-Yang Boundary Document
Drawing on Daoist thinking and the complementary relationship in set theory, this document builds a “positive case - negative case” reference table for the agent:
User provides P (what is wanted)-> Agent reasons about non-P (what is not wanted, where the boundary is)-> Record as an entry-> Next similar request looks up the table directly, aligned in seconds
Example entry format:
- P: Generate an API descriptionnon-P: Do not fabricate parameters, do not document unimplemented capabilities, do not add billing speculationboundary: Only describe interfaces that exist in the code
This table is a continuously growing record of decision boundaries. It expands as the project evolves and essentially turns “implicit preferences” into “explicit, queryable constraints,” greatly reducing repeated communication costs.
4. Implementation Advice and Common Pitfalls
The recommended rollout order is: write the main entry document first, then migrate the memory layering, and finally do skill layering and fill in the yin-yang table. Reversing this order easily leads to “many skills but uncontrolled behavior.”
There are three common pitfalls. First, treating memory as a log that only grows and never shrinks, which amplifies retrieval noise. Second, writing documents as manifestos without decidable conditions, which the model cannot execute. Third, fixing the skill classification once and never adjusting it, so the pyramid degrades into a static directory.
Four metrics can be used: first-pass task success rate, average number of rework rounds, change in the number of long-term memory entries, and skill invocation concentration. If long-term memory entries decrease while the first-pass success rate rises, the dual cycle is working.
When external capabilities are needed, they can be carried by general cloud capabilities, for example object storage for memory snapshots, message queues to decouple skill invocation, container platforms to host the runtime, and logging services with monitoring and alerting to track failure rates, so that the execution architecture gains observability and recoverability.
