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

    This article compares two common AI agent architectures—stateless message routing and state-centric closed-loop learning—across four dimensions: context management, tool systems, memory and retrieval, and migration cost. It explains how dynamic prompt assembly, tool registries, structured storage with full-text search, and credential handling affect long-term capability growth, and offers practical selection guidance and an implementation checklist for building maintainable agent systems.

    1. The Problem: Why “Next-Generation Assistants” Keep Appearing

    The agent space has seen a wave of new projects with strikingly similar marketing claims: one-command installation, seamless migration of existing configurations, and built-in “memory” and “skills.” For developers, installation convenience is not the real benchmark. What matters is whether the architecture can evolve sustainably.

    A reusable evaluation framework comes down to four questions: Can the system’s state be persisted? Can its capabilities be extended? Is its context retrievable? Is migration low-cost? This article uses these four points to provide a neutral technical analysis of two typical architectures.

    2. The Fundamental Difference Between the Two Architectures

    2.1 Routing-Based Architecture: Clear but Stateless

    The first architecture centers on a message routing layer. It receives messages from various instant messaging channels, parses them, calls a large language model, and routes the result back to the original channel. The flow can be abstracted as:

    1. message ingress → parsing → model call → tool execution → response routing → egress

    The strengths are clear layering, easy deployment, and straightforward horizontal scaling. The weaknesses are equally obvious: session contexts are isolated from one another, tool execution results are discarded after use, and long-term experience cannot be reused. Every interaction is close to a cold start, and system capability does not grow with usage.

    2.2 Closed-Loop Learning Architecture: State-Centric

    The second architecture focuses on a loop plus state. The core is a continuously running conversation loop that connects to three subsystems:

    1. ┌──────────────────────────┐
    2. │ Agent Core Loop (Main) │
    3. └──────────────────────────┘
    4. │ │ │
    5. ┌──────┘ ┌─────┘ └──────┐
    6. ▼ ▼ ▼
    7. Prompt Builder Tool Registry Session Store
    8. (Context Assembly) (Capabilities/ (Persistence +
    9. Groups) Full-Text Search)

    What matters is not code size but three accumulative designs: prompts are assembled dynamically based on the current task, tools are managed centrally through a registry and organized into groups, and sessions are retained long-term using structured storage with full-text indexing.

    3. A Closer Look at Four Key Dimensions

    3.1 Context Management: From One-Off to Composable

    In the routing-based architecture, the context lifecycle equals a single request. The closed-loop architecture treats context as an assemblable resource, selecting historical fragments, skill descriptions, and constraints as the task requires. In engineering practice, this usually involves budget control across three segments:

    1. budget = {"system": 2000, "history": 6000, "tools": 3000, "output": 1500}
    2. # When the budget is exceeded, trim by priority: system > tools > recent history > older history

    The key is a clear trimming priority and summarization strategy, not unlimited concatenation. Otherwise, cost and latency will quickly spiral out of control.

    3.2 Tool System: Registry Plus On-Demand Group Loading

    Once the number of tools grows, injecting all of them into the prompt consumes budget and reduces selection accuracy. A common approach is to register metadata in a registry (name, purpose, parameter schema, permission level), group tools into tool sets, and load only the subset relevant to the current task. Example:

    1. { "name": "file_search", "group": "workspace", "risk": "read",
    2. "schema": {"query": "string", "top_k": "integer"} }

    High-risk tools (write, delete, external calls) should be placed in separate groups with confirmation or approval steps.

    3.3 Memory and Sessions: Structured Storage Plus Full-Text Retrieval

    Persisting conversations and execution traces in a database and building a full-text index is the foundation of reusable experience. Retrieval typically combines two signals: keyword matching ensures precise hits, while vector similarity ensures semantic recall, followed by result fusion and reranking. Privacy and compliance require attention: sensitive fields should be masked, data should be isolated by tenant, and retention periods and deletion mechanisms should be defined.

    3.4 Migration and Cost: Configuration, Memory, Skills, and Credentials

    Migration is essentially the export and import of four asset types: runtime configuration, historical memory, skill definitions, and access credentials. Credentials should not be migrated in plaintext; the recommended approach is to have them managed by the platform’s key management capabilities and injected on demand at runtime. If an organization already uses general capabilities such as object storage, logging, and monitoring and alerting from Baidu AI Cloud, it can standardize session archiving, auditing, and alerting to reduce operational overhead.

    4. Selection Guidance and a Practical Checklist

    • If you only need multi-channel question answering with no long-running tasks, a routing-based architecture is sufficient; prioritize concurrency and availability.
    • If you need long-cycle tasks, experience accumulation, and multi-tool collaboration, choose a closed-loop architecture and focus your evaluation on storage and retrieval.
    • Regardless of architecture, you should have permission tiers, invocation auditing, failure retries with idempotency, and cost and latency dashboards.
    • Suggested implementation order: first get a single-tool loop working end to end, then add persistence and retrieval, and finally introduce multiple tool sets and approval flows.

    5. Conclusion

    Architecture quality is not determined by marketing language but by whether state can be persisted, capabilities can be extended, context can be retrieved, and migration can be low-cost. Running storage, logging, and monitoring on general cloud capabilities can take an agent from “able to chat” to a production system that is “accumulative and governable.”