AI Agent Architecture Evolution: From Message Routing to Closed-Loop Learning
This article compares two common AI agent architecture patterns: centralized message routing and closed-loop learning. It explains the core structural difference between stateless request handling and systems that write execution experience back into storage and retrieve it in later turns. It also covers the technical foundations of memory and retrieval, key considerations for tool ecosystems, migration and deployment costs, and a practical framework for deciding whether an agent needs persistent memory at all.
Lately, the agent tooling space has shown a recurring pattern: a project builds up momentum, and shortly afterward a new option appears claiming “seamless migration.” Most developers respond to this kind of pitch with indifference. Over the past two years, there has been no shortage of “next-generation AI assistant” marketing, but very few of those projects have actually stuck around.
If you shift attention from the marketing copy to the implementation, though, this round of change does touch a more fundamental question: should an agent be a message relay, or a system that continuously accumulates experience? Setting specific products aside, this article discusses two typical architecture patterns and the technical points worth attention when selecting between them and putting them into production.
1. The Fundamental Difference Between the Two Architecture Patterns
The first pattern is a centralized message-routing architecture. Its core is a message routing layer: it receives messages from instant messaging tools, team collaboration platforms, or self-built clients, parses them, calls a large language model, and then routes the model output and tool execution results back to the original channel. The main path looks like this:
Message ingress → Message parsing → Model call → Tool execution → Response routing → Message egress
This path is clear, easy to debug, and easy to scale horizontally, with almost no cognitive overhead from an engineering standpoint. But it has one structural weakness: every conversation turn is an independent context, and once tool execution finishes, nothing is retained in a structured form. Preferences a user corrected yesterday, or a failure path investigated last week, have to be explained all over again tomorrow.
The second pattern is a closed-loop learning architecture. Beyond the conversation loop, it separates out three relatively independent subsystems: a prompt builder, a tool registry, and session storage. All three form a bidirectional data flow with the core loop: execution results flow back into the storage layer and are retrieved and reassembled into the prompt in later turns. A rough diagram:
┌──────────────────────────────┐│ Agent core loop (main flow) │└──────────────────────────────┘│ │ │┌─────────▼──┐ ┌──────▼─────┐ ┌───▼────────┐│ Prompt │ │ Tool │ │ Session ││ builder │ │ registry │ │ storage │└─────────┬──┘ └──────┬─────┘ └───┬────────┘│ │ │└────────────┴────────────┘Retrieval results feed the next turn
The key difference is not “more tools,” but whether there is a loop that writes execution experience back and then retrieves it. Without that loop, an agent is forever a stateless function; with it, the agent has continuity of behavior.
2. Memory and Retrieval: The Technical Foundation of the Loop
The engineering difficulty of closed-loop learning concentrates in storage and retrieval. A fairly mainstream combination in the industry is relational storage plus full-text search: structured fields carry session metadata, task state, and tool call records, while a full-text index carries natural language fragments, with the two linked by identifier fields.
Three points are easy to overlook when making this choice:
- Retrieval granularity. Using an entire session as the recall unit introduces a lot of noise. A more practical approach is to split entries into facts, preferences, conclusions, and todos, each with a source and a timestamp.
- Forgetting mechanisms. More memory is not better. Expiration policies and conflict resolution rules need to be designed, otherwise contradictory old conclusions will keep polluting the prompt.
- Observability. Every recall should be able to answer “why was this item selected,” otherwise it is impossible to diagnose when production quality degrades.
A minimal working memory write and recall logic looks roughly like this (illustrative code, not a specific implementation):
def remember(session_id, kind, text, tags):# kind: fact | preference | conclusion | todostore.insert(session_id, kind, text, tags, ts=now())def recall(session_id, query, top_k=5):lexical = store.fts_search(query, session_id, limit=top_k * 2)structured = store.by_tags(session_id, tags_of(query))return rerank(merge(lexical, structured))[:top_k]
It is worth stressing that recall results must go through budget control before entering the prompt. The context window is a finite resource, and memory, tool descriptions, and conversation history squeeze each other. In practice, memory is usually allocated a configurable fixed proportion, combined with summarization and compression.
3. Tool Ecosystems: Quantity Is Not Capability
The second architecture often emphasizes the number of registered tools and how the toolset is grouped. Quantity is indeed a signal of ecosystem activity, but for users, three things actually affect the experience:
- Permission boundaries. Which resources a tool can read and write, and whether human confirmation is required, must be declared at registration time rather than constrained through the prompt.
- Idempotency and rollback. Write operations should be retryable without accumulating side effects, and destructive operations should retain a path to undo.
- Unified error semantics. Timeouts, rate limiting, and invalid parameters should return structured errors so the model can correct itself, rather than throwing a piece of free text.
Toolset grouping (dividing by domain, loading on demand) is a practice worth borrowing: it avoids stuffing all tool descriptions into the context at once, which both saves budget and reduces the chance of the model picking the wrong tool.
4. Migration and Deployment: Calculate the Cost Before You Start
“Install with one command, migrate with one command” experiences are increasingly common in the open source ecosystem, usually implemented through scripted installation and configuration export. When evaluating migration cost, it is better to focus on a checklist of questions than on the number of commands:
- Can configuration items be exported as plain text, making version management and auditing easier?
- Are secrets migrated by reference rather than copied in plaintext?
- Do memory and skill data have an explicit format version number?
- Is validation in an isolated environment supported first?
Platform compatibility is also a hard constraint. Some toolchains are natively built for Unix-like environments, and Windows users usually need to run them through virtualization or containerized environments, which brings additional resource overhead and filesystem performance differences. This needs to be factored in at the solution stage.
Deployment form is another fork: individual trial and team sharing are two different paths. The former can run on a single machine; the latter requires externalizing session storage and filling in common cloud capabilities such as logging services, monitoring and alerting, and secret management (general categories like object storage, message queues, and container platforms are sufficient). Otherwise, basic questions like “who had the agent do what, and when” cannot be answered.
5. Does an Ordinary User Really Need Another Tool
Back to the original question. The criteria can be narrowed to three:
- Task repetitiveness. If the questions asked every day are one-off, stateless routing is enough, and an extra memory layer only adds maintenance surface.
- The long tail of context. If your preferences, project conventions, and historical conclusions are highly personalized and hold up over the long term, the payoff from the memory loop accumulates with usage time.
- The operational cost you are willing to bear. A closed-loop system adds three things to look after: storage, retrieval, and cleanup.
A pragmatic path is to first get the business path working with a stateless approach, then distill the high-frequency, stable parts into structured memory entries, and gradually introduce retrieval and tool grouping. A common approach at Baidu AI Cloud in these scenarios is also to first run a minimal loop on general-purpose storage and compute resources, then evolve retrieval and scheduling capabilities as data volume grows, rather than adopting a complex architecture from the start.
Conclusion
The substance of the architecture debate is a contest between a “stateless function” and a “stateful collaborator.” The former wins on simplicity and control; the latter wins on accumulated experience. For developers, a more valuable action than chasing new projects is identifying the part of information in your own business that genuinely needs to be remembered, and designing clear write, retrieval, and forgetting rules for it. Tools will be replaced; this methodology will not.
