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

    Most agent frameworks run stateless sessions: context is dropped when a conversation ends, so the agent starts from zero every time and users must repeat the same project conventions, tool quirks, and preferences. This article breaks down a general architecture for a self-improving loop built from three subsystems—memory, skills, and proactive reminders—and explains the engineering details behind each: dual memory files with hard capacity limits, skill entries that capture reusable procedures, throttled reflection triggers, snapshot-based read/write separation, observability, and safety boundaries. It is written for engineers designing AI agents that accumulate capability through real usage instead of relying on hand-written documentation.

    1. The Problem: Agents Forget Everything When the Session Ends

    Most agent frameworks today use a stateless session design: context is discarded at the end of each conversation, and the next run starts from scratch when it comes to understanding the environment and the user. This model is simple to implement and keeps privacy under control, but the cost is that capability never accumulates. Users have to restate the same project conventions, the same tool quirks, and the same preferences over and over, while the agent keeps stepping into the same traps.

    Two approaches have emerged in the industry. The first is manual feeding: developers hand-write rule files, prompt templates, and operating manuals, and the agent follows the documentation. Its ceiling is the ceiling of the documentation—scenarios that were never written down are scenarios the agent cannot handle, and where the documentation is wrong, the agent executes the wrong thing faithfully. The second is automatic growth: the agent summarizes its own experience after completing a task, turning a one-off mistake into reusable capability. This article focuses on the second approach, abstracts it into a general architecture, and expands on the implementation details layer by layer.

    2. Overall Architecture: Three Subsystems, One Loop

    A working self-improvement loop is typically made up of three subsystems, each answering one question: what to remember, what to reuse, and when to look back and tidy up.

    • Memory subsystem: answers “which facts about the user and the environment are worth keeping long term.”
    • Skill subsystem: answers “which ways of doing things are worth solidifying into callable steps.”
    • Proactive reminder subsystem: answers “when to trigger review and consolidation.”

    Strung together, the three form a loop: memory and skills are read during task execution → experience is distilled after the task ends → the reminder mechanism triggers consolidation at the right moment → the consolidated result is written back into memory and skills → the next task calls on them. What makes the loop work is not how clever any single module is, but whether the write path has low enough friction and the read path is short enough.

    3. Memory Subsystem: Using Capacity Limits to Force Information Compression

    The easiest way to get memory design wrong is to make it append-only. Pure appending feels great early on, but after a few months it swells into a long document that is hard to search, retrieval cost grows linearly over time, and there is no way to automatically arbitrate when old information conflicts with new.

    A more robust approach is two files, hard limits, and itemized entries:

    1. ~/.agent/memories/
    2. ├── MEMORY.md # Environment facts, project conventions, tool quirks
    3. └── USER.md # User preferences, communication style, working habits
    • MEMORY faces the “world”: it records environment facts, such as build commands, directory conventions, and the behavioral characteristics of external dependencies.
    • USER faces the “person”: it records collaboration preferences, such as whether the user wants conclusions first or derivations first, and whether changes require confirmation beforehand.

    A hard limit (for example, on the order of a few thousand characters) is not a compromise but a design tool: limited capacity forces the agent to summarize and make trade-offs, outdated entries get naturally pushed out, and what remains is high-density fact. Three engineering points support this.

    First, itemize rather than use paragraphs. Only when entries are split with explicit separators can you replace or retire a single entry instead of rewriting the whole document.

    Second, isolate snapshots. Freeze a snapshot of the system prompt at session start; real-time entries can be written during the session, but the current turn reasons over the snapshot, which avoids inconsistent behavior caused by memory drift within the same session:

    1. class MemoryStore:
    2. def __init__(self, memory_limit=2200, user_limit=1375):
    3. self.memory_entries = []
    4. self.user_entries = []
    5. self.memory_limit = memory_limit
    6. self.user_limit = user_limit
    7. self._snapshot = {"memory": "", "user": ""}
    8. def freeze(self):
    9. self._snapshot = {
    10. "memory": "\n".join(self.memory_entries),
    11. "user": "\n".join(self.user_entries),
    12. }

    Third, evaluate before writing. Before adding an entry, check “whether a synonymous entry already exists” and “whether it conflicts with an existing entry,” then update or replace rather than blindly appending.

    4. Skill Subsystem: Turning Lessons Learned into Callable Assets

    A skill is the carrier of a “way of doing things,” with a granularity larger than a single fact and smaller than a complete solution. A qualified skill entry typically contains: applicable conditions, pre-checks, a step sequence, failure fallback, and verification.

    1. Skill entry structure (illustrative)
    2. - Name: Image-first release
    3. - Applies to: Containerized deployment
    4. - Pre-check: Confirm the image registry is reachable
    5. - Steps: Build → Push → Update orchestration → Rolling verification
    6. - Fallback: Keep the previous image tag
    7. - Verification: Health checks and probing of key endpoints

    The skill library needs governance, or it degrades into a documentation dump. Three mechanisms are recommended: deduplication and merging (semantically similar skills are merged into one entry with branch conditions preserved), hit-rate tracking (skills with zero calls over a long period are down-weighted or archived), and version marking (skills are updated as the environment evolves, with change notes retained).

    5. Proactive Reminder Subsystem: Making Consolidation Happen at the Right Time

    Most self-improvement efforts fail not because the agent cannot summarize, but because it never summarizes. The proactive reminder mechanism triggers a review at a task’s “learnable moments,” for example: the task involves retries, the task takes significantly longer than expected, the user issues a correction, or the same type of task recurs within a short period.

    After a trigger, the system should not write to the store immediately but go through three steps: candidate generation (what reusable information came out of this) → candidate filtering (is it general, or just a one-off) → persist or discard. To avoid being intrusive, reminders should support throttling and batching, merging multiple candidates into a single consolidation pass.

    6. Engineering Checklist for Closing the Loop

    • Separate reads from writes: read the snapshot during the turn, merge and write at the end of the turn to guarantee consistency.
    • Hard capacity constraints: set limits for memory, and quantity and length thresholds for skills.
    • Observability: record skill hit rates, reasons for memory eviction, and the number of reminder triggers.
    • Safety boundaries: redact sensitive information before storing it, and support per-entry deletion and export.
    • Packaging for non-developers: wrap skill library and memory management as visual configuration and templates so people who do not write code can maintain them too—this is also the key step toward broader adoption of this kind of capability.

    7. Conclusion

    The divide between “feeding by hand” and “growing on its own” is fundamentally a difference in where the capability ceiling comes from. With the former, the ceiling is set by the documentation; with the latter, it is set by the quality of the loop. Make memory high-density, make skills reusable, and make reminders a restrained trigger, and an agent can keep accumulating through real usage instead of starting from zero every time.