AI Agent Architecture with Self-Evolution: Skills, Memory, and Failure Learning
This article breaks down the architecture of self-evolving AI agents from a general engineering perspective. It explains why conventional stateless agent runtimes waste effort across sessions, then details three core mechanisms that close the learning loop: automatically distilling successful execution traces into reusable skills, treating failed paths as first-class records with explicit risk annotations, and capturing user corrections as persistent, scoped memory. It also covers the engineering constraints required to make self-evolution reliable in practice, including quality gates, deduplication, permission isolation, and observability metrics. Readers will gain a practical blueprint for turning agents from executable tools into accumulating productivity assets.
1. The Starting Problem: Why Most Agents Forget Everything After a Task
In current AI agent engineering practice, mainstream open-source frameworks share a highly similar runtime model: developers pre-orchestrate the tool chain and prompts, the agent receives an instruction, calls tools, returns a result, and the flow ends. This stateless execution model introduces a structural flaw: task experience cannot accumulate across sessions.
The waste shows up in three forms:
- Repeated exploration cost: When a similar task runs a second time, the model still has to re-plan the steps and probe tool parameters, so token consumption and latency repeat almost linearly.
- Errors are not reusable: The root cause identified during one failure is completely lost in the next session, and the same pit is stepped into again.
- Preferences must be restated repeatedly: A user’s verbal conventions for dependency management, code style, or directory structure never enter long-term context.
As a result, the industry has begun exploring a different technical route: treat “task completion” as the starting point for “experience capture,” and build a learning loop from automatic skill distillation + persistent memory + failed-path annotation. This article dissects the engineering implementation of that loop from a general architecture perspective.
2. Core Mechanism One: Automatic Skill Evolution, Turning Workflows into Reusable Assets
2.1 Trigger Conditions and Distillation Logic
When a task crosses a certain complexity threshold (for example, more than 5 planned steps, or multiple tools chained together) and converges successfully, the framework should abstract the execution trace into a “skill” document. The abstraction process typically involves three steps:
- Trace pruning: Remove temporary parameters tightly coupled to this specific input, and keep the generalizable step skeleton.
- Dependency declaration: Record the required tools, permissions, and prerequisite environment.
- Input placeholders: Convert variables such as project paths and target environments into placeholders so the skill becomes portable.
Pseudocode illustration:
if task.plan_steps >= 5 and task.status == "success":skill = abstract_workflow(trace=task.trace,drop_fields=["repo_path", "target_env"],placeholders={"<REPO>": "string", "<ENV>": "enum"})skill_store.save(f"~/.agent/skills/devops/{skill.slug}/SKILL.md", skill)
2.2 How Skills Are Reused
Distilled skills are loaded in two ways: explicit invocation or semantic matching. The explicit way has the user call the skill by name directly; the semantic way has the scheduling layer automatically recall a skill based on the similarity between the current request and the skill description. The key point is that a skill is a starting point, not an endpoint: the agent can still make local adjustments on top of it.
2.3 Directory-Based Skill Governance
To keep the skill library from degrading into an unordered pile of text, a three-layer structure of “category domain + skill name + metadata files” is recommended:
~/.agent/skills/├── mlops/│ └── fine-tune-pipeline/│ ├── SKILL.md # steps, prerequisites, inputs│ └── references/ # config samples, checklists└── devops/└── deploy-container/ # created automatically by the agent├── SKILL.md└── references/
A SKILL.md file should contain at least: applicable scenarios, non-applicable scenarios, the step sequence, the dependency list, known failure points, and a version number. The version number matters in particular, because it makes skills rollback-able, comparable, and eligible for canary rollout.
3. Core Mechanism Two: Failed Paths Are First-Class Citizens
Traditional frameworks retain only successful traces, which is a major loss in information utilization. A more mature approach writes the complete “fail first, then succeed” trace into the skill and explicitly annotates the failed branch.
Take containerized deployment as an example: the first attempt applies configuration in a declarative batch, which fails due to template syntax or field validation; the agent then switches to a path of layer-by-layer rendering, performing server-side validation before submitting, and finally succeeds. When distilling this, record:
- Failed action: what was done and caused the failure;
- Failure signal: the characteristic string identified from logs or return codes;
- Corrective action: the path that actually worked;
- Early-warning rule: run a pre-check before the next execution to surface the risk point in advance.
This upgrades a skill from an “operations manual” to an “operations manual with risk warnings,” which is exactly what experience density looks like.
4. Core Mechanism Three: Immediate Memory for User Corrections
Constraints a user mentions casually in conversation (for example, “use a faster package manager for dependency installation” or “commit messages must include the task ID”) are high-value, low-cost supervision signals. Engineering-wise, the system should:
- Recognize: Classify the corrective statement as a preference-type fact rather than a one-off instruction.
- Structure: Store it as a
scope / rule / confidencetriple, where the scope can be global, project-level, or directory-level. - Enforce: Inject it as a hard constraint during the subsequent planning phase, instead of relying on the model to “remember” it.
- Allow revocation: Provide an entry point to view and delete entries, preventing a wrong preference from polluting behavior over the long term.
It is worth emphasizing that memory and skills should be stored separately: a skill describes “how to do it,” while memory describes “what must be obeyed.” Mixing the two makes conflicts hard to locate during reuse.
5. Key Engineering Constraints for a Working Loop
For self-evolution to be genuinely usable, “automatic saving” alone is far from enough; four constraints are also required:
- Quality gates: A skill must pass a reproducibility check before entering the library, so that an accidentally successful trace is not distilled into a “best practice.”
- Deduplication and merging: Merge skills that are highly similar semantically, preventing library growth from degrading recall accuracy.
- Isolation and permissions: When skill execution involves real environment changes, authorization should be tiered, and high-risk actions should keep human confirmation.
- Observability: Establish metrics for skill hit rate, reuse success rate, and average step reduction, and use data to verify whether “it gets better the more you use it” is actually happening.
In terms of deployment form, this loop can run on a local development machine, or it can rely on general cloud capabilities such as container platforms, object storage, log services, and monitoring and alerting to provide centralized storage, version management, and effectiveness measurement for the skill library. The general infrastructure capabilities that Baidu AI Cloud provides along this “execute—distill—measure” chain can serve as a reference foundation for engineering implementation.
6. Conclusion
The next stage of competition among agents will not be about how nicely a single task is completed, but about whether experience can be accumulated and reused in a structured way. Distilling complex workflows into skills, annotating failed branches as risks, and precipitating user corrections into constraints—combined with quality gates and quantitative metrics—is what allows an agent to evolve from an “executable tool” into “accumulating productivity.”
