Agent Self-Evolution Loop Architecture: How to Design Memory, Skills, and Reflection Subsystems
Most agent frameworks treat a single session as a complete work unit, so context is discarded when the session ends and the agent never moves past its "first day on the job." This article breaks down the architecture of a self-evolution loop built from three subsystems: a memory subsystem that stores factual knowledge about the environment and user under strict character limits, a skills subsystem that automatically distills reusable procedures from execution traces, and a proactive reminder subsystem that triggers reflection at the right moments. It explains snapshot isolation for stable prompts, deduplication and fallback mechanisms for skills, and the production considerations around persistence, asynchronous processing, and monitoring. The core takeaway is that bounded cognition plus automated reflection plus reusable skills is what produces compounding gains over time.
1. The Problem: Agents Forget Everything When the Session Ends
Most agent frameworks assume that a single session is a complete unit of work. The session starts, the system prompt is loaded, and when the session ends, the context is thrown away. This assumption makes implementation simple, but it has an unavoidable consequence: the agent is permanently stuck in its “first day on the job.” Users have to re-explain environment details, project conventions, and tool quirks every time, and the agent repeats the same mistakes over and over.
The common industry workaround is “append-style memory”: continuously writing conversation summaries into a text file and loading the whole file at the start of the next session. This works early on but degrades quickly. The file grows linearly until it becomes a massive document tens of thousands of lines long after a few weeks. Retrieval depends on reading the whole thing or crude keyword matching. Outdated information never retires on its own, so noise mixes with useful information and eventually crowds out the limited context budget.
So the real problem is not “how to remember more,” but “how to continuously retain high-value knowledge under a limited capacity.” That is the starting point for designing a self-evolution loop.
2. Overall Architecture: Three Subsystems Forming a Loop
A working self-evolution loop typically consists of three subsystems, each answering a different question:
- Memory subsystem: stores factual knowledge about the environment and the user, answering “what does this world look like?”
- Skills subsystem: stores reusable procedures, answering “how should this kind of problem be handled?”
- Proactive reminder subsystem: triggers reflection at the right moment, answering “was that experience worth capturing?”
Together they form a loop: execute a task → produce a trace → reminder triggers reflection → distill a skill or update memory → the next task draws on it. Remove any one link and the loop degenerates into an ordinary logging system.
3. Memory Subsystem: Using a Capacity Limit to Force Compression
3.1 Two Files That Draw a Clear Cognitive Boundary
One approach that has proven effective is to maintain only two plain-text memory files: one for environment facts (runtime versions, directory structure, build and dependency quirks, internal project conventions) and one for the user profile (expression preferences, communication style, review habits, working rhythm). The benefit of plain text is transparency and auditability: users can open the files directly, edit them directly, and need no tools to do so.
Example structure:
agent_memory/├── MEMORY.md # Environment facts, project conventions, tool quirks└── USER.md # User preferences, communication style, collaboration habits
Entries are separated by explicit delimiters so the program can parse and replace them one by one, rather than running full-text regex matching.
3.2 A Hard Limit Is a Feature, Not a Constraint
Setting a fairly tight character limit on both memory files (for example, a few thousand characters) is a deliberate design choice. Limited capacity creates three positive pressures:
- Value must be judged before writing, so low-value information is naturally dropped;
- When a new entry conflicts with an old one, it must replace rather than stack, so outdated knowledge retires automatically;
- Retrieval cost stays constant and does not worsen the longer the agent is used.
This is a sharp contrast with append-style memory: the latter has unbounded capacity, while the former makes “forgetting” a first-class citizen.
3.3 Isolating Snapshots from Live State
The implementation maintains two parallel sets of state: a list of entries that can be read and written in real time during a session, and a snapshot frozen at session start. The system prompt uses only the snapshot, while tool calls read and write the live list.
class MemoryStore:def __init__(self, memory_char_limit=2200, user_char_limit=1375):self.memory_entries: list[str] = []self.user_entries: list[str] = []self.memory_char_limit = memory_char_limitself.user_char_limit = user_char_limit# Frozen at session start to keep the prompt stable within a single sessionself._snapshot: dict[str, str] = {"memory": "", "user": ""}def freeze(self) -> None:self._snapshot = {"memory": "\n".join(self.memory_entries),"user": "\n".join(self.user_entries),}
The payoff is determinism: the prompt does not change within a single session, avoiding behavior jitter caused by context drift; cross-session updates take effect by freezing again. When the limit is exceeded, the write function performs compression—merging synonymous entries and dropping low-priority ones—rather than simple truncation.
4. Skills Subsystem: Growing an Operations Manual from Execution Traces
The essential difference between skills and memory is that memory is facts while skills are procedures. A mature skill entry usually contains trigger conditions, pre-checks, a step sequence, failure fallback, and a verification method.
The key design is that skill creation does not depend on manual authoring. In the loop, after a task completes, the reflection step checks whether the trace contains a “non-obvious solution path”—for example, success only after several failed attempts, or an exception that requires a specific handling order. If the condition is met, the trace is compressed into a structured skill, written to the skill library, and retrieved the next time a similar trigger condition appears.
Engineering requires three safeguards:
- Deduplication and merging: when a new skill is semantically close to an existing one, merge them to keep the skill library from bloating;
- Trust annotation: record how often a skill has been invoked and succeeded, and downweight or retire skills with a low success rate;
- Fallback: if a skill invocation fails, fall back to the general reasoning path so that a bad experience is not amplified.
“Gets more capable the longer you use it” is not marketing language but a direct result of these mechanisms: the size and hit rate of the skill library improve monotonically with use, and the cost of a single skill is very low.
5. Proactive Reminder Subsystem: Making Reflection Actually Happen
Reflection without a trigger never happens. A workable approach is to add lightweight reminder logic: after a long task ends, after two or more consecutive failures, or after an explicit user correction, insert a judgment of “is this worth capturing?” The result is one of three: write to memory, distill a skill, or do nothing. Keeping “do nothing” as the default option significantly reduces noisy writes.
6. Implementation Advice and Cloud Support
To run this loop in production, there are four things to watch. First, memory and skill files need persistence; object storage or file storage can provide scheduled backups and versioning. Second, reflection and distillation add extra inference overhead, so they can be made asynchronous through a message queue to avoid blocking the main path. Third, metrics such as skill hit rate and memory compression count should be wired into logging services and monitoring alerts to assess whether the loop is actually converging. Fourth, if you deploy on a container platform, read-write consistency must be guaranteed for the same user session.
For users who do not write code, these capabilities can be packaged as default behavior in a higher-level product: users simply describe the task as usual, and capturing, retrieval, and reflection are all handled by the system, with no need to understand the underlying file structure. This is also a necessary step for self-evolution capabilities to move from developer tools toward general-purpose intelligent coding tools and office assistance scenarios.
7. Conclusion
The core of a self-evolution loop is not “bigger memory,” but “bounded cognition + automated reflection + reusable skills.” Limited capacity forces compression, snapshot isolation guarantees stability, and the reminder mechanism guarantees that reflection happens; only when the three stack together does an agent gain the compounding effect of accumulating value over time.
