Agent Self-Evolution Loop Architecture: How to Design Memory, Skills, and Reflection Subsystems

    This article breaks down a practical architecture for an agent self-improvement loop built from three cooperating subsystems: memory, skills, and proactive reminders. It explains why stateless agents lose context between sessions, why appending all history to one long file creates new engineering problems, and how a hard character limit forces information compression. You will also see how dual-file entry-based storage, session snapshots for consistency, parameterized skill entries in a pending-verification state, and decoupled reminder triggers work together, along with deployment pitfalls around latency, observability, privacy, evaluation, and cloud portability.

    1. The Problem: Agents “Forget” the Moment a Session Ends

    Most agent frameworks separate reasoning from persistence. Within a single session, an agent can call tools, break down tasks, and produce results. But once the session context is released, everything learned in that round disappears. The next session starts from zero, and the user has to repeat environment constraints, coding conventions, and personal preferences. This stateless design is simple to implement and friendly to horizontal scaling, but it shifts the entire cost of long-term collaboration onto the human.

    A common industry workaround is to append all history to one long text file. It does solve the “remembering” problem, but it introduces three new engineering problems. First, the file grows linearly over time and eventually becomes a giant document tens of thousands of lines long. Second, retrieval depends on reading the whole thing or crude keyword matching, and the noise ratio keeps climbing. Third, outdated information piles up with the same weight as valid information, diluting the model’s attention and actually lowering answer quality.

    So the real technical question is not “should we build memory,” but: how do you design a constraint mechanism that lets an agent automatically filter, compress, and reuse information under a limited capacity? The rest of this article uses the collaboration of three subsystems as the main thread to present a deployable architectural pattern.

    2. Overall Architecture: Three Subsystems Forming a Loop

    A usable self-improvement loop has to answer three questions at once: what to remember, how to reuse it, and when to reflect. That maps cleanly onto three subsystems, each with a single responsibility and a clear boundary.

    • Memory subsystem: stores “facts.” Environment information, project conventions, special tool behaviors, and user preferences and communication habits.
    • Skill subsystem: stores “methods.” It abstracts the successful path and the pitfalls of a specific task into a parameterized, reusable operating procedure.
    • Proactive reminder subsystem: stores “timing.” It holds no content; it only triggers a review at the right moment, so reflection does not depend on the model “remembering” to do it.

    Together they form a loop: a reminder triggers a review, the review produces structured entries, the entries land in memory and skills, and the next task consumes those entries. Remove any one link and the loop degrades into heuristics that only work occasionally.

    3. Memory Subsystem: Using a Hard Capacity Limit to Force Compression

    3.1 Two Files and Entry-Based Storage

    A restrained approach is to split memory into two plain-text files: one holding the agent’s understanding of the environment, one holding its understanding of the user. Entries are separated by explicit delimiters rather than relying on natural-language paragraphs. The benefits are low parsing cost, diffability, and easy human review and correction.

    An illustrative directory layout and format:

    1. ~/.agent/memories/
    2. ├── MEMORY.md # Environment facts, project conventions, tool quirks
    3. └── USER.md # User preferences, communication style, collaboration habits
    1. [entry] Build steps must push the image first, then roll out
    2. [entry] The default branch of this repo is protected; direct pushes are forbidden

    3.2 Why the “Limit” Is a Feature, Not a Flaw

    Setting a fairly tight character limit on both files (for example, on the order of a few thousand characters) turns “memory management” from a vague soft requirement into a decidable hard constraint. When remaining space runs low, the agent must do three things: decide whether new information is genuinely important, merge multiple fragments into one high-density conclusion, and delete old entries already superseded by newer facts.

    This contrasts sharply with the append-only model: there, information entropy rises monotonically, while here it stays at an approximate steady state. In engineering terms, the write path can be described as “compress first, evict second, write last,” and eviction actions should keep an audit log so mistaken deletions can be traced.

    3.3 Dual State: Live Entries and Session Snapshots

    An easily overlooked detail: memory should not be rewritten arbitrarily mid-session and immediately affect the system prompt, or behavior within the same session becomes self-contradictory. A workable approach maintains two parallel states — a writable list of live entries, and a snapshot frozen at session start.

    1. class MemoryStore:
    2. def __init__(self, memory_char_limit=2200, user_char_limit=1375):
    3. self.memory_entries = [] # live, writable
    4. self.user_entries = []
    5. self.memory_char_limit = memory_char_limit
    6. self.user_char_limit = user_char_limit
    7. # Frozen at session start to keep consistency within a session
    8. self._prompt_snapshot = {"memory": "", "user": ""}
    9. def commit_snapshot(self):
    10. self._prompt_snapshot = {
    11. "memory": "\n".join(self.memory_entries),
    12. "user": "\n".join(self.user_entries),
    13. }

    Using the snapshot inside a session and committing once at session end is a practical compromise between consistency and learnability.

    4. Skill Subsystem: Turning Pitfall Experience into Reusable Capability

    Memory answers “what the facts are”; skills answer “what to do next time.” A skill entry is valuable because it contains step ordering, preconditions, and failure-point warnings, not a single conclusion. A qualified skill entry typically includes: applicable scenario, pre-checks, operating steps, rollback method, and known pitfalls.

    The generation flow can be abstracted into four steps: after a task ends, extract the key decision points from the trajectory; parameterize concrete values (rewrite “push the feature branch” as “push the current working branch”); deduplicate and merge with existing skills; and run an executability self-check before writing. It is worth stressing that auto-generated skills should default to a “pending verification” state and only gain confidence after several successful reuses, so wrong experience is not amplified and spread.

    5. Proactive Reminder Subsystem: Making Reflection Independent of Chance

    The biggest enemy of reflection is forgetting. The reminder subsystem does not need to be complex: it can be a fixed-step trigger, an idle-time trigger, or a task-failure trigger. The key design is decoupling the trigger signal from the content — it only emits a structured event, and the main flow decides whether to actually run the review, which avoids frequently interrupting normal tasks. In engineering terms, a cooldown window and a daily quota are recommended to prevent reminder storms from driving up wasted overhead.

    6. Implementation Notes and Common Pitfalls

    • Balancing capacity and latency: the longer the injected memory, the higher the prompt cost and response latency, so treat the limit as a performance parameter, not just a content parameter.
    • Observability: instrument writes, compression, eviction, and skill invocations separately, and pair them with a logging service and monitoring alerts, so you can tell whether the loop is actually converging.
    • Privacy and permissions: memory files are sensitive data and should support encrypted storage, per-project isolation, and one-click clearing.
    • Isolation and evaluation: build an offline evaluation set for “whether learning works,” and use fixed tasks in regression comparisons with the loop on versus off, instead of judging by feel.
    • Combining with general cloud capabilities: the stateless compute layer can run on a container platform, memory and skill files are suited to object storage with versioning, task events can be decoupled through a message queue, and the whole system stays replaceable and portable.

    7. Conclusion

    The divide between “fed by humans” and “grows on its own” is not a feature checklist; it is whether learning is written into architectural constraints. Capacity limits, entry-based formats, snapshot consistency, pending-verification skills, and decoupled reminders — these five things together determine whether an agent can stay stable and keep getting stronger over long-term use. For developers, landing the smallest viable loop first and then tightening the policy step by step with evaluation data is the lowest-risk path.