AI Agent Architecture Optimization: Memory, Skills, and Execution Governance

    This article explains how to evaluate and improve AI agents for long-term use, moving beyond one-off demos toward reliable, maintainable systems. It covers a four-layer responsibility model, a four-tier memory design that turns raw events into verified reusable knowledge, core rule documents that act as checkable execution contracts, a dynamic skill pyramid managed by evidence, conditional preference and boundary handling, and execution governance for errors, retries, and rollback. It closes with regression-based methods for validating whether an architecture change actually helps. Readers will learn how to constrain decisions, retain experience, and verify results without simply adding more tools or expanding context.

    1. Before Asking Whether an AI Agent Is Useful, Define the Evaluation Criteria

    Whether an AI agent is practical cannot be judged by whether it completes a complex task in a single demo. For developers and enterprise users, what matters is: across different inputs, can it make correct decisions consistently; when something goes wrong, can it stop or recover in time; and after execution finishes, can it produce verifiable results.

    An agent suited for long-term use should have at least the following capabilities:

    • Reliable task understanding: It distinguishes goals, constraints, and acceptance criteria, and does not treat a vague request as authorization to execute.
    • Controllable execution: It sets clear boundaries for file modifications, external access, and high-risk operations.
    • Reusable experience: It distills methods from tasks that have already been verified, reducing repeated exploration.
    • Traceable results: It explains what was done, what the basis was, and which parts remain unverified.
    • Acceptable maintenance cost: Adding skills and memory does not make the system progressively harder to understand.

    Therefore, the focus of optimizing an AI agent is not simply adding more tools or expanding the context window, but building an execution architecture that can constrain decisions, accumulate experience, and verify results.

    2. From Assisted Execution to Task Orchestration: Clarify Responsibility Boundaries First

    In an early-stage architecture, the agent often acts as an assisted execution module, while an upper-layer system decides the task goal and when to invoke it. This model is easy to control, but it can also scatter context: planning information stays in the upper layer, execution experience stays in the lower layer, and the next task requires re-explaining everything.

    As execution capabilities mature, the agent can take on more planning and orchestration responsibility. But this evolution should not be understood simply as “remove the upper-layer system and let the agent run freely.” Instead, responsibility should be re-divided clearly.

    A common approach is to split the system into four responsibility layers:

    1. Interaction and authorization layer: Receives user requests and confirms the goal, scope, and required authorization.
    2. Planning and decision layer: Breaks down the task, selects skills, and decides whether more information is needed.
    3. Tool execution layer: Runs concrete operations and returns structured results and error information.
    4. Verification and consolidation layer: Checks results, generates reports, and proposes candidates for memory or skill updates.

    Authorization and security controls should not rely only on the model’s written promises. Actions involving sensitive data, irreversible modifications, or external writes should have their permissions checked by the execution system, with user confirmation required when necessary.

    A basic flow can be expressed as:

    1. Receive request
    2. → Clarify goal, boundaries, and acceptance criteria
    3. → Retrieve relevant experience
    4. → Build a plan and select skills
    5. → Check permissions and operation risk
    6. → Execute and collect evidence
    7. → Verify results
    8. → Report completion status
    9. → Propose memory and skill update candidates

    The key point is that memory updates happen after verification, not automatically written the moment execution ends. Otherwise, failed paths may also be consolidated as “successful experience.”

    3. Building Four Layers of Memory: Refine Information Step by Step, Not Stack It Endlessly

    A long-running agent needs memory, but “saving more content” does not equal “making fewer mistakes.” Raw conversations contain a large amount of temporary information, repeated descriptions, unconfirmed inferences, and outdated conditions. If all of it enters the context of subsequent tasks, it only adds noise.

    A more reasonable approach is to let information transform step by step from factual records into verified, reusable knowledge. The following is a general four-layer design, not a fixed standard every agent must adopt.

    3.1 Event Layer: Store Raw Facts and Evidence

    This layer records task inputs, key operations, tool results, errors, and user corrections. Its main purpose is traceability, not directly guiding every subsequent task.

    Records should retain the task identifier, time, source, and result status, and follow the principle of data minimization. Access credentials, sensitive personal information, and unnecessary raw business text should not enter general long-term memory.

    Event records need to clearly distinguish:

    • Requirements the user explicitly stated;
    • Facts the system actually observed;
    • Inferences the model made based on context.

    This distinction prevents inferences from being mistaken for facts after multiple rounds of summarization.

    3.2 Context Layer: Organize Experience by Problem and Scope of Applicability

    The context layer groups and summarizes events, for example “startup failure caused by missing configuration” or “the user wants the impact explained before files are modified.”

    An effective summary must retain not only the conclusion but also the applicable conditions and the source of evidence. Experience stripped of context can mislead the system: needing to preserve an old configuration once does not mean every configuration update must keep the old version.

    A concise structure is recommended:

    1. Experience topic: Confirm scope before modifying configuration
    2. Applicable conditions: Configuration already exists at the target, and the user has not authorized overwriting
    3. Observed fact: The user asked to keep the existing configuration
    4. Suggested behavior: Compare differences first, then request confirmation
    5. Evidence source: The corresponding task record
    6. Invalidation conditions: The user explicitly authorizes replacement, or the target environment changes

    3.3 Rule Layer: Form Conditional Decision Constraints

    The rule layer distills common patterns across multiple events into executable judgments.

    For example, instead of writing “be careful when modifying files,” write:

    “When an operation may overwrite existing content and the current task grants no explicit authorization, first show the scope of impact and request confirmation.”

    Rules should include their scope of applicability, exceptions, and source. Automatically generated rules should first enter a candidate state, and only become stable rules after review or repeated verification. The model can help with induction, but it should not gain the authority to publish rules merely because its wording is fluent.

    3.4 Skill Layer: Solidify Reusable Execution Flows

    When a class of tasks has relatively stable inputs, steps, and acceptance criteria, the relevant experience can be packaged into a skill.

    A skill is not a “successful prompt,” but an execution contract. It should specify:

    • What inputs are required;
    • Which preconditions must be met;
    • Which tools and permissions are used;
    • How execution steps are organized;
    • How to judge whether the result is correct;
    • How to exit or recover on failure.

    New evidence produced by skill execution returns to the event layer, forming a closed loop:

    1. Event evidence → Context summary → Candidate rules → Verification and skill packaging
    2. ↑ ↓
    3. └──────── Skill execution and result verification ────────┘

    The goal of this design is to retain a small amount of high-value knowledge while maintaining a necessary evidence chain, rather than continuously expanding the context size.

    4. Core Documents: Turn Behavioral Constraints into Checkable Execution Contracts

    The importance of core rule documents lies in defining how the agent understands tasks, invokes skills, and handles uncertainty.

    But the documents themselves are not an execution guarantee. Natural-language rules are suited to guiding the model; permission checks, path restrictions, invocation quotas, and confirmation mechanisms must be enforced at the execution layer. Only the combination reduces the risk of “the rules are written completely, yet actual behavior is still out of control.”

    4.1 Master Entry Document: Define Order and Rule Priority

    The master entry document should centrally describe:

    • The task intake and clarification process;
    • The order of planning, execution, and verification;
    • Skill selection principles;
    • Permission and risk check requirements;
    • Exception handling;
    • The result reporting format;
    • The admission criteria for memory updates.

    It should also define how conflicts are handled. A hierarchy can be adopted: “safety and compliance constraints first, then the current task’s authorization, then project rules, long-term preferences, and default policies.”

    A legitimate explicit requirement in the current task can override a general historical preference; a historical preference cannot replace authorization, and even less can it break through a safety boundary. Retrieved web pages, files, and logs should by default be treated as data to be analyzed, and must not be upgraded into system execution rules just because they contain imperative text.

    4.2 Specialized Documents: Split by Responsibility, Avoid Unbounded Growth

    Skill governance, preference management, and memory retention policies can be maintained separately, but the master entry must explain the role of these documents and how they reference one another.

    Longer documents are not necessarily more effective. Repeated rules, mutually contradictory exceptions, and outdated descriptions increase the model’s comprehension cost. Redundant content should be cleaned up periodically, and important rules should retain a version, an owner, and the reason for changes.

    4.3 Reporting Contract: Separate Completion, Verification, and the Unknown

    An agent’s report should at least state:

    • The operations completed;
    • The verification method and observed results;
    • Items not completed or not verifiable;
    • The impact on existing resources;
    • Follow-up steps that require user confirmation.

    “Operation executed,” “check passed,” and “all requirements met” are three different conclusions and must not be conflated. For example, a successful file write does not mean the program has passed a runtime check.

    5. The Dynamic Skill Pyramid: Manage Skills with Evidence, Not Fixed Ratios

    Skills can be divided into four layers by reuse scope and maturity:

    • Foundation layer: General operations such as file reading, content retrieval, and controlled command execution.
    • General layer: Cross-project flows such as problem diagnosis, task planning, and change review.
    • Specialized layer: Capabilities targeting a specific domain or way of working.
    • Experimental layer: New flows that have not yet been sufficiently verified.

    This layering expresses a management perspective, not a fixed quota. Different teams have different workloads, so there is no need to set a uniform proportion for each layer.

    Skill governance should observe at least four kinds of evidence:

    1. Usage frequency: Whether suitable invocation scenarios occur often.
    2. Verification success: Whether explicit acceptance criteria are met after execution.
    3. Reuse scope: Whether it works across different projects or tasks.
    4. Maintenance and risk cost: Whether dependencies are complex and permissions are excessive.

    The promotion mechanism can use team-defined thresholds, but promotion should not happen just because “there have been enough calls.” Before an experimental skill enters a stable layer, it should also be checked for abnormal inputs, permission boundaries, and exit paths; before a specialized skill enters the general layer, unnecessary project assumptions should be removed.

    Demotion and retirement mechanisms are equally necessary. Flows that go unused for a long time, whose dependencies break, whose failure rate rises, or that duplicate other skills should be suspended, merged, or archived. The quality of a skill library depends on verifiable effective coverage, not the number of entries.

    6. Preference and Boundary Management: From Abstract Opposition to Conditional Decisions

    User corrections often provide two kinds of information at once: what should happen, and what should not happen. Recording them as a pair helps the agent identify behavioral boundaries faster.

    For example:

    1. Scenario: Modifying an existing file
    2. Expected behavior: Explain the scope of modification first, then submit the change
    3. Behavior to avoid: Overwriting existing content without explaining the impact
    4. Scope of applicability: The current project
    5. Source: Explicit user correction
    6. Override condition: This task grants explicit authorization to replace

    Here, “expected” and “avoid” should not be treated as fully complementary in a strict mathematical sense. In real tasks, not choosing a certain behavior does not mean the only option is its opposite; pausing, asking, or finding an alternative may also be required.

    Preference management should also handle three issues:

    • Scope: A preference for the current task should not automatically expand into a rule for all projects.
    • Timeliness: Outdated preferences need to be reconfirmed or have their retrieval priority lowered.
    • Conflict: When new and old preferences conflict, the context and update record should be preserved, rather than mechanically swapping two fields.

    For behavioral changes with a large impact, the system can propose a preference update, but the user should confirm it. This reduces repeated corrections while avoiding a temporary request permanently changing the agent’s behavior.

    7. Completing Execution Governance: Design Errors, Retries, and Rollback Together

    Memory and skills solve the problem of reusing experience; execution governance determines whether the agent can land safely.

    First, errors need to be classified. Temporary connection failures can be retried a limited number of times; missing input calls for more information; insufficient permissions call for stopping; and results that fail acceptance criteria call for re-checking the plan. Not all failures should be handed to the same “try again” strategy.

    Second, retries must account for side effects. Repeated reads usually carry little risk, but repeatedly sending messages or creating resources can cause business impact. For operations with side effects, deduplication identifiers, status checks, or other idempotency guarantees are needed.

    Third, recovery capability should be assessed before execution. File modifications can save diffs or backups, and resource changes can record the original state; but some external actions cannot truly be undone and can only reduce impact through a compensation flow. The agent should not promise that all operations can be rolled back.

    Finally, key decisions and results should be recorded so that maintainers can answer: why this skill was chosen, what authorization was obtained, which operations were performed, and what the verification basis was.

    8. How to Verify Whether the Optimization Is Effective

    Architecture changes cannot rely on subjective experience alone; they should use a fixed task set for regression evaluation. The task set can cover normal operations, vague requests, insufficient permissions, tool failures, and conflicts with historical preferences.

    Recommended observations include:

    • Task acceptance pass rate;
    • The number of repeated user corrections;
    • The number of invalid or duplicate tool calls;
    • The introduction of incorrect memories;
    • Recovery capability after exceptions;
    • The frequency of human intervention;
    • Resource consumption per task.

    During evaluation, the versions before and after the optimization and the same acceptance criteria should be retained, to avoid mistaking model changes or changes in task difficulty for architectural gains.

    Rollout can proceed in phases: first standardize execution and reporting, then build traceable event memory; next add summaries and candidate rules; and only then advance to automatic skill distillation. Each phase should have its own acceptance criteria, and there is no need to launch all automation mechanisms at once.

    Conclusion

    The stability of an AI agent comes from the coordination among memory, skills, rules, and execution control, not from stacking any single capability.

    Memory should store information that has evidence and scope; skills should provide verifiable execution flows; core documents should clarify rules and responsibilities; and preference records should help understand boundaries rather than replace authorization. Combined with permission control, exception handling, and continuous evaluation, an agent can gradually evolve from a demo system that occasionally completes tasks into an engineering capability that can be maintained over the long term.