Agent Self-Evolution Loop Architecture: Memory, Skills, and Triggers
This article breaks down the architecture of a self-evolving AI agent loop built from three subsystems: memory, skills, and triggers. It explains why session-bound context is the core bottleneck, how hard capacity limits force memory compression, how session-level snapshots keep behavior consistent, and how reusable skills are generated, retrieved, and quality-controlled. It also covers trigger design, cold start, privacy, observability, evaluation, and running the loop on cloud infrastructure.
1. The Problem: Agents Forget Everything When the Session Ends
Most mainstream agent frameworks separate reasoning from memory. Within a single session, an agent can read files, run commands, and call APIs, but once the session ends, the context is reclaimed and the next run starts from a blank slate. In practice, developers watch the same agent repeat the same environment probing, the same build errors, and the same deployment order every week.
Two common workarounds exist in the industry. The first is hand-written skill files: structured documents that tell the agent how to handle a certain class of task. The second is append-only, log-style memory that dumps every historical conversation and fact into a single text file. The first approach caps capability at what a human has written — if it is not documented, the agent cannot do it. The second approach suffers from continuously rising entropy: retrieval cost grows linearly over time, and after a few months the file swells to tens of thousands of lines, so finding one key convention requires reading the whole thing.
The real question is not whether to store, but what to store, how to compress it, when to revisit it, and how to reuse it. The goal of a self-evolution loop is to turn experience into a first-class citizen that is searchable, callable, and evictable.
2. Overall Architecture: Three Subsystems Forming a Loop
A self-improving agent is typically built from three interlocking subsystems, none of which can be missing:
- Memory subsystem: stores facts, answering “what are the objective conditions of this environment and this person?”
- Skill subsystem: stores methods, answering “how was this class of problem solved before?”
- Trigger subsystem: initiates review at the right moment, answering “is there anything worth recording right now?”
Together they form a loop: task execution produces a raw trajectory → the trigger subsystem initiates a review during task wrap-up → the memory subsystem extracts high-value facts and compresses them into storage → the skill subsystem solidifies reusable steps into skills → the next task hits existing memory and skills directly, reducing trial and error. The key to the loop is not writing but whether reads actually hit, which makes retrieval and eviction as important as the write path.
3. Memory Subsystem: Using Hard Capacity Limits to Force Compression
3.1 A Minimal Storage Structure
One approach that has proven effective is to maintain only two plain text files: one for environment facts (project conventions, tool quirks, paths and dependency versions) and one for the user profile (preferences, communication style, collaboration habits). Entries are separated by a consistent delimiter, avoiding the operational overhead of introducing a database.
A representative structure:
memory/├── MEMORY.md # Environment facts: project conventions, tool behavior, common pitfalls└── USER.md # User profile: preferences, expression habits, working style
3.2 Capacity Limits Are Part of the Design
Setting a fairly tight character limit on both files (for example, a few thousand characters) is not a compromise but the core mechanism: because capacity is finite, every write must first answer “is this information more important than an existing entry?”, which naturally produces compression and eviction. This contrasts sharply with append-only mode, where the cost is deferred to read time and ultimately paid by every retrieval.
In engineering terms, bounded writing can be expressed with the following pseudocode:
class MemoryStore:def __init__(self, fact_limit=2200, user_limit=1375):self.facts = [] # live writable entriesself.users = []self.fact_limit = fact_limitself.user_limit = user_limitself._snapshot = {"facts": "", "users": ""} # session-level frozen snapshotdef add(self, text, limit, entries):if len(text) + sum(len(e) for e in entries) > limit:# trigger compression: merge synonymous entries, drop low-value onesentries = self._compress(entries, limit - len(text))entries.append(text)
3.3 Snapshot Isolation for In-Session Consistency
An easily overlooked detail: memory written mid-session should not immediately change the current system prompt, otherwise the agent’s behavior drifts within the same task. A common practice is to keep two parallel states — a live entry list and a snapshot frozen at session start. The current session reads only the snapshot, and new entries take effect in the next session. This preserves reproducibility and makes debugging easier.
4. Skill Subsystem: Turning Experience from Documents into Callable Assets
A skill is a level of abstraction above a fact: facts describe “what is”, skills describe “how to do it”. A qualified skill typically contains five elements: trigger conditions, pre-checks, a step sequence, failure fallback, and verification.
Generation should be automatic: after a task finishes, whether it succeeded or failed, the review step extracts the transferable parts from the trajectory, strips temporary details tightly bound to that specific task, and produces a structured skill entry for storage. For retrieval, a hybrid strategy of semantic similarity plus tag matching is recommended, so that relying on keywords alone does not cause missed recall.
Quality control matters: without review and deduplication, a skill library is quickly polluted by highly similar junk entries. Viable strategies include merging by similarity threshold, ranking by usage frequency, tracking failure rates, and periodic archiving.
5. Trigger Subsystem: Making Review Scheduled and Low-Cost
The most common failure mode in self-evolution is that nobody reminds the agent to review. Triggers can be time-driven (fired after a number of task rounds), event-driven (fired after task failure, retries exceeding a threshold, or a user correction), or budget-driven (fired when accumulated saved tokens reach a threshold). In engineering terms, review should be an independent, rate-limited, interruptible background process so it never blocks the main task path.
6. Implementation Notes and Common Pitfalls
- Cold start: memory and skills are empty at the beginning, so allow “blank runs” that complete tasks with general capability, then accumulate gradually.
- Privacy and compliance: user profile information should support one-click viewing, editing, and deletion, and sensitive information should not enter memory by default.
- Observability: instrument memory writes, skill hits, and review triggers so you can quantify whether “getting stronger with use” is actually happening.
- Working with general cloud capabilities: memory and skill files can live in object storage for persistence and versioning, review jobs can use a message queue to smooth out spikes, runtime metrics can feed into logging and monitoring services, and container platforms can host the stateless execution environment.
- Evaluation loop: keep a fixed regression task set and run it after every change, so the self-evolution process does not evolve capability in the wrong direction.
7. Conclusion
The essence of self-evolution is not making the model smarter but giving the engineering system the ability to not lose experience, to compress experience, and to reuse experience. Keep memory small, keep skills structured, and make review a habit, and any agent can keep getting stronger in real use. On cloud platforms such as Baidu AI Cloud, general capabilities like object storage, message queues, container platforms, and monitoring alerts let this loop run more reliably, more cheaply, and with less operational effort.
