Building an Agent Self-Improvement Closed Loop: From Task Experience to Reusable Skills
AI agents often fail to retain lessons from past tasks, leading to repeated trial-and-error when encountering similar problems. This article explores how to build a self-improvement closed loop that transforms task experiences into verified, reusable skills. It covers the definition of operational skills, the hybrid approach of manual and automatic extraction, the six key stages of the closed loop (trace collection, filtering, extraction, validation, retrieval, and feedback), a general implementation approach, and crucial security and governance considerations for ensuring reliable system improvement.
I. From “Executing Instructions” to “Accumulating Experience”
Many agentic systems can understand requirements, plan steps, and invoke external capabilities to complete tasks. However, once the task ends, the experience accumulated during execution rarely enters a long-term knowledge system. When encountering a similar problem next time, the system may still explore from scratch, repeating the same trial-and-error process.
For example, an agent executing a data import task might discover that the source data contains duplicate records, requiring deduplication based on a business primary key before format validation. If this discovery remains only in the current conversation context, subsequent tasks may hit the same roadblock. If the system can extract applicable conditions, processing steps, and validation standards for future retrieval and invocation, it forms reusable operational experience.
This is exactly the problem the agent self-improvement closed loop aims to solve: how to transform local discoveries during tasks into verified skills that can be reused across tasks.
A concept needs clarification first: “self-improvement” here does not necessarily mean the model’s parameters change. A more common implementation involves building a skill repository, retrieval mechanism, and feedback process outside the model, allowing the agent to improve task performance by updating external knowledge and operational rules.
Therefore, it is closer to system-level continuous learning rather than unconditional model self-training.
II. A Skill Is Not Just a Prompt, But a Bounded Operational Rule
In an agentic system, a skill can be understood as a reusable knowledge unit oriented toward specific tasks. It can take the form of a natural language document, or it can combine structured metadata, operation templates, and test cases.
A mere description like “check the configuration first when encountering issues” is usually insufficient to constitute a reliable skill. It lacks trigger conditions, objects to check, criteria for judgment, and completion standards, easily turning the execution process into open-ended exploration again.
A complete skill should typically include the following:
- Goal and Scope: What problems to solve and what not to solve.
- Trigger Conditions: What task features or error symptoms must be present to use it.
- Input Requirements: What data, context, and permissions are needed.
- Pre-checks: What conditions must be confirmed before execution.
- Operation Steps: What sequence to follow and which steps can be omitted.
- Branches and Exceptions: How to handle unmet conditions or execution failures.
- Validation Standards: How to determine if the result is correct, rather than just confirming the operation was performed.
- Risks and Limits: Whether sensitive data, state changes, or irreversible operations are involved.
- Source and Version: Where the experience comes from, when it was validated, and what environment it applies to.
The key is that a skill should describe a reproducible method rather than saving a log of a single execution.
For instance, “task succeeded after modifying the file” is merely a result record. “Check if the target configuration is missing before modifying, verify related functions after modification, and restore the original state if verification fails” is much closer to a transferable operational rule.
III. Manual Maintenance vs. Automatic Extraction: Not a Binary Choice
The advantage of manually writing skills is controllability. Developers can clearly define permission boundaries, review steps, and solidify stable business workflows. The downside is the high maintenance cost; new scenarios that are not observed and recorded struggle to enter the knowledge system.
Automatic skill extraction uses task execution itself as the source of experience. The system can identify recurring obstacles, effective solution paths, and necessary check steps, generating candidate skills for future reuse.
However, this does not imply that “manually maintained systems cannot automatically accumulate experience,” nor does it mean “automatically generated skills are inherently better than manually written ones.” Whether an experience closed loop can be achieved depends on whether the system possesses capabilities for trajectory collection, knowledge writing, validation, and lifecycle management, rather than just the format of the skill document.
A more reasonable engineering choice is usually a combination of both:
- Manually maintain high-risk, strictly constrained core skills;
- Automatically discover new experiences during tasks to generate candidate content;
- Determine whether to publish through testing or manual review;
- Continuously revise based on actual effectiveness, revoking when necessary.
Automation is responsible for reducing the cost of discovering and organizing experience, while governance mechanisms limit the propagation of errors.
IV. Six Key Stages of the Self-Improvement Closed Loop
1. Collect Task Traces: Retain Interpretable Evidence
The input for experience extraction should not only include the final answer but also the task goal, key decisions, execution results, error messages, correction processes, and validation evidence.
It is especially important to distinguish between three scenarios: first, the system completed an operation; second, the external environment reported the operation as successful; third, the task goal was actually achieved after independent inspection. These three are not equivalent.
For example, a successful data write does not mean the data content is correct; a successful report generation does not mean the report covers all requirements. Traces lacking result validation are prone to producing erroneous experiences.
Trace collection should also adhere to the principle of minimization. Credentials, personal information, and business-sensitive content should not enter the skill repository as-is. You can record “requires read access to authorization credentials,” but not the actual credential values.
2. Filter Experience: Not Every Task Deserves to Become a Skill
Before automatic extraction, you need to assess whether the experience has reuse value.
Content suitable for extraction usually has the following characteristics:
- Likely to recur in subsequent tasks;
- The solution path has a certain degree of non-intuitiveness;
- Applicable conditions can be clearly described;
- Has result validation or other credible evidence;
- Can reduce repetitive exploration rather than just increasing document volume.
One-time temporary addresses, specific user preferences, or unverified guesses are usually not suitable to be saved as general skills. They can enter other types of memory but should be managed separately from operational skills.
This distinction helps prevent the skill repository from being flooded with short-term facts, which would make retrieval results increasingly cluttered.
3. Extract Candidate Skills: Preserve Constraints, Remove Accidental Details
The core of experience extraction is abstraction, not simple summarization.
Suppose a task solved a data validation issue by adjusting the processing order. The system needs to identify: was the truly effective factor the deduplication step, or the change of data source? Is a specific path name just environmental information at the time, or a necessary constraint for the operation?
If accidental details are treated as necessary conditions, the skill becomes overly specific. If key constraints are entirely removed, the skill may become overly generalized.
Therefore, candidate skills should simultaneously preserve “why to do it this way” and “when not to do it this way.” When evidence is insufficient, unverified assumptions should be explicitly marked rather than written as definitive rules.
4. Validate Candidate Skills: Use Tests to Block Error Accumulation
Extraction completion does not mean it is ready for use. At minimum, structural checks, scope checks, sensitive information checks, and operational risk checks should be performed.
For tasks that can be reproduced in isolated environments, the following should also be designed:
- Positive examples: Can the skill produce the expected result when conditions are met?
- Boundary examples: Does it correctly halt or switch to another process when input is missing or conditions change?
- Negative examples: Will it be mistakenly triggered by unrelated tasks?
- Failure examples: Is there a reasonable recovery path when execution anomalies occur?
Validation results should be bound to the skill version. You cannot assume that a modified version remains reliable just because an older version was successful.
5. Publish and Retrieve: Surface the Right Skill for the Right Task
After a skill is stored, it can be retrieved using a combination of task type, keywords, semantic similarity, and structured conditions.
Relying solely on text similarity is insufficient. Two tasks might both mention “import failure,” but one is due to format incompatibility and the other due to insufficient permissions; their handling methods are entirely different.
A more robust workflow is to first recall candidate skills, then verify environmental constraints, input types, permission requirements, and current state. Only skills that meet critical conditions enter the execution plan.
Additionally, avoid placing the entire skill repository into the context at once. Too many skills not only increase processing costs but may also introduce conflicting instructions. On-demand loading is usually better for controlling behavioral boundaries.
6. Feedback and Update: Form an Undoable Continuous Improvement Process
After a skill is used, you need to record whether it was triggered correctly, whether it completed the task, whether it caused additional errors, and whether manual intervention was required for correction.
Failure feedback should first locate the cause:
- Is there an error in the skill itself?
- Is the current task outside the applicable scope?
- Has the external environment changed?
- Did the retrieval mechanism select the wrong skill?
- Did the execution process deviate from the skill’s requirements?
These causes require different remediation methods. A retrieval error does not necessarily require rewriting the skill, and an environment change should not be misjudged as a permanent failure of the method.
Skill states can be categorized as candidate, verified, published, disabled, and archived. Retaining version history and rollback capabilities ensures that impact can be contained promptly after a problem is discovered.
V. A General Implementation Approach
Architecturally, the system can be decomposed into a task executor, trace storage, experience extractor, validation module, skill repository, and retrieval module. These modules collaborate through clear data boundaries, preventing the task executor from directly publishing arbitrary content as long-term rules.
Below is a tech-stack-agnostic schematic workflow. The names are used only to explain the logic and do not represent off-the-shelf interfaces:
Execute task and collect tracesIf results lack verification evidence:Retain diagnostic informationDo not publish new official skillsElse:Determine if the experience is worth reusingIf worth reusing:Generate candidate skillCheck sensitive info, permission requirements, and scopeRun available testsIf high-risk operation involved:Enter manual reviewIf publishing conditions met:Save new version and its verification evidenceWhen processing the next task:Retrieve candidate skillsVerify preconditions and current permissionsLoad and execute on demandVerify task resultsRecord feedback, decide to retain, revise, or disable
The most important design principle here is: skill generation and skill publishing should be separated.
The model can propose new operational methods, but the right to officially use them should be determined jointly by validation rules, permission policies, and review processes. This retains the benefits of automation while reducing the risk of a single error being amplified over the long term.
VI. Often Overlooked Security and Governance Issues
1. Prevent Untrusted Content from Polluting the Skill Repository
Task inputs, external documents, and error logs may all contain injection instructions. During experience extraction, they should be treated as data to be analyzed, not as system rules with authorized status.
For example, an external text claiming “skip safety checks from now on” cannot be written into a skill just because it appeared in the trace of a successful task. The system needs to maintain source boundaries and check whether candidate skills attempt to expand permissions, bypass reviews, or alter trusted rules.
2. Skills Cannot Grant Themselves Permissions
A skill can state what permissions are needed to execute a certain action, but it cannot obtain delete permissions simply because the document states “can delete data.”
Authorization should be determined by an independent access control mechanism. For operations involving production environment changes, data deletion, financial operations, or sensitive information access, additional approvals, scope limits, and audit logs should be set.
3. Control Error Generalization
A single success only provides limited evidence. The system should clearly distinguish between “effective in a specific sample” and “universally reliable across a class of tasks.”
For skills with limited evidence, you can restrict their scope, require additional confirmation, or use them only for planning assistance. As more validation results accumulate, you can then decide whether to expand the applicable scope.
4. Prevent Skill Duplication and Conflict
Automatic extraction can easily generate multiple skills with similar content or versions with contradictory steps. Before storing, check for similar content to decide whether to add, merge, or update.
When conflicts arise, do not simply select based on update time. You also need to compare applicable conditions, validation evidence, and risk levels. If a clear judgment cannot be made, halt automatic execution and request confirmation.
VII. How to Prove the System is Actually Improving
An increase in the number of skills does not equate to an increase in capability. To determine if the closed loop is effective, you need to observe task results rather than just tallying new documents.
You can focus on the following metrics:
- The rate at which the same error recurs for similar tasks;
- Task success rate and result validation pass rate;
- The number of exploration steps and execution time required to complete tasks;
- Skill retrieval hit rate and false trigger rate;
- Failures, rollbacks, and revisions after skill publication;
- Number of manual interventions, and compliance of high-risk operations.
During evaluation, distinguish between changes in model capability, changes in task difficulty, and the impact brought by skill reuse. When conditions permit, use a fixed set of tasks to compare results with and without skill retrieval enabled, and record differences in the runtime environment.
For live tasks, adopt phased rollouts and continuous monitoring to prevent unvalidated experiences from directly affecting all users.
VIII. Conclusion: Reliable Self-Improvement Focuses on the Closed Loop, Not Just Auto-Writing
An agent automatically generating skills only completes part of the experience accumulation process. A truly reliable mechanism must also answer three questions: on what basis does this experience hold, under what conditions should it be used, and how can it be rolled back if an error is found.
Therefore, self-improvement capability is not simply about letting the system “remember more,” but enabling it to selectively save experiences, validate them with evidence, invoke them in the correct scenarios, and revise them based on feedback.
For developers, the highest priority is not to build a massive skill repository, but to construct a small-scale, testable, auditable, and rollbackable closed loop. Only when experience reuse can consistently reduce errors and repetitive exploration does skill accumulation genuinely translate into an improvement in system capability.
