Agent Memory and Skill Governance: A Practical Architecture for Reliable AI Agent Execution
This article presents a general architecture for improving AI agent execution by focusing on memory consolidation, explicit constraints, and layered skill governance rather than simply adding more tools. It describes a four-stage memory pipeline, core execution documents, a skill pyramid, a preference-boundary table, and a runtime workflow that connects documents, memory, and skills into a closed-loop execution system.
In intelligent coding and task orchestration scenarios, many teams start by using a main control agent to call several capability components. Over time, they often discover that long-term effectiveness is not mainly determined by connecting more tools. Instead, it depends on how memory is accumulated, how constraints are written, and how skills are governed in layers. This article abstracts these practices into a general framework for optimizing AI agent execution architecture. It is not tied to a specific product. The focus is on using documents and mechanisms to elevate an agent from an auxiliary role to an entity that can independently complete a closed-loop execution process.
1. From Main-Agent/Sub-Agent Invocation to Execution-Centered Design
A common starting point is to use a task orchestration layer as the main controller and treat another agent capability as a callable module. In the short term, this approach has low installation cost and can quickly add capabilities such as retrieval, scripting, or browser access. However, medium-term problems tend to emerge: the main control layer and the execution layer do not share a unified contract for what should be remembered, what should be done, and how to roll back after errors. As a result, memory becomes fragmented, skills are repeatedly registered, and reporting formats become inconsistent.
A more reliable evolution is to make the execution architecture itself a system that can be constrained, observed, and upgraded. The orchestration layer can be retained, but the core should shift toward a single rule set for the entire task lifecycle: intent understanding, skill selection, process recording, and result reporting. On the cloud side, object storage can be used to store long documents, message queues can support asynchronous tasks, and logging, monitoring, and alerting services can track failures. These are general infrastructure components and do not change the principle that documents serve as policy.
2. Memory Systems: From Multi-Layer Storage to a Dual Loop of “Remember Less, Remember Well”
Native memory is often layered by time or session, such as short-term dialogue, mid-term session summaries, and long-term profiles. Simply adding more layers is not enough. The key is the conversion path between layers. A practical four-stage pipeline is as follows:
Cluster conversation records: Cluster by topic, project, or error type rather than storing entire raw transcripts. Clustering reduces noise and prevents context from being overwhelmed by casual conversation.
Extract execution processes: Convert “which commands were run, which files were changed, and what key decisions were made” into structured events rather than storing another copy of the logs. The extraction should be reusable: for similar tasks next time, the agent should be able to directly match a step skeleton.
Deep understanding: Use a large model to abstract causality and preferences from the clustered results, producing guidance such as “under which constraints should which strategy be selected,” rather than generating another piece of prose. The output of this layer should be searchable and editable by humans.
Skill consolidation: Turn repeatedly occurring and stably effective strategies into callable skills, including input/output contracts, failure fallback, and applicability boundaries. A skill is not a copy of memory; it is an executable form of memory after compression.
This forms a dual loop. The memory loop is responsible for “remembering less”: it retains only clustered facts and boundaries. The skill loop is responsible for “remembering well”: it solidifies high-frequency correct paths into orchestrable units. The two loops validate each other: when a skill fails, the counterexample should be written back into memory; when a new preference appears in memory, it should trigger a skill version upgrade or downgrade.
Three implementation points are important. First, writing should have a threshold: raw conversations that have not been clustered or extracted should not enter the long-term layer by default. Second, recall should have a budget: each time, only retrieve a limited number of clusters relevant to the current task, avoiding the practice of stuffing all memory into the prompt. Third, forgetting should have rules: expired experiments and details already covered by skills should be downweighted or archived to prevent memory expansion.
3. Core Documents: Execution Contracts More Important Than a Skill List
Skills and scripts solve “whether the agent knows how to do something.” Core documents solve “whether it should do it, to what standard, and how to report failure.” From an architecture perspective, writing clear constraints is often more important than rushing to add skills. When constraints are clear, the model converges toward the goal. When constraints are vague, it diverges beyond the boundaries.
It is recommended to maintain at least three types of mutually referenced documents, connected by a hub document.
3.1 Hub Document: Agent General Principles
This is not a promotional page. It is a contract loaded with priority at runtime. It should specify:
- Execution flow: The order of intent clarification, planning, execution, verification, and reporting, as well as which steps can be skipped.
- Skill orchestration: How to select skills by task type, whether parallel execution is allowed, and which source takes precedence in case of conflict.
- Reporting format: Required fields for success, partial success, and failure, avoiding the situation where work appears complete but cannot be accepted.
- Memory architecture: Write conditions for each layer, recall strategy, and synchronization with skills.
- Fault tolerance: Fallback and confirmation rules for timeouts, tool failures, and mid-task requirement changes.
The hub document should explicitly declare its references to other documents, for example: “For skill layering, see the Skill Pyramid document; for decision boundaries, see the P / not-P Boundary Table.” This prevents multiple documents from contradicting each other.
3.2 Skill Pyramid Document
Skills should be layered by invocation frequency and transferable value, using a dynamic perspective rather than one-time labels:
- Foundation layer (more than about half of invocations): Capabilities used almost every day, such as file operations, terminal commands, and read-only web access. These require stable interfaces and reversible side effects.
- General layer (about 30%): Cross-project reusable capabilities such as troubleshooting, planning, and code review. These emphasize checklists and output templates.
- Specialized layer (a little more than 10%): Capabilities used only in a specific business or technical domain. Deeper domain assumptions are allowed, but prerequisites must be clearly stated.
- Experimental layer (about 5%): New skills and drafts. These are isolated by default and do not enter the production main path.
The upgrade mechanism should be auditable. For example, to move from the experimental layer to the specialized layer, a skill must be used multiple times in real scenarios within an agreed period and confirmed effective by its owner. To move from the specialized layer to the general layer, it must have been used in multiple different projects and have project-specific assumptions removed. Downgrading is equally important: skills that fail continuously or conflict with the P / not-P Boundary Table should be returned to the experimental layer or taken offline. The pyramid is an analytical perspective; the ratios can be adjusted according to team workload, but the principle of “stability at the bottom, experimentation at the top” should be maintained.
3.3 P / not-P Boundary Table
This table records what the user expresses as “what is wanted” (denoted P) and what the model should proactively infer as “what is not wanted / boundaries” (denoted not-P). This is not a philosophical label, but a continuously growing decision table:
- Paired validity: P and not-P are semantically opposite, with no absolute positive or negative. What is recorded is the current preference, not an eternal truth.
- Reversible query: If the user explicitly prefers the previous not-P in a certain case, the corresponding P becomes the new not-P. Usually, no new entry is needed; a reverse query is sufficient.
- Automatic correction intake: Every manual correction should be summarized as a boundary entry and retrieved at the start of the next task, reducing repeated explanations.
Entries should be short, searchable, and include context such as project, language style, and safety red lines. For example, “provide the conclusion first, then the steps” and “do not pile up background before reaching the conclusion” form a pair. Mathematically, this can be viewed as a complementary relationship over a set: if the currently effective preference set is A, execution must avoid falling into its complement; when the user flips a preference, the element moves from A to the complement. In engineering practice, a simple key-value store or table is sufficient; a complex system is not required.
4. Connecting Documents, Memory, and Skills in One Execution Chain
The recommended runtime order is: load the hub document → retrieve the P / not-P boundary table and relevant memory clusters by task → select skills according to the pyramid → execute and write process events → report → decide whether to cluster and whether to upgrade skills. If any step lacks documentation, do not replace it with temporary verbal conventions; otherwise, the architecture will quickly degrade back to “the main controller calls whatever it wants, and components record whatever they want.”
Validation can use very simple criteria: whether the second similar task requires significantly fewer questions and makes fewer mistakes; whether skill invocations concentrate on the foundation and general layers; whether the experimental layer remains isolated; and whether corrections automatically take effect in the next task. If all four improve simultaneously, it shows that “remember less, remember well” is not a slogan, but the result of memory compression and skill solidification working together.
5. Common Pitfalls and Countermeasures During Implementation
- Adding memory plugins without conversion paths: The number of layers increases, and so does noise. The countermeasure is to enforce clustering and extraction, and prohibit long-term retention of raw text.
- Unlimited skill growth: Skills have different names but overlapping behavior. The countermeasure is to use pyramid quotas and upgrade thresholds, and merge duplicate skills.
- Documents written as vague values: The model cannot execute them. The countermeasure is to make processes, formats, and failure branches all checkable.
- P / not-P table becoming static dogma: After user preferences change, the old P is still retrieved. The countermeasure is to support flipping and expiration, and archive expired items.
In enterprise environments, core documents can be placed in a version repository, with changes going through review; process events can be sent to logging services; large files and knowledge bases can be stored in object storage. These are general engineering practices. The goal is to make the agent’s constraints and memory auditable, rather than relying on temporary intelligence from a single conversation.
In summary, the usefulness of an AI agent ultimately depends on whether the execution contract is clear, whether memory is compressed into searchable boundaries and events, and whether skills are layered by frequency and value with upgrade and downgrade paths. After clarifying the main-agent/sub-agent relationship, optimization should continue to focus on three things: remember less, remember well, and deviate less. This way, even if the underlying model or tools are replaced, the team can still preserve the same governance method.
