Memory and Skill Loops for Self-Evolving Agents

    Stateless assistants forget after each session. This article explains layered memory, a write-and-reuse skill loop, retrieval, governance, and when that design can replace a blank-prompt coding assistant.

    Why “remembering” is not enough

    Many agents look strong in a single session: they read context, call tools, and finish the task. When the session ends, that experience often stays only in the chat log. The next run starts from a blank prompt. Users restate environments, directory conventions, release processes, and communication preferences. Models repeat the same mistakes.

    Self-evolution here does not mean online training of model weights. It means the agent, within controlled bounds, writes experience into external state that can be injected, retrieved, and revised, then prefers to reuse it on later tasks.

    To judge whether a framework can replace a stateless assistant, look at four things: what it stores, how it writes, how it recalls, and how it avoids storing the wrong thing. Dumping full conversation history into the prompt inflates context, lets noise drown constraints, and raises cost. A more stable pattern is layered memory plus a skill loop.

    Layers of memory

    In practice, keep at least three kinds of information apart so they are not mixed in one free-text blob.

    Environment and conventions. Repository layout, build commands, environment-variable conventions, release windows, forbidden operations, and verified troubleshooting conclusions. These change slowly, but a wrong record can cause wrong actions. Maintain them as structured items: topic, conclusion, evidence, update time, and scope.

    User and collaboration style. How to address the user, how much detail they want, whether to propose a plan before changing code, risk tolerance, and preferred output formats. These affect communication. Do not mix them with infrastructure facts, or retrieval may treat a personal preference as a system fact.

    Task traces and reusable skills. A successful investigation, a standard code-review checklist, or a fixed data-processing procedure cannot be reliably invoked next time if it lives only in chat. Abstract it as a skill: trigger, inputs, steps, tools, acceptance criteria, and failure fallback. Skills are procedural knowledge; memory entries are factual knowledge. Store them separately.

    At session start, inject only a task-relevant summary, not the full history. Keep the full text for retrieval when needed. That preserves long-term understanding while bounding prompt length.

    How the learning loop runs

    The loop is: execute, reflect, persist, reuse, correct.

    In execution, the agent completes the task with current skills and memory and records key decisions: which command was used, which memory was relied on, and whether the result met acceptance criteria. Reflection does not ask the model to “feel smarter.” It asks, against the outcome: which step is reusable, which was valid only for this input, and which was an error that should become a lesson.

    Persistence is rule-constrained. New facts need a source. Conflicts with old facts are marked for confirmation, not silently overwritten. Skills must include failure conditions so a one-off success is not treated as a general procedure. On reuse, a new session first searches similar tasks: if a skill hits, follow it; otherwise plan. On correction, after user rejection or execution failure, lower confidence on the matching item or retire it.

    Control logic, not a product API:

    1. on_session_start:
    2. facts = load_scoped_memory(task, user)
    3. skills = search_skills(task_intent)
    4. context = summarize(facts, skills, token_budget)
    5. on_task_end:
    6. delta = reflect(trace, outcome, user_feedback)
    7. if delta.is_fact and delta.has_evidence:
    8. upsert_memory(delta, conflict_policy="flag")
    9. if delta.is_procedure and delta.reusable:
    10. upsert_skill(delta, require_acceptance=true)
    11. if outcome == failure:
    12. mark_lesson(delta, do_not_repeat=true)

    What matters is write policy: no evidence, no store; no acceptance criteria, no skill; no silent overwrite on conflict.

    What cross-session retrieval must solve

    A conversation from weeks ago usually has only a few useful sentences for the current task. Full-text search is good for keyword recovery—“how it was configured then,” “which release failed.” Keywords miss paraphrases, so vector search can be added. Vector hits must return original snippets and dates so the model does not invent from similarity. Filter results again: down-rank stale environment facts, keep retired skills off the execution path, and prefer user preferences over generic style.

    By default, isolate memory by workspace and user. Personal preferences must not leak into shared project memory; project facts must not be written into a private profile. Secrets, tokens, and customer data should be refused, or stored only as pointers such as “configured, location X,” never the secret itself.

    Built-in skills and auto-created skills

    Mature frameworks usually ship high-frequency skills: code review, dependency-upgrade checks, experiment logs, pre-release checklists, literature synthesis. Built-ins set a quality floor: clear steps, checkable outputs, confirmation points for dangerous operations.

    Auto-created skills turn repeated work into assets, but they need a threshold. Extract a skill from traces only after similar tasks succeed a agreed number of times and steps stabilize. Keep the extract as a draft until human or automated tests pass. When sharing, use an open procedure: goal, preconditions, tools, steps, acceptance, risks. Do not export private paths, accounts, or internal addresses from a single conversation.

    Version skills. When the environment changes, old steps can be harmful. Before execution, check that the skill version matches current environment constraints; if not, treat it as reference, not as something to follow blindly.

    Can this replace a stateless coding assistant?

    Do not conclude from the word “memory” alone. If the pain is restating context, continuing work across days, and leaving troubleshooting conclusions for the next person, an agent with layered memory and a skill loop is usually a better fit: state lives outside the session, closer to a colleague who stays on the team. If work is highly one-off, strongly regulated, or must not write long-lived state autonomously, a stateless assistant plus a human-maintained runbook is safer.

    Before replacing anything, run a small A/B, not a demo: the same class of tasks for two weeks. Compare restated instructions, error recurrence, time spent manually editing memory, and incidents caused by wrong memory. The loop is working only if recurrence drops and bad writes can be found and rolled back.

    Accept the bound: this improves external knowledge and process, not the model’s reasoning ceiling. Complex architecture decisions still need human review. Split tool permission, memory-write permission, and command-execution permission so “more remembered” does not become “more able to act” without control.

    A governance checklist for production

    Before go-live, decide: who can change shared memory, how conflicts are arbitrated, how long memory is retained, whether users can view and delete their preferences, who approves skill drafts, and whether failure lessons are visible to everyone. Keep an audit log: which session wrote which fact, on what evidence, and whether it was later revoked. Inject summaries and citations into the prompt; keep raw records in retrievable storage for traceability. Hygiene on a schedule: merge duplicates, clean stale environment facts, and demote unused skills.

    For enterprises, this capability fits existing container platforms, logs and monitoring, and object storage: traces in logs, skills and memory in controlled stores, alerts on abnormal writes and dangerous commands. Use general cloud capabilities; do not tie the design to a proprietary interface. If you use a general cloud such as Baidu AI Cloud, the focus remains isolation, audit, and backup—not treating the memory system as a mysterious model feature.

    Summary

    A self-evolving agent is controlled external memory plus a skill loop: environment facts and user preferences in separate files or tables, scoped injection at session start, history via full-text and semantic retrieval, repeated successful procedures as skills with acceptance criteria, and failures as explicit lessons. It can replace an assistant that starts from zero each time only if writes are auditable, conflicts are visible, and permissions can be revoked. The reason to invest is not “remember more,” but “repeat fewer of the same mistakes.”