AI Agents: From Message Routing to Closed-Loop Evolution
This article compares two AI agent architectures: routing-based agents, which pass messages through a short pipeline and leave nothing behind, and closed-loop agents, which turn each interaction into searchable, reusable assets. It breaks down the closed-loop design into three subsystems—prompt construction, tool registry, and session storage—and explains the practical benefits of cross-session continuity, observability, and cumulative capability. It also covers migration steps, a four-question selection checklist, and how to map the architecture onto general cloud service categories. The goal is to help developers decide whether their use case actually needs closed-loop complexity.
1. The Problem: Why “Being Able to Chat” Is Not the Same as “Being Able to Grow”
AI agent tools are iterating quickly, with a new approach discussed every few weeks and marketing pitches that sound almost identical: smarter planning, more natural conversation, lower integration barriers. For developers, the meaningful differences are architectural. One agent leaves nothing behind when the session ends; another turns interaction results into reusable assets.
This article calls the first type a routing-based agent and the second a closed-loop agent. It analyzes them across four dimensions—architecture, components, data, and engineering adoption—and offers a verifiable way to judge which one you need.
2. Routing-Based Architecture: Clear but No Accumulation
The core of a routing-based agent is a message routing layer. It receives messages from various instant messaging channels, parses them, calls a large language model, and returns the result along the original path. The main flow can be abstracted as:
Message ingress → Message parsing → Model call → Tool execution → Response routing → Message egress
The advantages are clear: a short pipeline, single responsibility, easy horizontal scaling, and a new channel only requires one more adapter.
The limitations are equally clear. The context lifecycle is bound to a single session, and tool execution ends when it finishes, with no structured retention. As a result, the same type of question is explained repeatedly, user preferences cannot accumulate, and troubleshooting depends on stitching together external logs.
3. Closed-Loop Architecture: Turning Interactions into Searchable Assets
Beyond the main loop, a closed-loop agent separates three relatively independent subsystems: prompt construction, tool registration, and session storage. The structure looks like this:
┌──────────────────────────┐│ Agent main loop (core) │└──────────────────────────┘│ │ │┌──────┘ │ └──────┐▼ ▼ ▼Prompt builder Tool registry Session storage│ │ │▼ ▼ ▼Context assembly Dozens of tools Structured DB + full-text search
Each subsystem needs to be explained separately.
The prompt builder assembles the final context from system constraints, long-term memory fragments, current retrieval results, and the current turn’s input. This is not string concatenation but an assembly process with priority and budget control: when the token budget is limited, the fragments most relevant to the current intent are kept first.
The tool registry decouples capability declaration from implementation. Each tool describes its own name, purpose, parameters, and constraints, and the model selects what it needs. Once the number of tools grows, grouping and retrieval-based recall must be added; otherwise selection accuracy drops as the candidate set expands.
Session storage writes conversations, tool calls, and results into a structured database and builds a full-text search index. This step is the key to the “loop”: history is no longer a log but knowledge that can be recalled again.
4. Three Practical Benefits of the Closed Loop
First, cross-session continuity. User identity, terminology habits, and past conclusions can be recalled again, reducing repeated explanations.
Second, better observability. Tool calls and results are stored in the same database, making it easy to measure failure rates, average latency, and frequent failure patterns, which provides a basis for optimization.
Third, cumulative capability. Stable workflows can be solidified into skills or templates, and new tasks reuse existing solutions through retrieval instead of reasoning from scratch every time.
It is worth stressing that a closed loop does not mean “automatically getting smarter.” If written content is not filtered, memory gets polluted by noise and recall quality actually declines. Write policies and eviction policies must therefore be designed together with the retrieval policy.
5. Migration and Initialization: Moving Config, Memory, and Keys at Once
Migrating from routing-based to closed-loop usually takes three engineering steps: first migrate configuration and credentials, then migrate historical memory, and finally verify tool availability. Pseudocode:
# 1. Initialize configuration (model endpoint, timeout, retry)init_config(endpoint=..., timeout=30, max_retry=2)# 2. Migrate historical memory and preferencesmigrate(memory=True, skills=True, credentials=True)# 3. Verify tool registration and connectivityfor tool in registry.list():assert tool.health_check()
Practical advice: credential migration must use a key management service or environment variable injection, never a plaintext config file. After migration, run a small-traffic canary first, confirm that recall results and tool selection behave as expected, and only then switch over fully.
6. Selection Checklist
Four questions can quickly tell you whether closed-loop capability is needed:
- Does the task persist across sessions or across days? If so, memory has high value.
- Do you need to call multiple internal systems? If so, tool registration and permission isolation are necessary.
- Do you need auditing and traceability? If so, structured storage is indispensable.
- Is it only single-turn Q&A? If so, a routing-based agent is enough and there is no need to add complexity.
7. Cloud Deployment: Filling Engineering Gaps with General Capabilities
The closed-loop architecture places higher demands on infrastructure, which map onto general cloud product categories: sessions and memory live in database services, full-text search is handled by search capabilities, tool execution runs on a container platform with network isolation, credentials are hosted in a key management service, and full-chain metrics feed into logging and monitoring/alerting. If you use the relevant general capabilities from Baidu AI Cloud, you can select by the categories above, focusing on whether data encryption, permission granularity, and call auditing meet compliance requirements.
8. Conclusion
The standard for judging whether an agent solution is worth investing in is not whether it can chat, but whether it can turn every interaction into a searchable, reusable, auditable asset. Routing-based agents solve connectivity; closed-loop agents solve continuity. First determine whether the business needs continuity, then decide how much architectural complexity to take on—that is the sound evolution path.
