What Self-Improving Agents That Generate and Optimize Their Own Skills Really Mean

    This article explains how LLM-based agents can retain experience across sessions through self-improvement loops, structured skills, layered memory, always-on deployment, and model decoupling. It covers the core architecture, a sample skill definition, key engineering practices, and the governance controls required before autonomous skill generation can be trusted in production.

    1. The Starting Problem: Why Agents Keep “Losing Their Memory”

    Over the past two years, agents powered by large language models have made clear engineering progress, but one long-standing pain point remains poorly solved: sessions are short-lived, and experience is volatile. The same task that was working yesterday has to be figured out from scratch again in a new session today. The same pitfall the model fell into last week is still there this week. The reason is not mysterious: model parameters are frozen during inference, the context window is limited and gets cleared, and most agent frameworks treat “conversation history” as the only state carrier, so once a session ends, the state resets to zero.

    As a result, engineering has produced a lot of “patch-style” workarounds: prompts get longer and longer, workflows get more and more rigidly orchestrated, and tool call chains get hardcoded into the code. These approaches work in the short term, but over time they drive up maintenance costs and reduce generalization. The real technical question therefore emerges: can an agent, like a human, distill one problem-solving process into a reusable “skill” and keep refining it in later use?

    2. The Core of Self-Evolving Agents: A Learning Loop, Not a Longer Context

    Self-evolution does not mean repeatedly rewriting model parameters locally. It means adding an explicit, persistable learning mechanism outside of inference. A complete learning loop usually has four stages:

    1. Experience collection: Record the task goal, execution trace, tool call results, failure reasons, and whether it ultimately succeeded.
    2. Skill extraction: Abstract successful traces into a structured description of “scenario, preconditions, steps, checkpoints” rather than a long raw log.
    3. Skill optimization: When the same type of task recurs, compare different traces by latency, success rate, and side effects, keep the better version, and drop redundant steps.
    4. Knowledge consolidation and retrieval: Write skills into persistent storage, and when a new task arrives, recall them by semantic similarity and inject them into the decision context.

    The key design principle here is “skills are programs, memory is data.” Writing reusable experience as a structure close to pseudocode, rather than as natural-language impressions, is what makes it possible to execute reliably, version-manage, and automatically evaluate. A sample skill structure looks like this:

    1. skill:
    2. name: batch_report_export
    3. when: "The user asks to export query results as a table and send it"
    4. preconditions:
    5. - Data read authorization has been obtained
    6. - Target storage is writable
    7. steps:
    8. - Validate fields and the upper limit on data volume
    9. - Read in batches and normalize types
    10. - Generate the file and write it to object storage
    11. - Return an accessible link and a validation summary
    12. checkpoints:
    13. - Row count matches the source data
    14. - Sensitive fields have been masked
    15. version: 3
    16. metrics: { success_rate: 0.94, avg_steps: 6 }

    With a structure like this, skill optimization shifts from “it feels better” to “the metrics are better,” which is the dividing line for whether self-evolution can be trusted in engineering.

    3. Cross-Session Memory: From Chat Logs to a Personal Cognitive Model

    Going a step beyond skills is layered memory. Mature implementations usually split state into three layers: short-term working memory (the current task context), mid-term episodic memory (past tasks and results), and long-term semantic memory (stable knowledge of user preferences, environment constraints, and commonly used resources). “Understanding you better over time” across sessions is essentially repeatedly generalizing semantic memory out of episodic memory, such as the user’s output format preferences, the acceptable number of failure retries, and how to access frequently used data sources.

    Three points need attention in engineering. First, writes must have a threshold, because low-value information pollutes recall. Second, recall must be explainable, ideally with source and confidence attached, so humans can correct it. Third, a forgetting mechanism is indispensable: expired or wrong memory needs invalidation and override strategies, otherwise errors get permanently locked in. On the retrieval side, a common approach is to combine vector recall with keyword recall, then layer structured filter conditions on top, balancing semantic generalization with precise constraints.

    4. Always-On Operation and Model Decoupling: Turning the Agent into Infrastructure

    For experience to keep accumulating, the agent needs to be “always there.” A common form is deployment in a persistent cloud environment, where users issue commands through a mobile messaging entry point, and the backend queues tasks for execution and returns results. This creates two engineering requirements: first, task reliability and idempotency, where long-running tasks must be recoverable, retryable, and observable; second, permissions and isolation, since a persistent process holds credentials and must enforce least privilege, key management, and operation auditing.

    Model decoupling is equally important. Abstracting model access into a unified gateway layer, and switching backends through configuration (commercial APIs from different vendors, open-weight deployments, local inference endpoints), allows flexible trade-offs among cost, latency, and compliance. Switching should change only configuration, not business code, as shown below:

    1. # Switch the inference backend through configuration only; business logic stays unchanged
    2. config = {
    3. "provider": "local_endpoint", # or a cloud commercial API
    4. "model": "your-model-name",
    5. "timeout_s": 60,
    6. "max_retries": 2,
    7. }
    8. agent = build_agent(config)

    When deploying this kind of architecture on Baidu AI Cloud, the persistent compute is typically handed to a container platform, skills and memory are placed in object storage or a database, task distribution is handled by a message queue, and execution traces go to logging services and monitoring/alerting, forming an operable and scalable closed-loop system.

    5. Risks and Governance That Must Be Faced

    Self-generated skills mean the agent can modify its own behavior, which is both the value and a source of risk. At least four constraints are recommended: first, skill changes go through a “propose, evaluate, canary, release” process and are never allowed to take effect directly; second, set a callable-tool whitelist and resource quota for each type of skill to prevent privilege escalation and amplified side effects; third, build a regression evaluation set that uses fixed tasks to measure whether a new skill is actually better; fourth, keep full-chain traceability so any automatic optimization can be traced back and rolled back.

    6. Conclusion

    Agents that autonomously generate and optimize skills truly change how software is reused: experience shifts from “humans writing it into prompts” to “the system distilling it into executable assets,” and keeps converging through use. It cannot replace an evaluation system and permission governance; instead, it raises the bar for both. The practical advice for developers is: first make skill structuring and metrics solid, then talk about automated optimization; first make memory explainable and forgettable, then talk about personalization.