Self-Evolving Agents: Skill Memory and the Learning Loop

    This article examines why most agents are stateless and forget across sessions, then introduces a self-evolving agent architecture built around experience collection, skill generation, skill optimization, and persistent retrieval. It covers structured skill representations, cross-session personal memory, cloud-resident deployment, model-agnostic routing, and engineering controls for reliability, security, privacy, and evaluation.

    1. Root Cause: Why Most Agents Forget Every Time

    In real business scenarios, interactions between users and agents often span days or even months. Yet most agent implementations are stateless: each turn reconstructs context from the context window, and the context is destroyed when the session ends. This leads to three typical symptoms:

    • Repeated work: A user explained their coding standards, directory conventions, and release process last week, but has to explain them again this week.
    • Repeated mistakes: The agent steps into the same pitfall twice and cannot turn “that change was wrong last time” into a constraint.
    • Flat cognition: The agent has no longitudinal accumulation of the user and cannot form a preference profile, so it can only give generic answers.

    Expanding the context window only pushes the point of forgetting further back; it does not change the mechanism itself. The real solution is to separate memory from context and turn it into an external asset that can be persisted, retrieved, and evolved. This is the starting point for designing self-evolving agents.

    2. What Is a Self-Evolving Agent? A Four-Stage Closed Loop

    A self-evolving agent is an agent system with a learning loop. Its difference from an ordinary agent is not a larger model, but an additional feedback path at runtime, composed of four stages:

    1. Experience collection: Record task goals, execution traces, tool call results, and user correction signals.
    2. Skill generation: When a type of task is solved repeatedly or at high cost, distill the successful path into a reusable “skill.”
    3. Skill optimization: After a skill is invoked, revise it continuously based on success/failure feedback instead of fixing it permanently after one generation.
    4. Knowledge persistence and retrieval: Write conclusions to a persistent layer and recall them by relevance in later tasks.

    The main loop can be described in pseudocode:

    1. while True:
    2. task = receive_task()
    3. skills = retriever.search(task, top_k=5) # Retrieve relevant skills
    4. trace = agent.solve(task, skills=skills) # Execute and record the trace
    5. signal = evaluate(trace, user_feedback) # Success / failure / correction
    6. if signal.need_new_skill:
    7. skill = distill(trace) # Distill a new skill
    8. skill_store.upsert(skill)
    9. else:
    10. for s in skills:
    11. if s.used_in(trace):
    12. skill_store.revise(s, signal) # Optimize in place
    13. memory.persist(trace, signal)

    The key point is that both revise and upsert are runtime behaviors. They do not require retraining the model or manually changing code.

    3. How Skill Memory Works

    3.1 Skill Representation

    A skill should not be a vague natural-language impression. It should be a structured, verifiable entry. A minimal usable structure looks like this:

    1. {
    2. "id": "skill_0421",
    3. "name": "Pre-release checks for frontend projects",
    4. "trigger": "Requests related to release, bundling, or deployment",
    5. "steps": ["Read build configuration", "Run static checks", "Validate environment variable completeness"],
    6. "constraints": ["Do not operate directly on the production environment"],
    7. "success_count": 12,
    8. "fail_count": 1,
    9. "version": 3
    10. }

    trigger determines recall hit rate, constraints carries hard rules formed from user corrections, and success_count / fail_count provide the basis for optimization and retirement.

    3.2 Generation and Optimization Strategy

    • Be conservative about trigger conditions: Not every task is worth persisting. Use conditions such as “the same type of task appears N times” or “a single execution exceeds a step threshold” to avoid flooding the skill library with noise.
    • Keep traces of failures too: Write failure paths as “counterexample constraints”; their value is often higher than that of success paths.
    • Version instead of overwrite: Keep historical versions for rollback and attribution, and avoid letting one bad optimization contaminate all later tasks.
    • Confidence decay: Skills that have not been hit for a long time should be downweighted or archived to prevent stale knowledge from interfering with judgment.

    3.3 Retrieval and Context Assembly

    Recall usually uses hybrid retrieval that combines keywords and vector semantics, then sorts by relevance × confidence, and finally injects only the Top-K results into context. Controlling the injection volume is important: too many skills occupy context and dilute attention, which can reduce success rate.

    4. Cross-Session Personal Cognitive Model

    Beyond skills, it is also possible to maintain a layer of user-profile memory, divided into three types:

    • Semantic memory: Long-term preferences and facts, such as tech stack, naming conventions, and documentation language.
    • Episodic memory: Conclusions and decision reasons from past concrete tasks, supporting follow-up questions such as “why was it decided this way last time?”
    • Procedural memory: The skill library, describing “how to do it.”

    Only when these three work together can an agent evolve from a “generic assistant” into a “collaborator that understands you.” In engineering terms, it is necessary to define write policies (which information can be persisted automatically) and forgetting policies (how expired information is cleaned up); otherwise, the profile will degrade over time.

    5. Deployment Form and Model Agnosticism

    Self-evolution requires a process that stays online for a long time, so a common form is cloud-resident + message-entry driven: the agent runs on a cloud host or container platform, users issue instructions through instant messaging tools or a self-built web entry point, and the backend continuously executes long-running tasks without requiring a local machine to stay powered on.

    For the model layer, abstraction routing is recommended: uniformly wrap the inference interface, switch backend models through a single configuration command, and leave business code unchanged. This allows different model specifications to be selected according to task cost and avoids strong lock-in to a single model vendor. Note that after switching models, the compatibility of prompts and skill descriptions may change, so a regression evaluation set should be retained for validation.

    6. Engineering Implementation and Risk Control

    • Skill library governance: Deduplication, merging, version rollback, and permission isolation (separating team-level and personal-level skills).
    • Reliability: For the persistence layer, object storage is recommended for skills and traces; message queues can smooth peaks and drive asynchronous optimization tasks; logging and monitoring/alerting can track skill hit rate and failure rate. On Baidu AI Cloud, for example, these capabilities can be mapped to general product categories such as object storage, message queues, container platforms, logging, and monitoring/alerting.
    • Security boundaries: If a skill includes command execution capability, allowlists and sandbox isolation are mandatory; operations involving the production environment require human confirmation.
    • Privacy compliance: Cross-session memory is personal data, so it should support viewing, export, and one-click deletion, and clearly define the data retention period.
    • Effect evaluation: Build a fixed task set and compare success rate and step count differences between “memory enabled” and “memory disabled,” using data rather than intuition to judge whether the loop is actually effective.

    7. Conclusion

    The value of self-evolving agents is not that they chat better, but that they turn “experience” into assets that can be accumulated, reused, and audited. Skill memory solves repetition and forgetting, the learning loop solves continuous improvement, and cloud residency plus model agnosticism solve availability and cost flexibility. For developers, the real barrier has shifted from “integrating a model” to “designing governance mechanisms for memory and skills”—this is both a technical problem and an engineering discipline problem.