What Agent Self-Generated and Self-Optimized Skills Mean for AI Engineering
This article breaks down what it means for AI agents to autonomously generate and optimize skills, addressing the core problem that most agents forget everything once a session ends. It explains four foundational capabilities and their engineering requirements: turning successful task trajectories into reusable skills with verifiable acceptance criteria, evolving skills through controlled versioning driven by real failure samples, designing layered cross-session memory with governance, and running agents as always-on services decoupled from channel integrations. It also covers model-layer abstraction for provider portability, plus the risks and boundaries of self-evolving systems. The key takeaway is that this approach turns knowledge from volatile context into versioned, testable, and rollback-capable engineering assets.
1. The Starting Problem: Why Agents Keep “Losing Their Memory”
Over the past two years, the capability boundaries of AI agents have been pushed upward quickly, but one structural flaw has never been truly solved: session-bound amnesia. Most agents are stateless, function-style systems—they take context as input, produce a result, and once the session ends, the context is discarded. The operating conventions a user spent half an hour teaching yesterday, the API pitfalls hit last week, and the naming conventions for a particular business object all reset to zero today.
In engineering practice, we patch this in a few ways: writing longer and longer prompts, stuffing documents into a retrieval store, and running a “background sync” at the start of every session. These approaches help to some degree, but they do not address the root cause: knowledge is not being structured into executable, reusable, and iterable assets. It simply exists as scattered natural-language fragments inside the context.
The direction of “autonomously generating and optimizing skills” matters precisely because of this: it moves an agent from a one-off Q&A tool to an executor that accumulates engineering experience. Below is a breakdown of the four foundational capabilities it relies on and the key engineering points for each.
2. Capability One: Generating Reusable Skills from Experience
In an engineering context, a skill is closer to a “solidified operating procedure”: it abstracts the successful trajectory of a multi-step task into an invokable unit with preconditions, a step sequence, failure fallbacks, and acceptance criteria. The difference from traditional hard-coded tools is that a skill is induced by the agent itself after completing a task, rather than written in advance by a developer.
A minimal skill description structure can be written as:
skill:name: batch_export_daily_reportversion: 3triggers: ["export daily report", "日报导出"]preconditions:- Read-only credentials for the target data source have been obtainedsteps:- Validate the time range parameter; default to 00:00–24:00 of the previous day- Fetch data page by page, with an upper limit of 500 records per page and 3 retries on failure- Aggregate and write to object storage using the naming rule report/{date}.csv- Return the accessible path and the number of recordsfallbacks:- On data source timeout, fall back to reading the previous trading day's snapshotacceptance:- The record count differs from the source-side count by less than 0.5%
The key point is that the acceptance criteria must be decidable. If a skill only records “then tidy up the data,” it cannot determine on the next invocation whether it succeeded, and therefore cannot enter the optimization loop. Decidable acceptance conditions are the prerequisite for the entire learning loop to hold.
3. Capability Two: Optimizing Skills in Use, Not Rewriting Prompts
The essence of skill optimization is controlled version iteration. A practical engineering approach is to introduce version numbers and effectiveness metrics: log duration, retry count, number of human interventions, and acceptance pass rate on each invocation. When the same skill fails in the same way several times in a row, trigger a revision that generates a new version while keeping the old one for rollback.
def maybe_evolve(skill, metrics):# Only trigger a revision after consecutive failures reach the threshold, to avoid thrashingif metrics.fail_streak < 3:return skillcandidate = revise(skill, failure_samples=metrics.recent_failures)if evaluate(candidate, metrics.benchmark) > evaluate(skill, metrics.benchmark):skill.archive() # Keep the old version to support rollbackreturn candidatereturn skill
There are two easily overlooked constraints here. First, revisions must be driven by real failure samples; otherwise the model will “optimize based on imagination” and break a skill that was working. Second, a new version should be regression-tested against a fixed set of benchmark cases before going live, to avoid fixing something locally while degrading overall behavior. The skill library therefore needs an isolated evaluation set and a canary release strategy, which is consistent with conventional software release practices.
4. Capability Three: Layered Design for Long-Term Cross-Session Memory
“Understanding you better over time” is not achieved through longer context, but through layered memory. A fairly common division in the industry has three layers:
- Working memory: the current session context, limited in capacity and released when the session ends;
- Episodic memory: the process and conclusions of past tasks, searchable by time and task type;
- Semantic memory: stable facts induced from multiple episodes, such as a user’s output format preferences or a team’s API conventions.
The write path needs governance; otherwise memory will quickly be polluted by noise. In practice, the recommendation is: only tasks accepted as successful are allowed to be written to episodic memory; semantic memory must be upgraded only after repeated occurrence (for example, the same preference observed three or more times); each memory entry retains its source and confidence, with newer and higher-confidence entries overriding on conflict, and users are allowed to view and delete them. Memory should also be isolated by user and tenant, and sensitive fields should be masked before being persisted—this is an indispensable part of enterprise scenarios.
5. Capability Four: Continuous Background Operation and Decoupled Integrations
To make an agent truly “keep working,” it needs to be separated from interactive sessions and deployed as an always-on service: the container platform hosts the runtime, tasks and results are decoupled through a message queue, logs and metrics flow into a unified logging service and monitoring/alerting system, and failed tasks enter retry and dead-letter flows.
On the integration side, it should be decoupled from business logic. Users may issue commands from instant messaging tools, mobile applications, or internal systems, so a protocol adapter layer is needed to normalize messages from different channels into an internal task model:
Channel adapter layer → Task normalization → Scheduling and auth → Agent runtime → Skill library / memory store↓Logs · Metrics · Alerts
Authentication and quotas must be moved ahead to the scheduling stage; otherwise an always-on agent that can automatically perform actions is equivalent to opening an entry point with excessive permissions in the system. All skills with side effects should support a “requires human confirmation” switch.
6. Model-Layer Decoupling: Designing Replaceability into the Architecture
Not being tied to a single model provider relies in engineering on a model abstraction layer: unify message and tool-call formats, converge differences such as temperature, context window, and billing into capability declarations, and have the runtime select a model by task type—use a more capable model for reasoning-intensive tasks, a lower-cost model for bulk extraction, and a private endpoint for sensitive data. Switching only changes configuration, not business code.
class ModelPort(Protocol):def complete(self, messages: list[dict], tools: list[dict]) -> Response: ...# Switch backends via configuration only, with zero changes to business coderouter = ModelRouter(config="models.yaml")
Three supporting things are needed: unified invocation metering for cost attribution, automatic fallback to a backup backend on failure, and version management for prompts and tool definitions to avoid behavior drift caused by model upgrades.
7. Risks and Boundaries
Self-evolution amplifies errors. Once a skill is incorrectly induced, it will be reused repeatedly; once memory is polluted, it will keep affecting outputs. Therefore, there must be rollback, audit, and human-takeover channels. It is also necessary to distinguish skill tiers that “can be optimized automatically” from those that “must be human-confirmed”; actions involving funds, permissions, and data deletion should not enter automatic iteration. Observability is not optional: without a complete call chain and decision trail, this kind of system cannot be operated in production.
8. Conclusion
What agent-generated and self-optimized skills truly change is the form knowledge takes in a system—from volatile context into versioned, testable, and rollback-capable engineering assets. Four points matter in implementation: skills must have decidable acceptance criteria; optimization must be driven by real failures and support canary release and rollback; memory must be layered and governable; and models and channels must be decoupled. If an enterprise already has foundational capabilities such as a container platform, message queue, object storage, and monitoring/alerting, and is willing to invest in evaluation sets and permission governance, this kind of architecture has a clear implementation path on platforms with a complete cloud-native and observability product system, such as Baidu AI Cloud.
