AI Agent Architecture: From Message Routing to Closed-Loop Learning

    A technical comparison of two AI agent architectures: stateless message-routing dispatchers versus closed-loop agents built around persistent memory, retrieval, and reflection write-back. It breaks down the four core subsystems, explains why portable configuration does not mean portable capability, and provides a selection checklist plus the engineering constraints—privacy, memory pollution, cost, observability, and infrastructure—that determine whether an agent can turn interactions into reusable assets.

    The Technical Divide Behind the Hype

    Discussion of the “next generation of personal agents” has heated up noticeably. Every few months a new project appears, positioned as the replacement for the previous approach, and the pitch is remarkably consistent: install with a single command, migrate configuration seamlessly, push the capability boundary further out. For developers, the interesting question is not the popularity ranking. It is what these systems actually solve at the architecture level, and what they leave unsolved.

    Abstract away the individual products and two technical routes become clear: one centered on message routing, the other on closed-loop learning. The first answers “where does the conversation happen.” The second answers “what remains after the conversation.” That divide determines whether an agent stays a tool or becomes an assistant.

    Route One: The Message-Routing Dispatch Architecture

    The core of a dispatch architecture is a message routing layer. It accepts connections from several instant messaging entry points, parses each message, calls a large language model, and routes the model output back to the originating channel using the session identifier. The typical path looks like this:

    1. message entry -> message parsing -> model call -> tool execution -> response routing -> message exit

    The advantages are clear:

    • Low cognitive load: the chain is linear and the debugging path is short, so any failing stage can be located quickly.
    • Low integration cost: the adapter pattern is mature, and adding a messaging channel usually means implementing one unified event interface.
    • Multi-tenant friendly: a routing table keyed by session ID scales horizontally without much friction.

    The limitations are equally clear. Every turn runs in an isolated context, tool results are discarded once used, and the system accumulates no reusable assets. Users must restate preferences, project background, and constraints every time they start a new session, and the operator has no historical behavior to improve quality against. In effect it is a stateless forwarder, with a ceiling set by the single context window.

    Route Two: The Closed-Loop Agent Architecture

    A closed-loop architecture splits the system into four cooperating subsystems driven by a long-running core loop:

    1. ┌──────────────────────────────────────────────┐
    2. │ Agent core loop (main dialogue loop, can reach tens of thousands of lines) │
    3. └──────────────────────────────────────────────┘
    4. │ │ │
    5. ▼ ▼ ▼
    6. Prompt builder Tool registry Session store
    7. (context assembly) (capability list) (persistence + full-text search)

    The responsibilities and engineering priorities of each subsystem are as follows.

    1. Prompt builder. Instead of concatenating a static system prompt, context is assembled dynamically for the current task, typically from four parts: role constraints, long-term memory fragments, retrieved historical experience, and available tool descriptions. The context budget needs explicit management. The common approach is layered trimming: stable constraints stay resident, while experience fragments are injected top-K by relevance.

    2. Tool registry. Tools declare their name, purpose, input schema, and permission level as metadata, and are exposed on demand at runtime rather than pushed into the prompt all at once. As the tool count grows, grouping and retrieval-based recall become mandatory; otherwise selection noise degrades invocation accuracy significantly.

    3. Session store. A combination of relational storage and a full-text search index turns conversation history, task conclusions, and failure cases into queryable assets. Retrieval quality determines memory quality, which usually means supporting both keyword matching and vector similarity recall, then applying fusion ranking.

    4. Core loop. This drives the iterate cycle of plan, execute, observe, and reflect. The key difference from a linear chain is the reflection write-back stage: once a task ends, reusable conclusions are extracted and written to memory, so the next round starts from a higher baseline than the last.

    A skeletal version of the loop:

    1. while not done:
    2. context = prompt_builder.build(task, memory, tools)
    3. action = model.plan(context)
    4. if action.type == "tool":
    5. observation = registry.invoke(action.name, action.args)
    6. session.append(action, observation)
    7. else:
    8. done = True
    9. memory.write(extract_lesson(session)) # key: persist experience

    Why Portable Configuration Is Not Portable Capability

    New systems often emphasize one-click inheritance of existing configuration, memory, and credentials. This deserves a sober reading: what migrates is the data asset, not the capability structure. If the target architecture lacks a memory write-back path and a retrieval path, imported history is just a static archive and never participates in decisions. When evaluating migration value, ask three questions: does memory participate in prompt assembly, is retrieval measurable, and does write-back have a quality gate. Missing any one of the three, migration is just moving boxes.

    Selection Checklist

    Dimension Dispatch Closed-loop
    Context continuity Isolated per turn Accumulated across sessions
    State management Essentially stateless Explicit persistence
    Operational complexity Low Medium to high
    Room for improvement Depends on prompt tuning Depends on memory and retrieval iteration
    Fit Notifications, queries, lightweight Q&A Long-running tasks, personal assistants

    The practical recommendation is to adopt in layers: start with a dispatch architecture to absorb high-concurrency, low-complexity entry traffic, then introduce closed-loop capability for the few scenarios that need long-term continuity, rather than maxing out complexity on day one.

    Engineering Constraints in Production

    • Privacy and compliance: long-term memory means long-term retention of personal data, so retention periods, deletion mechanisms, and access boundaries must be explicit.
    • Memory pollution: a wrong conclusion that gets written back will be amplified on every reuse, so confidence thresholds and a human confirmation step are needed.
    • Cost control: retrieval, reflection, and retries all multiply call volume, so budget caps and fallback strategies are required.
    • Observability: retrieval hit rate, tool success rate, and write-back adoption rate should feed monitoring and alerting; without them there is no way to tell whether an optimization actually worked.
    • Elastic foundation: running the core loop on a container platform, storing memory snapshots in object storage, using a message queue to smooth traffic spikes, and relying on logging and monitoring services to trace long chains is a fairly safe general pattern, and can be assembled from such general-purpose capabilities on Baidu AI Cloud.

    Conclusion

    Dispatch and closed-loop architectures are not replacements for each other; they are a tradeoff between complexity and continuity. Whether an agent is worth adopting should not be judged by how easy it is to install or how loud the marketing is, but by whether it converts interactions into reusable assets—and whether those assets can be retrieved, evaluated, and corrected. Get those three right, and a tool genuinely evolves into an assistant.