Agent Learning Loop Architecture: A Practical Guide

    This guide presents a reproducible reference architecture for building AI agents that accumulate capability over time. It explains a single-core, multi-entry design, a four-layer memory model split by time scale, runtime skill generation with automatic pruning, and an offline evaluation pipeline that validates experience before promotion. It also covers how to run three isolated agent instances from one codebase, common pitfalls with acceptance criteria, and how to host the system on Baidu AI Cloud using generic managed services. The focus is on treating memory, skills, and verification as one closed loop rather than picking a particular model.

    1. Why “Learning” Is the Dividing Line for Agents

    Over the past two years, personal agents have moved from concept demos to everyday tools, and a clear dividing line has emerged. Early solutions competed on whether an agent could call tools; what separates solutions today is whether it can accumulate capability over long-term use.

    Accumulating capability does not mean stuffing chat history into a context window. At the system level, it means solving three coupled problems: state continuity across sessions, the consolidation of reusable operational experience, and continuous validation of that experience.

    An observation repeatedly confirmed in the industry is that compounding effects appear only when three independent capabilities — runtime skill learning, persistent multi-layer memory, and an optional weight-training pipeline — are integrated into one framework. Without memory, every session starts from zero. Without skill consolidation, repetitive work never gets eliminated. Without validation, consolidated “experience” quickly degrades into noise and can even contaminate later decisions. Discussing a learning loop is therefore about engineering a system with feedback control, not shipping a single feature.

    This article takes a neutral technical perspective, abstracts a reproducible reference architecture, and explains how to build multiple agent instances with isolated responsibilities on top of it. No specific vendor product is involved; every capability described maps to a general technical category in the industry.

    2. Reference Architecture: One Core, Multiple Entry Points

    A workable learning loop usually needs a unified core agent class that carries all the logic. A CLI, a message gateway, a batch job runner, and an IDE plugin are simply different entry points to that core. This “single core, multiple entry points” design yields two direct benefits. First, behavioral consistency is guaranteed: no matter which entry point starts a task, system prompt construction, context compaction, tool invocation, and state write-back all follow the same path. Second, migration cost across environments is minimal — the same codebase runs in a local terminal, a container, a remote host, an elastic compute platform, or a cluster scheduler, with differences pushed down into configuration.

    The core loop generally follows a synchronous alternating inference-action pattern, summarized in four stages:

    1. loop:
    2. 1. Build the system prompt (inject persona, memory summary, skill list)
    3. 2. Check the context budget; trigger compaction/summarization if needed
    4. 3. Issue an interruptible model call (supports cancellation and timeouts)
    5. 4. Execute tool calls and write back observations
    6. goto 1

    “Interruptible” is an easily overlooked but critical property. Long-running tasks must be abortable by an external signal; otherwise, once a tool call blocks, the entire background process becomes uncontrollable. The execution location for commands should likewise stay pluggable: a local terminal suits debugging, containers suit dependency isolation, remote hosts suit long-lived processes, elastic platforms suit burst compute, and cluster schedulers suit batch parallelism. Keeping the code unchanged and switching only the execution backend configuration is the basis of this architecture’s reproducibility.

    3. Layered Memory: Dividing Responsibility by Time Scale

    Memory should not be a single cache; it should be split by time scale and abstraction level. A practical division has four layers:

    • Working memory: the context window of the current session. Smallest capacity, shortest lifespan, responsible for continuity of reasoning right now.
    • Session memory: archived per conversation and searchable by topic, used for回溯-style recall such as “where did we leave off last time.”
    • Long-term memory: stable facts, preferences, constraints, and project background that persist across sessions, usually stored as structured entries alongside a vector index.
    • Procedural memory: skills and operational patterns that record “how to get something done” rather than “what something is.”

    The write strategy must differ for each. Working memory controls size through compaction and summarization. Session memory is filtered by time decay and importance scoring. Long-term memory requires explicit confirmation so a one-off slip of the tongue is not frozen into a long-term preference. Procedural memory can only be promoted after validation. Storing “facts” and “methods” together is the root cause of poor results in most self-built setups: the model retrieves facts when it needs a method and recites steps when it needs a fact.

    4. Runtime Skill Generation and Automatic Pruning

    In this context, a skill is a reusable operational pattern: a description with preconditions, execution steps, and failure fallbacks, optionally accompanied by scripts or templates. The typical runtime skill learning flow is: after a task completes, trigger reflection, extract generalizable steps, generate a candidate skill entry, write it to a pending-validation area, retrieve and use it in later similar tasks, and decide whether to keep, merge, or retire it based on success rate.

    Automatic pruning matters just as much. Without a convergence mechanism, a skill library swells within weeks until retrieval noise outweighs useful signal. Common pruning strategies include score-based retirement using call frequency and success rate, deduplication and merging by semantic similarity, archiving entries with zero calls over a long period, and versioned retention for rollback. In engineering terms, keep the source task identifier and validation record on each skill entry so any skill can be traced back to the scenario where it was validated.

    1. {
    2. "skill_name": "Batch rename and generate a change manifest",
    3. "preconditions": ["target directory is writable", "backup completed"],
    4. "steps": ["scan candidate files", "generate mapping table", "execute renames", "output change manifest"],
    5. "rollback": "reverse rename using the mapping table",
    6. "stats": {"calls": 12, "success_rate": 0.92, "last_used": "2026-08-20"}
    7. }

    5. Offline Evolution and Validation: Making Experience Testable

    Online feedback alone is not enough to guarantee quality, because the distribution of real tasks is sparse and expensive. The reference approach adds an offline pipeline alongside online learning: build evaluation sets from historical tasks, replay candidate skills and prompt variants in batch, and compare baseline against the new version using measurable metrics (task completion rate, number of steps, tool call error rate, human ratings). Only versions that significantly outperform the baseline are allowed to be promoted. This is consistent with general methods for automatic prompt optimization: it turns “is the change better?” from a subjective judgment into a repeatable experiment.

    Note that optional weight-level training is an advanced stage, not a requirement. In most scenarios, retrieval-augmented memory plus a validated skill library already covers the majority of the gains. Weight training suits cases where behavioral style must be fixed, domain terminology is dense, or latency is extremely sensitive, and it must be paired with data anonymization, sample filtering, and regression evaluation; otherwise the gains are offset by catastrophic forgetting.

    6. Building Three Isolated Agents from Scratch

    Isolation matters because it prevents personas, memory, and skills from contaminating each other. The recommended approach is “same core code + separate configuration directory + separate storage namespace”:

    1. Prepare an independent configuration for each instance: persona settings, tool allowlist, memory store path, skill library path, and messaging channel credentials.
    2. Programmer instance: connect the local development and debugging toolchain, allow reading and writing the workspace, and bias skills toward build, test, and refactoring workflows.
    3. Deep research instance: centered on retrieval, fetching, summarization, and cross-verification, with the tool allowlist tightened to read-only and mandatory annotation of information sources and timestamps.
    4. Designer instance: focused on solution generation and review, outputting structured specifications instead of directly modifying code, to avoid unauthorized writes.
    5. Unified message entry: bind each instance to a separate session identifier so contexts never cross; enable timeouts, retries, and circuit breaking for long-lived background processes.
    6. Observability and governance: collect logs, metrics, and traces centrally, and set audit records for memory writes and skill promotions.

    When deploying on Baidu AI Cloud, the requirements above can be carried by a combination of general-purpose capabilities: a container platform hosts the persistent runtime, object storage holds memory and skill snapshots, a message queue decouples long-running tasks, and log service plus monitoring and alerting provide observability, while a key management service holds credentials. This keeps the architecture neutral while gaining elasticity and operability.

    7. Common Pitfalls and an Acceptance Checklist

    • Memory without governance: write-only, never delete, and retrieval hit rate eventually drops. Acceptance criterion: memory entries are traceable and can be invalidated.
    • Skills without validation: treating a one-off success as a general method. Acceptance criterion: every skill has a validation record and a fallback.
    • No context budget: key constraints get lost midway through long tasks. Acceptance criterion: constraints survive compaction unchanged.
    • Incomplete isolation: multiple instances sharing storage causes persona drift. Acceptance criterion: namespaces and credentials are fully independent.
    • Non-interruptible execution: background tasks run out of control. Acceptance criterion: any task can be safely terminated by an external signal.

    Following this architecture, you end up with a reproducible, observable, continuously improving personal agent system: it remembers your preferences, turns repetitive work into skills, and keeps self-correcting through offline evaluation. The real barrier is not model selection but whether you design memory, skills, and validation as a single closed loop.