Agent Execution Architecture Optimization: Building Dual Loops for Memory and Skills
A well-designed AI agent is not just one that can call tools—it must understand task boundaries, stay consistent across multi-step execution, learn from failures, and avoid repeating mistakes after user corrections. This article presents a practical architecture for agent execution governance, covering a four-layer memory design, a unified core rules document, dynamic skill tiering, paired preference and exclusion boundaries, and the engineering practices—least privilege, versioning, and evaluation on fixed task sets—needed to turn memory and skills into mutually reinforcing feedback loops.
1. From “Able to Call Tools” to “Able to Reliably Complete Tasks”
Evaluating whether an agent is useful cannot be reduced to whether it can run commands, access web pages, or generate code. For developers and enterprise users, what matters more is: can it understand task boundaries, stay consistent across multi-step execution, accumulate experience from failures, and avoid repeating errors after user corrections?
In real deployments, agents often start as auxiliary components attached to existing systems, where the upper-level system handles task intake, tool allocation, and result aggregation. As execution rules, memory, and skill orchestration mature, some tasks can be handed to the agent for independent handling. However, removing intermediate orchestration layers does not automatically improve results. Whether the architecture should be simplified depends on task complexity, permission isolation requirements, failure diagnosis cost, and maintenance capacity—not on the number of components.
Three pipelines are genuinely worth optimizing:
- Execution pipeline: how tasks are understood, decomposed, executed, and verified.
- Memory pipeline: which information is worth retaining, and how it is retrieved, updated, and evicted.
- Capability pipeline: how successful experience is converted into reusable skills.
When these three pipelines work together, an agent can move from “answering questions ad hoc” to “delivering work reliably and continuously.”
2. Four Layers of Memory: Retain Accurately, Not More
The most common mistake in memory systems is storing the entire conversation history and hoping the model will automatically find the key points when needed. Recording more does not mean understanding more deeply; it can instead introduce stale preferences, duplicated information, and contradictory instructions.
One practical design divides memory into four logical layers. Note that this “four-layer” model is an architectural approach, not a native capability every agent has.
1. Interaction Record Layer: Preserve Traceable Facts
This layer stores task requests, user feedback, execution results, and necessary operation logs, primarily for auditing, tracing, and re-analysis.
Records should include timestamps, task identifiers, sources, and applicable scope. Sensitive content should be masked or access-restricted according to permissions; data should not be retained indefinitely just because it “might be useful later.”
Interaction records should not be injected directly into subsequent tasks as high-priority instructions. Web content, external files, and historical tool outputs may contain untrusted text and should be treated as data to be analyzed, not as new execution rules.
2. Process Experience Layer: Distill Reusable Execution Patterns
This layer focuses on “how the task was actually completed,” for example:
- When a certain class of error appears, which conditions to check first.
- Which step is expensive and worth validating in advance.
- Which solution works only in specific environments.
- Which failures stem from insufficient permissions rather than code logic issues.
Experience must retain its applicability conditions. Decontextualized summaries easily turn into wrong rules—for example, generalizing a single network timeout into “this type of request is always unavailable.”
3. Semantic Understanding Layer: Organize Preferences, Constraints, and Associations
With the help of large language models, records and experience can be summarized into task themes, user preferences, decision rationales, and knowledge associations.
But model-generated summaries are not inherently reliable. Important conclusions should link back to their sources and distinguish three evidence types: “explicitly confirmed by the user,” “observed multiple times,” and “inferred by the model.” Different evidence types should carry different levels of trust when retrieved later.
The value of this layer lies not in producing more summaries, but in reducing duplication, identifying conflicts, and converting scattered feedback into searchable, structured information.
4. Skill Consolidation Layer: Turn Mature Experience into Execution Assets
Once a processing workflow has been repeatedly validated, it can be consolidated into a skill. A skill is not just prompt text—it can include checklists, operating procedures, scripts, test methods, and failure handling strategies.
Skills should clearly define their inputs, preconditions, outputs, and non-applicable scenarios. A skill that only says “how to do it” without “when it can be done” invites the agent to mechanically apply experience in the wrong contexts.
The four layers can form the following path:
Interaction records → Task classification → Process distillation → Semantic validation → Skill candidates → Testing and release
This path is not strictly one-way. When a skill fails, the system should be able to trace back to the original evidence and revise the related experience, rather than accumulating the same type of errors.
3. Core Rules Document: Establishing Unified Execution Constraints
In an agent system, skills determine “what can be done,” while core rules determine “what should be done.” When the two conflict, there must be a clear priority order—never left for the model to guess on the fly.
Core rules can be maintained centrally or split by responsibility, but there should be a single authoritative entry point. At a minimum, they should cover the following.
1. Define the Task Execution Workflow
A general workflow can include:
Understand the goal → Retrieve relevant constraints → Formulate a plan → Select skills → Execute operations → Verify results → Report status → Update candidate memory
For simple, low-risk tasks, the workflow can be compressed. For tasks involving data deletion, permission changes, or production environment modifications, explicit confirmation checkpoints should be required. The purpose of the workflow is not to add formal steps, but to prevent critical judgments from being skipped.
2. Define Priority of Instructions and Information
Security policies, access permissions, and the user’s current explicit requests must be distinguished from historical preferences, general experience, and external materials.
For example, a historical memory saying “handle automatically when possible” does not authorize the agent to bypass a “confirm before modifying” requirement in the current task. Memory can assist understanding; it cannot expand authorization on its own.
3. Define Skill Selection Rules
When selecting a skill, the agent should weigh applicability conditions, risk, cost, success history, and environment compatibility—not just description similarity.
When multiple skills might apply, prefer the option that is validated, requires fewer permissions, and produces results that are easier to verify. When no suitable skill exists, the agent should be allowed to fall back to the general workflow rather than force a match.
4. Standardize Result Reporting
It is recommended to split results into: “completed,” “verification evidence,” “outstanding items,” and “risks and next steps.” Having executed a command does not mean the task succeeded; having generated a change does not mean the change took effect.
Reporting must distinguish plans, attempts, and facts, and avoid writing speculation as completion status.
Additionally, the rules document itself is not a security boundary. Critical permissions should be enforced by the execution environment, approval mechanisms, and access control—never by relying on written instructions alone for the model to voluntarily follow.
4. Dynamic Skill Tiering: Managing Capabilities by Actual Value
As a skill library grows, the problem often shifts from “lacking capability” to “being unable to find the right capability.” Skills can therefore be tiered dynamically by usage frequency, stability, reuse scope, and risk.
1. Foundation Layer
General operations such as file reading, content search, controlled command execution, and basic network access. These are used frequently and should prioritize clear interfaces, controlled permissions, and predictable behavior.
2. General Layer
Cross-project workflows such as troubleshooting, task planning, code review, and test design. These should minimize dependence on specific environments and clearly state the information they require.
3. Domain-Specific Layer
Skills targeting particular domains or business functions, such as data analysis, model experimentation, design review, and code repository maintenance. Domain skills should record their domain assumptions to avoid being misapplied to mismatched tasks.
4. Experimental Layer
Holds new workflows and skill drafts that have not been sufficiently validated. Experimental skills should have restricted usage scope and should not be assigned high-risk operations directly.
These tiers are not fixed proportions, and promotion or demotion should not be decided by call counts alone. A frequently failing skill has no place in the stable tier; a rarely used skill that handles critical tasks should not be dismissed as low-value.
A more reasonable promotion criterion: sufficient valid invocations within an observation window, consistently passing result verification, and a completed applicability scope review. Demotion triggers include persistent failure, changes in dependencies, expanded permission requirements, or the availability of a more reliable alternative workflow.
5. Preference Boundary Management: Record What Users Want—and What They Don’t
Users typically state goals without spelling out all boundaries. For example, “help me optimize the implementation” may implicitly carry constraints like “don’t change external behavior,” “don’t add complex new dependencies,” and “keep the change scope small.”
A paired recording approach links positive preferences with exclusion boundaries:
- What outcome is desired.
- What approaches are not acceptable.
- Which tasks it applies to.
- Who confirms it, and when.
- Under what conditions exceptions are allowed.
For example:
Goal preference: Prefer maintainable implementations.
Exclusion boundary: Avoid introducing hard-to-understand abstractions just to reduce a small amount of code.
Applicable scope: Routine maintenance of the current business module.
Exception conditions: Shared components need a unified extension interface, and the change has been confirmed.
These “relative boundaries” should not be misunderstood as strict logical complements. “Prefers simplicity” does not automatically mean “rejects all complex solutions,” because necessary complexity may come from genuine requirements.
Likewise, if a user chooses the opposite approach in one task, it does not mean the global preference should flip immediately. The system should first determine whether this is a temporary exception, a scenario-specific preference, or an explicit long-term change.
6. Forming Dual Loops Between Memory and Skills
The memory loop solves “how to understand tasks more accurately,” while the skill loop solves “how to complete tasks more reliably.” They can reinforce each other, but not through unchecked automatic strengthening.
The memory loop can be designed as:
Retrieve relevant information → Assess applicability → Execute the task → Gather feedback → Update or evict memory
The skill loop can be designed as:
Identify repeated workflows → Distill candidate skills → Define verification methods → Trial on a small scale → Release stable versions → Evaluate continuously
When connecting the two loops, set quality gates. One success does not prove a workflow is generally effective; one user correction does not necessarily establish a long-term rule. For experience involving sensitive data, permission operations, or critical business logic, add human review.
This is how “remember less, remember better” translates into an actual mechanism: retain information that is evidenced, properly scoped, and still valid, and actively clean up duplicated, expired, and misleading content.
7. Engineering Implementation: Permissions, Versioning, and Evaluation
A complete solution cannot stop at document organization and experience summaries. It should also cover the following engineering measures.
1. Least Privilege and Failure Control
Grant only the access a task requires. For modification operations, prefer previews, diff checks, and reversible approaches. Timeouts, unavailable dependencies, and permission denials should be handled by category, avoiding infinite retries or duplicate submissions.
For operations that need retries, first check idempotency; for non-idempotent operations, verify the status of the previous execution before retrying.
2. Version Management and Conflict Handling
Core rules, skills, and critical memories should all retain version history and change rationale. When an update fails, the previous version should be restorable.
On conflict, first check source authority, applicable scope, and confirmation time, and clarify with the user when necessary—rather than simply letting the latest record overwrite the old one.
3. Evaluate Against a Fixed Task Set
Before and after optimization, use the same or comparable task sets and observe task completion, user correction counts, invalid tool calls, execution cost, and recovery capability.
Memory quality should also be checked separately: whether retrieved content is relevant, whether it cites outdated information, and whether constraints from one project are incorrectly carried into another.
A system should not be judged as “smarter” merely because its answers are longer, its steps more numerous, or its tool calls more frequent.
8. Conclusion
Agent usability is, at its core, an execution governance problem. The model provides reasoning, tools provide operations, memory provides context, skills provide reuse paths, and core rules keep all of these capabilities bounded within the right goals and constraints.
In practice, the highest-priority investment is not endlessly expanding the skill library, but building a clear execution workflow, reliable memory evidence, dynamic skill management, and a verifiable feedback loop. Only when every execution can be checked, every piece of experience can be traced, and every improvement can be evaluated will an agent gradually become a dependable engineering collaborator.
