AI Agent Execution Architecture Optimization: Coordinating Memory, Skills, and Constraints

    This article explains how to evaluate and optimize AI agents from the perspective of the execution system rather than isolated responses. It covers a four-layer memory design, the feedback loop between memory and skills, the core rule document as the control plane, dynamic skill layering, preference and boundary management, safeguards against automatic learning becoming an error amplifier, evaluation metrics, and a phased rollout approach.

    1. Judge an Agent by Its Execution System, Not by a Single Response

    In development practice, an agent is often first introduced into an existing system as an auxiliary component. It may retrieve information, perform local operations, or complete a specific type of task. As usage scenarios expand, developers gradually assign it responsibilities such as planning, tool invocation, result checking, and experience reuse.

    The questions being asked also change. At first, the focus is on whether the agent can complete a task. Later, the focus shifts to whether it can complete tasks reliably, whether it respects boundaries, and whether it will repeat the same mistakes in the future.

    Therefore, the usefulness of an agent cannot be judged only from a few conversations. A reliable execution system should satisfy at least four requirements:

    • Clear task objectives: The agent can identify deliverables, completion conditions, and information that has not yet been confirmed.
    • Controlled operations: Tool calls are constrained by permissions, budgets, and risk rules.
    • Reusable experience: The agent can retain useful knowledge instead of mechanically accumulating all historical records.
    • Verifiable results: The agent not only provides conclusions but also explains the basis, execution status, and unresolved issues.

    This means that optimization should shift from “adding more prompts and tools” to “building a unified execution architecture.” Memory, skills, and rule documents are not independent attachments. They are three layers that jointly determine behavior.

    2. Build a Four-Layer Memory System to Turn History into Usable Experience

    A multi-layer memory approach is an architectural design method. It does not mean that all agents naturally have the same memory structure. The implementation can be adjusted according to task complexity, but raw conversations, user preferences, and execution methods should not be mixed in the same storage space.

    A practical approach is to divide information processing into four layers.

    2.1 Event Record Layer: Preserve Traceable Facts

    This layer records the original task, key tool calls, user feedback, and execution results. It is mainly used for auditing and post-incident review.

    Records should include the task identifier, time, operation target, actual result, and evidence location. Sensitive content should be masked, and access credentials should not be written into ordinary logs.

    It is also important to distinguish different information sources:

    • Requirements explicitly stated by the user;
    • Objective results returned by tools;
    • Inferences formed by the model based on context;
    • Assumptions that have not yet been verified.

    If sources are not distinguished, a model’s guess may later be treated as fact, contaminating long-term memory.

    2.2 Topic Summary Layer: Merge Repeated Information

    Raw records are often highly repetitive and contain many details that are meaningful only for a specific task. The topic summary layer organizes related events by task type, project scope, or problem category.

    For example, multiple file-organization tasks can be grouped under “directory organization and naming conventions,” while multiple troubleshooting sessions can be grouped under “runtime environment checks.”

    Summarization is not simple text compression. It needs to preserve the applicable conditions, exceptions, and evidence sources of a conclusion. Two tasks that appear similar should not be forcibly merged if their permission conditions or business objectives differ.

    2.3 Experience Understanding Layer: Extract Verifiable Rules

    This layer can use a language model to identify stable patterns in tasks, such as:

    • Which prerequisite checks are often missed;
    • Which execution order makes fault localization easier;
    • Which user corrections reflect long-term preferences;
    • Which failures are related only to a specific environmental anomaly.

    Model-generated experience should first be treated as candidate records rather than permanent rules. Candidate experience needs to be confirmed through repeated evidence, validation in subsequent tasks, or human review.

    A reasonable experience entry should answer three questions: what scenario it applies to, what evidence supports it, and when it does not apply.

    2.4 Skill Precipitation Layer: Turn Experience into Execution Specifications

    Experience is suitable for further precipitation into a skill only when it can describe clear inputs, steps, outputs, and checking conditions.

    For example, “check the impact scope before modifying a file” is an experience. In contrast, “read the target file, generate a diff preview, check reference relationships, confirm before writing, and run verification” can form a reusable skill workflow.

    It is important to note that a skill is not a simple summary of raw memory, nor is it the final destination of all experience. Preferences are suitable for preference records, facts are suitable for knowledge records, and only stable operating methods are suitable for the skill library.

    The four-layer processing chain can be summarized as:

    Event record → Topic summary → Experience validation → Skill candidate

    Each step should retain traceability so that conclusions do not become disconnected from original evidence.

    3. Create a Two-Way Loop Between Memory and Skills

    Memory addresses “what happened in the past and which information is worth keeping.” Skills address “how to execute when encountering a similar task.”

    The coordination between the two should not be a one-way conversion from historical records into skills. It should also include feedback after skill execution:

    Task execution → Collect evidence and feedback → Update candidate experience → Revise skills → Validate in new tasks

    The key to this loop is distinguishing “accidental success” from “stable effectiveness.” One successful task does not prove that a workflow is generalizable. One failure does not directly prove that a skill should be discarded.

    In practice, a skill can record the following information:

    • Applicable tasks and explicitly excluded scenarios;
    • Input conditions and required permissions;
    • Step order and key checkpoints;
    • Success criteria;
    • Common failures and recovery methods;
    • Last validation time and current version.

    The goal of long-term memory is not unlimited growth but higher density of useful information. Repeated records can be merged, outdated knowledge should be marked invalid, and inferences lacking evidence should have lower retrieval priority. Keeping fewer but more reliable records is usually more valuable than accumulating large amounts of unorganized history.

    4. The Core Rule Document Is the Control Plane of the Execution Architecture

    Skills describe how to perform local tasks. The core rule document defines how the entire system selects, executes, and checks those practices.

    It cannot replace model capability or permission mechanisms, but it can reduce process drift, rule conflicts, and repeated explanations. This is especially important as the number of skills grows. Without a unified entry point, different skills may adopt different confirmation standards, reporting formats, and fault-tolerance methods.

    The core rule document should cover the following areas.

    4.1 Task Execution Workflow

    A unified basic workflow can be used:

    Understand the objective → Check information completeness → Create a plan → Validate permissions → Execute operations → Verify results → Report and archive

    For simple, low-risk tasks, the workflow can be shortened. For operations such as deleting data, modifying access permissions, or sending information externally, confirmation steps must be added.

    4.2 Rule Priority

    The document should clarify the relationship among safety policies, permission restrictions, current user requirements, project conventions, long-term preferences, and skill instructions.

    Long-term preferences should not override explicit current instructions. Suggestions in skills cannot break safety boundaries. When conflicts occur, the system should explain the conflict and request confirmation rather than choosing a seemingly convenient interpretation on its own.

    4.3 Skill Selection and Composition

    Before invoking a skill, the agent should check its applicable scope, dependencies, and required permissions. When composing multiple skills, it should confirm that the output of the previous step meets the input requirements of the next step.

    Skills should not be selected only because their names are similar. Multiple local workflows should not be concatenated and assumed to be correct as a whole.

    4.4 Result Reporting and Fault Tolerance

    Reports should distinguish items that are completed, verified, unverified, and failed. Operations in a plan should not be described as already completed. A successful tool return does not automatically mean that a business objective has been achieved.

    When an error occurs, the system should first determine whether it is retryable, requires input adjustment, or requires human intervention. Automatic retries should have an upper limit to avoid duplicate writes, resource consumption, and fault expansion.

    In addition, the rule document is a versionable configuration asset and should undergo review and change tracking. “Prohibited operations” in the document must also be enforced by tool-layer permission controls. They cannot rely only on the model’s voluntary compliance.

    5. Dynamic Skill Layering: Frequency, Value, and Risk Determine Placement

    Skill layering can reduce retrieval and maintenance costs, but the number of skills in each layer should not be fixed by a rigid ratio. Different teams have different task structures, and skill distribution changes with project phases.

    Four layers can be used:

    Layer Main Characteristics Management Focus
    Foundation Layer High frequency, stable, used across tasks Interface consistency and strict testing
    General Layer Methods applicable to multiple project types Input/output specifications and applicable boundaries
    Specialized Layer Dependent on specific domains or environments Prerequisites and domain validation
    Experimental Layer New or not yet sufficiently validated Isolated execution and human review

    Layering is not a static label, nor is it merely ranking by invocation count. A high-frequency skill may require stricter invocation limits because of higher misuse risk. A low-frequency skill may still be worth maintaining because of high business value.

    Promotion mechanisms should consider usage effectiveness, cross-scenario validation, and risk level. For example, an experimental skill should be considered for a stable layer only after it passes validation in multiple independent tasks and has no unresolved high-risk issues.

    The reverse mechanism is equally important. When the environment changes, failures increase, or the applicable scope shrinks, a skill should be downgraded, suspended, or archived. Every promotion and downgrade should have a reason and version record for later review.

    6. Turn User Corrections into Preference and Boundary Records

    When users say what they want, they often do not fully state which methods are unacceptable. Recording positive goals and boundaries as pairs can help agents reduce repeated misunderstandings.

    For example, if a user asks for “concise explanations,” this can form two parts:

    • Positive preference: Prioritize conclusions and necessary steps;
    • Boundary constraint: Reduce repeated background information while retaining key risk warnings.

    Here, the boundary is not a complete mathematical complement. The opposite of “concise” is not simply “detailed,” because a user may want concise conclusions but detailed reasoning. Natural-language preferences usually contain multiple dimensions and depend on the task scenario.

    Therefore, a preference record should include at least:

    • Preference content and associated boundaries;
    • Applicable scenarios;
    • Source and confirmation status;
    • Update time;
    • Exception conditions.

    If a user requests a detailed explanation in a specific task, the system should not immediately reverse a global preference. A more reasonable approach is to record it as a current-task requirement. The long-term record should be updated only after the user explicitly expresses a long-term change.

    The value of boundary management is to reduce repeated corrections, not to fix decisions on behalf of the user. The system should support viewing, modifying, deleting, and revoking preferences.

    7. Prevent “Automatic Learning” from Becoming an Error Amplifier

    Automatically organizing memory and generating skills has clear value, but it can also introduce new risks.

    First, retrieved documents, web content, or tool outputs are external data. They should not gain the authority to modify system rules simply because they enter the context. Operational instructions in external content must be handled separately from task evidence.

    Second, candidate memory should be isolated from formal memory. A model can propose new rules, but high-impact changes—such as expanding permissions, modifying confirmation workflows, or adjusting data retention policies—require human review.

    Third, memory should be isolated by user, project, and permission scope. Private information in one project should not be retrievable by tasks in another project. Expired permissions should not remain effective through historical records.

    Finally, rollback capability should be provided. If a new skill or rule causes anomalies, the system should be able to restore a previous version and identify which change affected execution results.

    8. Evaluate Optimization Effects with Real Tasks

    To determine whether the architecture has improved, use a representative set of tasks rather than only observing whether answers are more fluent.

    The following metrics can be tracked continuously:

    • Task completion rate: Whether deliverables meet predefined standards;
    • Verification pass rate: Whether results pass tests, checks, or human acceptance;
    • Repeated error rate: Whether corrected problems appear again;
    • Number of human interventions: How many supplements or corrections are needed to complete a task;
    • Memory retrieval effectiveness: Whether retrieved content is relevant, accurate, and still valid;
    • Skill reuse effectiveness: Whether repeated planning is reduced while result quality is maintained;
    • Safety and cost metrics: Whether unauthorized attempts occur and whether tool calls and context consumption are reasonable.

    During evaluation, changes in the model, documents, skills, and environment should be distinguished. Adjust items one by one as much as possible. If multiple changes are made at the same time, it becomes difficult to explain the source of the benefit.

    9. Phased Implementation: Constrain Execution First, Then Expand Autonomy

    Implementation can be divided into four steps.

    Step one: Establish a unified execution workflow, result-reporting format, and high-risk confirmation rules. First solve the problem of uncontrollable behavior.

    Step two: Add event records and task archiving so that failures can be traced and later optimization has evidence to rely on.

    Step three: Organize a small number of validated skills around high-frequency tasks, and gradually introduce topic summarization and candidate-memory review.

    Step four: Build dynamic layering, preference management, automated regression validation, and version rollback. Then carefully expand the scope of automation.

    The real usability of an agent does not come from remembering all history or having a huge skill catalog. It comes from turning reliable experience into controlled action. A unified rule document standardizes the workflow, layered memory preserves evidence, skills carry stable methods, and validation plus feedback continuously corrects the system. Together, these elements form a maintainable and explainable execution system.