AI Agents: From Message Routing to Closed-Loop Learning
This article compares two common AI agent architectures—routing-based agents and closed-loop agents—and explains why the ability to converse does not guarantee that knowledge is retained. It covers the engineering characteristics of each design, a side-by-side comparison, the constraints behind one-command migration and initialization, and key context engineering practices such as layered injection and retrieval-first prompting. It also offers practical guidance on architecture selection and cloud deployment.
AI Agents: From Message Routing to Closed-Loop Learning
1. Background: Why “Being Able to Chat” Is Not the Same as “Retaining Knowledge”
Over the past two years, AI agents have moved from demos to daily use, and the installation barrier has been reduced to a single command. For a typical open-source agent, a quick install usually means running one script, refreshing the environment variables in the current terminal session, and entering a launch command to start a conversation. On compatibility, Linux and macOS are generally supported first, while Windows users need a Linux-compatible environment such as WSL2. A first run also requires an initial configuration pass. If you want to bring over existing configuration, memory, skills, and API keys, a migration command can import them in one step.
As installation experiences converge, the focus of competition is shifting from “can it run” to “what remains after it runs.” This article abstracts two typical architectures:
- Routing-based agents: The core is a message routing layer. It receives messages from instant messaging tools, team collaboration platforms, email, or webhooks, parses them, calls a large language model, and routes the response back to the original channel.
- Closed-loop agents: The core is a continuously running conversation loop that works with modules for prompt construction, tool registration, and session storage, turning the result of each interaction into a reusable asset.
Note that this article does not review or recommend any specific product. It only discusses the general engineering characteristics of the two architectures as a reference for architecture selection.
2. Routing-Based Architecture: Clear, but Lacking Memory
The request path of a routing-based architecture is straightforward:
Message ingress → Message parsing → Model call → Tool execution → Response routing → Message egress
The advantages are obvious: clear layering, easy horizontal scaling, and a low cost of onboarding new channels. Teams can keep adding message adapters without changing the core logic.
The problem lies in the “context lifecycle.” Most routing-based implementations treat a session as an independent unit: a request comes in, the model generates an answer, and the path ends once tools finish executing. User preferences are not written to long-term memory, and successful operation sequences are not abstracted into reusable skills. As a result:
- High repeated explanation cost: Users have to restate the background every time.
- No accumulation of capability: A flow that works today has to be re-tuned tomorrow.
- Difficult troubleshooting: Without unified storage, logs are scattered across channel adapter layers.
- Loose permission and key management: Keys are spread across environment variables and configuration files, making rotation and auditing hard.
3. Closed-Loop Architecture: Turning Interactions into Assets
A closed-loop architecture is usually built around a relatively large core loop (in the material referenced at the beginning of this article, this loop is on the order of roughly nine thousand six hundred lines of code), with three key subsystems radiating outward:
┌─────────────────────────────┐│ Agent Core Conversation Loop │└─────────────────────────────┘│ │┌──────────┘ └──────────┐▼ ▼┌────────────┐ ┌────────────┐ ┌────────────┐│ Prompt Builder │ │ Tool Registry │ │ Session Store │└────────────┘ └────────────┘ └────────────┘│ │ │▼ ▼ ▼Layered context Dozens of tools Database + full-text search
The responsibilities of the three subsystems can be understood as follows:
- Prompt builder: Assembles context in layers of “system persona + long-term memory + skill list + current task,” controlling injection order and budget.
- Tool registry: Declares capabilities as tools with schema constraints, loaded by tool set to avoid stuffing all definitions into the context at once.
- Session store: Uses a relational database to persist sessions and messages, with a full-text search index supporting historical recall.
The value of this design is a closed loop: interactions produce data → data is retrieved and structured → structured results feed the next prompt construction. Memory is no longer “stuffing all history in,” but “recalling the most relevant fragments on demand.”
4. Key Differences
| Dimension | Routing-Based Architecture | Closed-Loop Architecture |
|---|---|---|
| Core abstraction | Message channel | Continuously running agent loop |
| Context | Single session, destroyed on exit | Layered persistence, recallable across sessions |
| Capability extension | Add channel adapters | Register new tools or skills |
| Data accumulation | Basically none | Session database + full-text search |
| Operations focus | Concurrency and routing reliability | Storage consistency, retrieval quality, key governance |
| Typical risk | Capability does not accumulate | Context bloat and noisy recall |
It is worth stressing that the two are not mutually exclusive. A common production pattern is “the routing layer handles ingress, the closed-loop layer handles cognition”—keeping multi-channel entry points while pushing memory and skills down into unified storage.
5. Migration and Initialization: Engineering Constraints Behind a One-Line Command
“Moving all configuration with one command” sounds easy, but it actually involves four types of assets, each with pitfalls:
- Configuration: Model endpoints, temperature, timeouts, and retry policies. When migrating across environments, the items most often missed are environment-specific ones. A two-layer structure of “base configuration + environment overrides” is recommended.
- Memory: A distinction is needed between “factual memory” (user preferences, long-term goals) and “episodic memory” (the process of a particular task). The former should be kept lean, and the latter should be archivable.
- Skills: These are essentially tool descriptions with input and output schema constraints. During migration, schema compatibility should be validated to avoid unrecognized fields in a new version.
- Keys: They must never be migrated in plaintext along with configuration. The recommended practice is to migrate only “references,” keep keys in environment variables or a key management service, and re-authorize them under least privilege.
A sound migration order is: back up the storage files first → run initialization → run migration → finish with a “recall verification” to confirm that historical memory can be retrieved correctly.
# Example: initialization and migration (command names follow the actual tool documentation)agent initagent migrate --source ./backup --include memory,skills,configagent doctor # Check whether storage, indexes, and key references are usable
6. Context Engineering: The Real Challenge of Closed-Loop Systems
The closed-loop architecture shifts complexity from “concurrency” to “context quality.” In practice, four principles are recommended:
- Layered injection: System instructions are the most stable, long-term memory comes next, and task context is the most recent; allocate budget by layer.
- Retrieval first: Retrieve before assembling, rank by both similarity and recency, and avoid pouring in entire stretches of history.
- Structured accumulation: Abstract successful multi-step operations into “skills,” replacing copy-pasted history with parameterized descriptions.
- Observability: Log the hit fragments and scores of each recall to make it easier to evaluate the noise rate.
Illustrative code:
def build_prompt(task, store, budget=6000):memory = store.search(task, top_k=5, weight={"similarity": 0.7, "recency": 0.3})skills = store.list_skills(task.domain)return {"system": SYSTEM_PROMPT,"memory": memory[:budget // 2],"skills": skills,"task": task.text,}
7. Selection Guidance and Cloud Deployment
Three questions can serve as a self-check when choosing an architecture:
- Does the business need to remember users across sessions? If so, lean toward closed-loop.
- Are channels highly fragmented? If fragmentation is severe, keep a routing layer.
- Does the team have the operational capability for storage and retrieval? If not, prioritize managed solutions.
For cloud deployment, general-purpose capabilities can be combined: use a container platform to host the agent runtime, object storage for backups and skill packages, a message queue to smooth peaks and decouple channel ingress, a database service for sessions, and logging plus monitoring and alerting to cover retrieval quality and call-chain observability. If model inference is involved, a model service platform can provide unified access and quota management, avoiding keys scattered in business code.
8. Conclusion
The routing-based architecture solves “getting connected,” while the closed-loop architecture solves “remembering and being useful.” What truly determines the long-term value of an agent is not how short the installation command is, but whether interactions can be structurally accumulated, recalled on demand, and reused safely. For developers, the pragmatic path is to retain multi-channel routing capability, push memory, skills, and key governance down into unified subsystems, and continuously evaluate context quality with observability tooling.
