Agent Self-Evolution Loop: How Memory and Skill Distillation Mechanisms Work
This article breaks down the engineering design of a self-evolving agent loop built around three cooperating subsystems: memory, skills, and reminders. It explains why the common "one session, one context" model caps agent capability, contrasts rule files and append-only logs as inadequate fixes, and shows how hard character limits, session-level snapshots, dual-trigger skill distillation, and forced routing of review output turn one-off execution traces into reusable assets. Readers will find the overall data flow, a memory store code example, a skill entry template, observability and cost-control practices, and a staged rollout path that also works for non-programmers.
1. The Problem: Agents Forget Everything When the Session Ends
Most mainstream agents today follow a “one session, one context” model: the prompt and history are loaded when the session starts and discarded when it ends. This creates a structural flaw — the agent cannot accumulate experience from past executions. Every time a user starts a new task, the agent begins from scratch, steps on the same landmine again, and asks about the same preference again.
Two workarounds are common in the industry. The first is hand-fed rules: developers write rule files that spell out workflows, conventions, and caveats one by one. The ceiling here is obvious — the agent knows only what you wrote, and the rule file bloats quickly with each maintenance cycle. The second is append-everything logging: all history is piled into a single file, which grows to tens of thousands of lines within months, so retrieving one old fact means reading the whole thing, with far more noise than signal.
The real fix is not a bigger context window but a learning loop: let the agent automatically distill experience from execution into reusable assets and revisit them at the right moment. Using a general architecture in which memory, skills, and reminders cooperate, this article unpacks the engineering essentials of that loop layer by layer.
2. Overall Architecture: Three Subsystems, One Loop
The self-evolution loop consists of three subsystems with clear responsibilities and no coupling between them:
- Memory subsystem: stores facts, answering “who you are, what the environment looks like, what the conventions are.”
- Skill subsystem: stores methods, answering “how was this class of problem solved last time.”
- Reminder subsystem: stores timing, answering “when should we stop and summarize.”
The data flow across the three is a one-way reinforcing loop: execute a task → produce a trace → the reminder subsystem triggers a review → distilled output is written to memory or skills → the next task loads these assets → execution efficiency improves → new traces are produced. The key to the loop is that the distillation step must be automated; otherwise the loop degenerates into a manually maintained rule base.
3. Memory Subsystem: Trading a Hard Capacity Limit for Information Density
The first principle of memory design is restraint. The approach that has proven effective in practice is to keep only two plain-text files, with entries separated by a consistent delimiter:
~/.agent/memories/├── MEMORY.md # Environment facts, project conventions, tool quirks└── USER.md # User preferences, communication style, work habits
The real design insight is that the character limits are deliberately set tight — around 2200 characters for environment memory and around 1375 for the user profile. This is not laziness; it turns “what to remember” into a continuous prioritization contest. With limited capacity, the agent must judge which fact matters more for downstream decisions, and low-value entries are naturally pushed out. By contrast, the problem with append-only mode is not forgetting too little but remembering too much, which collapses the signal-to-noise ratio.
In implementation, memory storage typically maintains two parallel states: a list of entries that can be read and written in real time, and a snapshot frozen at session start.
class MemoryStore:def __init__(self, memory_char_limit=2200, user_char_limit=1375):self.memory_entries = [] # Live, writable entriesself.user_entries = []self.memory_char_limit = memory_char_limitself.user_char_limit = user_char_limitself._snapshot = {"memory": "", "user": ""} # Session-level frozen snapshot
The snapshot mechanism solves a consistency problem: entries written mid-session should not silently change the system prompt within the current round, or the model will contradict itself in the same session. Writes land in the entry list first, and the snapshot is frozen again at the next session, producing semantics that are “stable within a round, evolving across rounds.”
Three more things are needed in engineering: deduplication and near-synonym merging of entries, timestamp-based selection among conflicting entries, and an eviction policy for over-limit cases (scored by recency of use and breadth of impact). These three points determine whether memory is an asset or a liability.
4. Skill Subsystem: Turning a One-Off Mistake into a Reusable Method
If memory is a pocket notebook, a skill is an operations manual. The minimal structure of a skill entry should contain four parts: applicable conditions, steps, failure signals, and fallback. The failure signal is the most easily overlooked part yet the most valuable — it lets the agent recognize early in a similar problem that “this time is different from last time.”
Dual triggers are recommended for generating skills: distill a positive skill when a task succeeds and the path was non-trivial; distill a negative skill (that is, “do not do this”) when a task fails and the root cause has been identified. The distilled output first goes to a candidate area and is promoted to a formal skill only after being hit repeatedly several times, which prevents a one-off incidental experience from polluting the manual.
Skill entry template- Name: Pre-flight checks for container image release- Applies to: Image pull failures during the release workflow- Steps: 1) Verify the image tag 2) Push the image 3) Run the deployment- Failure signal: Deployment reports a missing image layer- Fallback: Roll back to the previous version and keep the logs
5. Reminder Subsystem: Making Summarization a Scheduled Action
Experience does not arise on its own; it needs an alarm clock. The reminder subsystem does not have to be complex — three strategies are at its core. First, periodic review, triggered by a fixed number of rounds or a time window. Second, event-driven triggering, fired immediately on task failure, user correction, or a repeated question. Third, budget control, capping the tokens and write volume of a single review so the loop itself does not become a cost black hole.
The output of a review must be routed mandatorily: facts go to memory, methods go to skills, and timing adjustments change the reminder frequency. Without this step, a review is just another piece of discarded context.
6. Observability and Cost Control
The biggest risk of a self-evolving system is that it becomes unexplainable: capability improves, but nobody knows why. It is advisable to audit all write operations, recording at least four items: source task, trigger type, write type, hit count, and eviction reason. Combined with a layered loading strategy — only high-hit entries stay resident, and the rest are retrieved on demand — this keeps a high signal-to-noise ratio within a limited context budget.
7. Rollout Advice and Usability for Non-Programmers
For teams, the recommended rollout order is: memory and snapshots first, then skill candidates and promotion, and finally reminders and auditing. Each step delivers benefits that can be verified independently. So that users who do not write code can benefit too, these capabilities can be packaged on top of general-purpose categories on a cloud platform — for example, using object storage to hold memory and skill files, a message queue to drive review tasks, a container platform to host the runtime, and logging plus monitoring and alerting for auditing and budget alerts. This turns “self-evolving” from an engineering capability into a default product capability.
8. Conclusion
The essence of the self-evolution loop is replacing manual feeding with architectural constraints: capacity limits force information compression, the snapshot mechanism guarantees session consistency, dual-trigger distillation turns mistakes into assets, and reminders plus auditing keep the whole process sustainable and explainable. Get these four things right, and an agent genuinely becomes more capable the longer you use it.
