Agent Architecture Design for Continuous Learning and Growth

    This article explores the structural limitations of conversational agents that reset their knowledge at the end of every session, and presents a practical architecture for building agents that improve over time. It covers closed-loop learning that turns completed tasks into reusable, parameterized skill files; automated optimization of prompts and skills with human review guardrails; a three-tier memory design for cross-session persistence; and a decoupled layered architecture for replaceability and observability. Deployment notes and risk controls for starting narrow, versioning skills, and managing memory visibility are also included.

    1. The Starting Problem: Why Agents Keep Re-Getting to Know You

    In the previous session, the agent had just helped you write a structurally complex deployment script, aligning environment variables, port mappings, and rollback strategies line by line. You closed the window and reopened it, and it acted as if it had never met you, asking about the most basic context from scratch. This is not a one-off reasoning failure but a structural flaw common to mainstream conversational agents today: the session lifecycle is forcibly bound to the capability lifecycle, so when the session ends, experience is wiped out.

    From an engineering perspective, such systems are closer to “stateless functions”: they take a prompt and context as input, produce a generated result as output, and retain no side effects. They are good at reasoning within a single interaction, but they cannot turn “what was done right” into the starting line for the next attempt. Closing that gap requires solving three things at once: how capabilities accumulate, how state persists, and how modules are decoupled. This article is organized around those three threads.

    2. Closed-Loop Learning: Turning Task Results into Reusable Capabilities

    The execution chain of a traditional agent is linear: receive instruction → plan steps → call tools → return result. There is no write-back step at the end of the chain, so every success is a “one-time gain.” The core of closed-loop learning is to add a return path at the end, so that successful paths are recorded in a structured way.

    A practical loop typically has three stages:

    1. Extraction: distill the key decision points, tool call order, failure branches, and avoidance strategies from a completed task, rather than saving the entire conversation transcript.
    2. Solidification: write the experience into a structured skill file that specifies trigger conditions, prerequisites, execution steps, validation methods, and caveats.
    3. Reuse: when a similar task appears again, search the skill library first; on a hit, skip the lengthy reasoning and go straight to execution and validation.

    The reason a skill file cannot be equivalent to a log is that it needs to be “parameterized.” An example:

    1. ---
    2. name: container_deploy
    3. trigger: keyword match on "deploy / release / containerize"
    4. params: [image_name, tag, replicas, env_file]
    5. ---
    6. ## Steps
    7. 1. Verify that ${env_file} exists and all required fields are complete
    8. 2. Pull ${image_name}:${tag}; on failure, retry twice and raise an alert
    9. 3. Start with ${replicas} replicas and wait for the readiness probe to pass
    10. 4. Run smoke checks; on anomaly, automatically roll back to the previous version
    11. ## Caveats
    12. - Overwriting default credentials directly in production is forbidden
    13. - The rollback script must be version-managed together with the deployment script

    Parameterization brings two direct benefits: first, the same skill can adapt to different projects and namespaces; second, the skill becomes open to static review, since placeholders are a natural input contract. If an open skill description specification is adopted, skills can also migrate between different agent runtimes, avoiding lock-in to a single implementation.

    3. Automatic Optimization of Prompts and Skills: Efficiency with Control

    Once the skill library grows, the cost of manually tuning prompts rises quickly. A fairly mainstream industry approach is to introduce “evolutionary optimization”: treat prompts and tool descriptions as parameters that can be iterated, use a scored task set as the fitness function, and keep the better-performing variants generation by generation. Compared with the reinforcement learning route, this kind of method needs neither gradients nor large-scale training resources; it can iterate using only an inference API, and usually has a clear advantage in sample efficiency.

    But automatic optimization must be constrained, otherwise it easily produces “metrics up, intent drift.” Three guardrails are common in engineering:

    • Submit changes as patches, keeping a rollback-capable diff view;
    • Require human review before merging and taking effect; silent runtime rewriting of its own prompt is forbidden;
    • Keep a fixed baseline version and a regression evaluation set; any optimization must prove non-regression on the baseline.

    4. Three-Tier Memory: Making State Survive Across Sessions

    Persistence is the physical basis of the “sense of growth,” and can be divided into three tiers by access frequency and lifecycle:

    • Built-in long-term memory: stores stable facts such as user preferences, project conventions, and technology stack choices; small in size and high in hit rate, with deduplication and conflict resolution required on write.
    • Session retrieval layer: slices and vectorizes historical conversations and recalls them on demand, solving the “can’t remember the details” problem; time decay and relevance thresholds are needed to keep noise from crowding out the context.
    • External plugin memory: connects to team knowledge bases, ticketing systems, or documents in object storage, pulled on demand through a standard interface, making the capability boundary pluggable.

    There must be a clear write policy across the three tiers: stable facts are promoted to long-term memory, one-off details stay in the retrieval layer, and authoritative data always comes from the external system of record, preventing memory from diverging from real state.

    5. Architectural Decoupling: Replaceable, Observable, Governable

    If learning, memory, and execution are mixed in one process, the system quickly becomes unmaintainable. The goal of decoupling is clear layering: the interaction layer handles sessions and permissions, the orchestration layer handles task planning and skill dispatch, the capability layer wraps tool calls, the storage layer unifies reads and writes for memories and skills, and the evaluation layer handles regression and canary releases.

    In terms of deployment shape, such systems typically run in containers on self-owned servers or in the cloud, with object storage holding skill and memory snapshots, and logging and monitoring services tracking the call chain and failure rate. Built on general-purpose container and storage capabilities from Baidu AI Cloud, it is fairly natural to version the skill library, periodically archive memory snapshots, and use a unified monitoring and alerting system to observe performance differences before and after optimization.

    6. Rollout Advice and Risk Control

    • Start from a narrow scenario: first let the loop cover only one class of high-frequency tasks, and expand only after validating the skill hit rate.
    • Give skills an “expiration date”: retest periodically with the regression set, and automatically demote invalid skills to pending-review status.
    • Make memory visible and deletable: provide users with an entry point to view and clear it, with permissions and minimal collection as prerequisites.
    • Keep costs predictable: set budgets and frequency caps for retrieval recall and optimization iterations to avoid runaway context and call volume.

    The real dividing line is not how well the model chats, but whether the system can turn one success into a long-term asset. Closed-loop learning handles “knowing how to summarize,” tiered memory handles “remembering,” and architectural decoupling handles “being able to change.” With all three in place, an agent evolves from a single chat window into a digital counterpart that continuously accumulates working habits.