AI Agent Architecture: From Message Routing to Closed-Loop Learning
This article compares two core AI agent architectures—message routing and closed-loop learning—and examines how they differ in context management, tool invocation, state persistence, and portability. It breaks down the mechanisms of each approach, details four core capabilities of closed-loop agents (persistent memory and retrieval, tool organization, skill reuse, and configuration migration), and offers scenario-based selection guidance along with a practical implementation checklist. Developers will find observable metrics and deployment practices for building maintainable, transferable agent infrastructure.
AI Agent Architecture: From Message Routing to Closed-Loop Learning
1. Why “Being Able to Chat” Is No Longer Enough
Discussion around AI agent projects has been heating up, but the debate is often reduced to “who will beat whom.” From an engineering perspective, that kind of comparison has limited value. What is actually worth studying is how different architectures differ in context management, tool invocation, state persistence, and portability—and how those differences affect long-term usage.
One class of solutions centers on message routing: it receives messages from different channels, parses them, hands them to the model for inference, and sends the result back to the original channel. The flow is clear, easy to understand, and quick to ship. However, in typical implementations each conversation turn is relatively independent, context is released as soon as tool execution finishes, and there is no reusable experience layer.
Another class of solutions emphasizes closed loops: prompt construction, tool registration, and session storage are placed inside the same loop, so interaction results can be accumulated as searchable memory and reusable skills. This article focuses on that technical divide, discussing design points, engineering costs, and applicability boundaries.
2. Mechanism Breakdown of the Two Architectures
2.1 The Message-Routing-Centric Architecture
The typical flow can be abstracted as:
Message ingress -> Message parsing -> Model invocation -> Tool execution -> Response routing -> Message egress
The advantages are single responsibility and clear boundaries. The channel adaptation layer is decoupled from the inference layer, making scaling and canary releases relatively easy. The limitations are equally obvious:
- Short context lifecycle; cross-session knowledge is hard to accumulate.
- Tools are coupled with channels; adding new capabilities often requires changes to the routing layer.
- No unified memory or retrieval facility, so the same problems get solved repeatedly.
2.2 The Closed-Loop-Learning-Centric Architecture
Its structure is closer to a cohesive runtime kernel supported by three subsystems:
+-----------------------------+| Agent Core Loop (Main) |+-----------------------------+| | |+------+ +------+ +------+| Prompt | | Tool | |Session||Builder | |Registry| |Store |+------+ +------+ +------+| | |Context assembly Capability Persistencelist & retrieval
Key design points include:
- Prompt builder: dynamically assembles system instructions, history summaries, and retrieved snippets per task, while controlling the context budget.
- Tool registry: describes each tool’s name, purpose, parameters, and permissions with unified metadata, supporting grouping and on-demand loading.
- Session store: persists conversations, tool calls, and results to storage, and recalls relevant snippets in later turns via full-text retrieval.
Together these three form a closed loop: interactions produce data, data is indexed, the index feeds back into prompts, and prompts drive more accurate tool calls.
3. Four Core Capabilities of the Closed-Loop Architecture
3.1 Persistent Memory and Retrieval
Memory should not be “stuffing the entire history into the prompt.” It should be a layered structure:
- Short-term: the current session window, injected directly into the prompt.
- Mid-term: session summaries and key conclusions, compressed and saved.
- Long-term: preferences, constraints, and domain facts, stored independently with full-text retrieval support.
In engineering practice, a common combination is “structured storage + full-text index”: keyword matching happens first at recall time, then the model judges relevance, balancing cost and accuracy.
3.2 Organizing Tool Capabilities
Once the number of tools grows, injecting all definitions at once quickly exhausts the context. A workable approach is metadata + grouping + progressive disclosure: present the capability list and applicable scenarios first, then load detailed parameter descriptions after the model makes a selection. At the same time, each category of tool must have permission boundaries and rollback strategies, especially for operations involving writes, deletions, and external calls.
3.3 Skill Formation and Reuse
When a certain class of task is repeatedly executed successfully, it can be abstracted into a parameterized workflow (steps, preconditions, checkpoints) and become a reusable skill. Three practical criteria for deciding “whether it is worth distilling”: it recurs, the result is verifiable, and the steps are relatively stable.
3.4 Configuration and Migration
Long-term use brings configuration bloat: model access parameters, keys, preferences, skills, and memory. The ideal state is separation of configuration and data, plus versioned export formats, so migration becomes a declarative operation rather than manual item-by-item rebuilding. During migration, sensitive credentials must be encrypted or handled as references to avoid plaintext spreading.
An illustrative migration flow:
Export: config + memory + skills -> versioned archive (credentials as references)Validate: structure check + permission check + summary consistency checkImport: version adaptation -> index rebuild -> sampled recall verification
4. Selection Guidance: By Scenario, Not by Hype
- Mainly multi-channel customer service and notification push, with short sessions and slow knowledge updates: the routing architecture is lower cost.
- Mainly long-term companionship, R&D assistance, and operations inspection, requiring cross-session accumulation: the closed-loop architecture delivers more obvious benefits.
- Hybrid scenarios: use a routing layer on the outside for channel adaptation and a closed-loop kernel on the inside for memory and tools—a relatively safe combination.
For evaluation, four observable metrics are recommended: first-attempt task success rate, repeated-question rate, memory recall hit rate, and average context cost per task. These metrics reflect real experience better than “feature count.”
5. Implementation Checklist
- Build a minimal closed loop first: session store + retrieval + a few tools, and validate recall quality.
- Budget the context: set limits and eviction policies for system instructions, history, and retrieved snippets.
- Tier tool permissions: read-only, internal write, and external side effects, approved tier by tier.
- Make the full chain observable: log prompt versions, tool calls, and latency to ease regression localization.
- Normalize migration and backup: store configuration and memory separately, and rehearse recovery regularly.
- Platform-side support: use a container platform to host the runtime, object storage for archives, log services and monitoring alerts to track quality metrics, and a message queue for peak shaving.
6. Conclusion
Competition among agents ultimately comes down to “whether sustainable accumulation and controlled execution are in place.” Message routing solves the reach problem; closed-loop learning solves the growth problem. For developers, the rational path is to first clarify how strongly the scenario demands memory and tools, then choose the architecture, and continuously calibrate with observable metrics. If an enterprise wants to build such capabilities in its own environment, it can build operable, transferable agent infrastructure on general cloud products from Baidu AI Cloud, such as containers, storage, logging, and monitoring.
