Agent Architecture with Self-Evolution: From Stateless Chat to Persistent Skills and Memory

    This article breaks down why mainstream conversational AI forgets everything after a session ends, and what it takes architecturally to build an agent that accumulates experience. It covers the closed learning loop that turns successful task traces into reusable, parameterized skill files; the offline optimization of prompts and skills through a mutate-evaluate-select search; a three-layer memory model spanning working memory, long-term semantic memory, and external knowledge sources; and the decoupling of reasoning, memory, skill, and tool layers through clear contracts. It also lists practical guardrails such as confidence thresholds, human review, rollback-friendly version control, and observability first.

    1. The Root Cause: Why Conversational AI Forgets Everything

    In the previous session, the model worked with you back and forth to produce a complex automated deployment script. Close the window, reopen it, and it is back to factory settings, with no knowledge of your preferences, prior agreements, or project context. This is not a shortcoming of one particular model but an architectural outcome of mainstream conversational AI today: session state lives only within the lifecycle of a single request and is released when the request ends. The model itself writes no long-term state.

    In engineering terms, such a system behaves like a stateless function: the output depends only on the current input and fixed parameters, and history takes no part in the computation. This buys excellent horizontal scalability and privacy control, at the cost that experience cannot accumulate. Users pay a context-rebuilding cost on every interaction: pasting code, restating conventions, correcting the same misunderstanding again.

    Moving AI from a passive tool to a growth-oriented digital counterpart that retains working habits requires three things at the architecture level: turning execution results into reusable capabilities (a learning loop), persisting cross-session information and making it retrievable (layered memory), and decoupling learning, memory, and reasoning (clear boundaries). Each is covered below.

    2. Closed-Loop Learning: Turning Task Experience into Reusable Skills

    The execution path of a traditional agent is linear: receive instruction → plan steps → call tools → return result. When the task ends, the reasoning and trial-and-error along that path are discarded. The change in a growth-oriented architecture is to add a return path at the end of the chain: once a task is judged successful, an experience-consolidation process is triggered.

    A workable loop usually has four stages:

    1. Trace collection: record the task input, the tool call sequence, failed retries, and the final successful path.
    2. Experience distillation: extract the key decision points and preconditions from the trace, discarding one-off accidental factors.
    3. Skill consolidation: write a structured skill file containing applicable scenarios, pre-checks, execution steps, rollback plan, and caveats.
    4. Load and reuse: when a similar scenario is hit again, load the skill first, skip the lengthy reasoning, and go straight to execution.

    A skill file should not be a running log but a parameterized operating manual. Example:

    1. ---
    2. name: container_deploy
    3. triggers: ["deploy", "release", "containerized release"]
    4. params: {image_name, tag, replicas, env}
    5. ---
    6. 1. Validate that params are complete; confirm missing items with the user
    7. 2. Build and tag the image: {{image_name}}:{{tag}}
    8. 3. Apply the orchestration config with {{replicas}} replicas
    9. 4. If the health check fails, roll back to the previous version
    10. notes: in production, confirm resource quotas and canary strategy first

    Parameterization yields two direct benefits: a wider reuse radius, since the same skill fits different projects, and portability, since skills exist as plain text in an open description format and can be migrated and shared across agent runtimes instead of being locked to a single one.

    The boundary of automation needs emphasis. Automatically generated skills introduce the risk that wrong experience gets reused repeatedly, so engineering practice should set three gates: a confidence threshold (a skill is generated only after success rate and repeat-hit counts meet the bar), human review (changes merge much like a code review), and rollback-capable version management (skill files go under version control so a regression can be reverted quickly). Without these three gates, “self-evolution” easily degrades into “self-pollution.”

    3. Automatic Optimization of Prompts and Skills: Iteration Speed with Control

    Beyond skill files, system prompts and tool descriptions are also optimizable. The industry has approaches that model prompt optimization as a mutate-evaluate-select search: maintain a set of candidate prompts, score them on a task set, keep the solutions that win on multiple metrics (the Pareto front), and converge generation by generation. Compared with reinforcement-learning-style fine-tuning, this kind of method needs no GPU training and iterates through inference APIs alone, so trial-and-error is cheap and results come fast.

    Optimization, however, must be offline in execution and controlled in production:

    • Optimization runs in an isolated environment over a historical task set and never touches production traffic directly.
    • Outputs are submitted as change proposals and take effect only after human review.
    • An evaluation baseline is kept; every prompt or skill change is compared against key metrics (task success rate, average number of steps, human intervention rate), and a regression blocks the merge.

    This constraint ensures the system’s direction of growth is set by people rather than decided by metric drift on its own.

    4. Three-Layer Memory: Continuity from Within a Session to Across Sessions

    Skills alone do not amount to “knowing you.” A complete memory system is usually split into three layers:

    • Working memory: the current session context, limited in capacity and shortest in lifecycle, responsible for present reasoning.
    • Long-term semantic memory: factual information such as user preferences, project conventions, and technology-selection decisions, stored as structured entries and retrievable by tag and similarity.
    • External memory and knowledge access: plugins or connectors pull from external sources such as document repositories, code repositories, and ticketing systems on demand, avoiding stuffing all information into the context.

    For retrieval, the industry commonly uses a hybrid of semantic and keyword search, together with reranking and context-budget control, injecting only a few of the most relevant fragments into the prompt. Engineering practice also needs explicit write and forgetting rules: which information may be kept long term, which needs periodic expiry, and how users can view and delete it. What can be remembered must be auditable and revocable; that is the prerequisite for long-term usability.

    5. Architectural Decoupling: Letting the Three Capabilities Evolve Independently

    If learning, memory, and reasoning are kneaded into a monolith, any change in one place pulls on everything. The goal of decoupling is to define clear contracts:

    • Reasoning layer: responsible for planning and decisions, depending only on a standardized context interface.
    • Memory layer: provides write, retrieval, and expiry capabilities, hiding the storage implementation from the layer above (local files, a relational database, object storage, or a vector retrieval service are all interchangeable).
    • Skill layer: describes capabilities with files and metadata, supporting hot loading and version switching.
    • Tool layer: unified description interfaces and permission declarations, with sensitive operations requiring explicit authorization and audit logs.

    The direct payoff of decoupling is replaceability and observability: the storage backend can migrate smoothly as data grows, skills can be released gradually, and calls across the whole chain can be traced. With logging services and monitoring alerts, a team can pinpoint which skill or which piece of memory caused a behavior regression.

    6. Implementation Advice and Common Pitfalls

    1. Solve observability before self-evolution: without trace records and metric baselines, automatically generated experience cannot be validated.
    2. Keep skills few and refined: consolidate high-frequency tasks with stable steps and controllable failure costs first.
    3. Minimize memory: store only necessary facts, and mask or handle sensitive information locally.
    4. Keep humans in the loop: route key changes through review and keep a second confirmation for high-risk operations.
    5. Control cost: bring retrieval budget, context length, and call counts under quota management, and run the runtime and data layers on general cloud capabilities such as container platforms, message queues, and object storage.

    The value of a growth-oriented agent lies not in being “better at chatting” but in turning one-off collaboration into accumulating organizational assets: experience becomes skills, preferences become memory, and changes become reviewable versions. Only when these three have clear boundaries and audit mechanisms does AI truly move from tool to a digital counterpart that keeps evolving and understands you better the more you use it.