Agent Architecture Evolution: From Message Routing to Closed-Loop Learning

    This article compares two mainstream AI agent architectures—centralized message routing and closed-loop learning—at the design level. It breaks down their differences in context handling, memory, tool extensibility, and prompt construction, then introduces a five-dimension framework for evaluating state persistence, extension cost, operability, data compliance, and migration reversibility. Readers will also find general migration steps, cloud deployment building blocks, and common pitfalls to avoid when choosing an architecture.

    1. Introduction: Why the “Next-Generation Assistant” Deserves a Calm Evaluation

    New agent projects have been appearing at a rapid pace, and their marketing often highlights claims such as “seamless migration” and “understands you better.” For developers, the real question is not whether to chase the latest release, but three engineering questions:

    1. Does the new architecture fix the structural flaws of the old one?
    2. Is the migration cost manageable and reversible?
    3. For everyday users, do the benefits of installing one more tool outweigh the operational burden?

    This article does not judge any specific implementation. Instead, it abstracts two typical design patterns and compares them at the architecture level, helping readers build their own evaluation criteria.

    2. Abstract Models of Two Mainstream Architectures

    2.1 Centralized Message Routing

    The core of this design is a message routing layer. It unifies access to multiple instant messaging channels, parses incoming messages, calls a large language model, and returns tool execution results along the original path. The processing chain can be summarized as:

    1. Message ingress → Parsing and authentication → Model call → Tool execution → Response routing → Message egress

    The strengths are clear boundaries, easy understanding, and straightforward horizontal scaling of channel integrations. The weaknesses are equally obvious: each conversation turn is essentially an independent context, and execution ends once the tool finishes, with no reusable accumulation layer. Users have to restate the background every time, making it hard to achieve the “gets smoother the more you use it” experience over the long term.

    2.2 Closed-Loop Learning

    Another design splits the system into three independently evolving subsystems, connected by a core conversation loop:

    1. ┌──────────────────────────────┐
    2. │ Core Conversation Loop │
    3. │ (Main Control Logic) │
    4. └──────────────────────────────┘
    5. │ │ │
    6. ┌──────┴─────┐ ┌─────┴─────┐ ┌───┴──────┐
    7. │ Prompt │ │ Tool │ │ Session │
    8. │ Builder │ │ Registry │ │ Store │
    9. └────────────┘ └───────────┘ └──────────┘
    10. │
    11. Persistence and Full-Text Search

    The key differences are three points: prompts are assembled dynamically based on the scenario; tools are managed through a registry and loaded on demand by “tool sets”; and sessions and memory are persisted to a database with full-text search support. This forms a closed loop of “execute—record—retrieve—feed back into the prompt,” which theoretically enables continuous learning.

    3. Engineering Breakdown of the Key Differences

    3.1 Context and Memory: From “Stateless” to “Retrievable State”

    The routing architecture delegates context to external channels or the caller, leaving the service itself nearly stateless. The closed-loop approach treats memory as a first-class citizen: sessions are persisted in a structured form, and combined with a full-text index, relevant historical fragments are recalled by relevance in a new conversation turn and injected into the prompt.

    Privacy and compliance require special attention in engineering: memory persistence means data retention, so tiered storage, deletion policies, and access controls must be designed to avoid accumulating sensitive information locally or in the cloud over the long term.

    3.2 Tool Extension: From “Hard-Coded Branches” to “Registry + Tool Sets”

    Once the number of tools grows, hard-coded branches quickly spiral out of control. The registry pattern abstracts each tool into a unified contract (name, description, input schema, handler function, permission declaration), then groups them into tool sets and loads them on demand. This controls prompt length and makes least-privilege permissions easier to enforce.

    Illustrative definition:

    1. class ToolSpec:
    2. name: str
    3. description: str
    4. input_schema: dict
    5. handler: callable
    6. permission: str # e.g., read / write / network
    7. REGISTRY: dict[str, ToolSpec] = {}
    8. def register(spec: ToolSpec):
    9. REGISTRY[spec.name] = spec

    3.3 Prompt Construction: From Fixed Templates to Layered Assembly

    Layered assembly typically includes a system constraints layer, a capability inventory layer (a summary of the current tool set), a memory recall layer, and a task context layer. The benefit is observability and trimmability: when anomalies occur, you can quickly identify which layer caused the behavior drift.

    4. A Selection Framework: Scoring Across Five Dimensions

    It is better to replace subjective impressions with quantifiable dimensions:

    • State accumulation: Does it support session persistence and retrieval recall?
    • Extension cost: Does adding a new tool require changes to the main control logic?
    • Operability: Are logging, monitoring and alerting, and failure self-recovery complete?
    • Data compliance: Are storage location, encryption, deletion, and auditing complete?
    • Migration reversibility: Can configuration and data be fully exported and rolled back?

    If your scenario is lightweight notifications and Q&A, the routing architecture is sufficient. If you need a long-term companion assistant or cross-session task continuity, the closed-loop architecture is a better fit.

    5. Migration and Implementation Recommendations

    General migration steps (without any specific commands):

    1. Inventory assets: configuration items, memory data, custom tools, and a credentials list.
    2. Define mappings: map old configuration fields to the prompt layers and tool registry of the new architecture.
    3. Validate with small traffic: run a canary release on non-core channels first, checking recall accuracy and tool success rates.
    4. Switch fully while keeping a rollback window.
    5. Establish observability: record latency, tool call chains, and failure reasons for each conversation turn.

    Credential management must use a key management service or environment isolation; never write credentials into a repository. Logs should be desensitized.

    6. Common Cloud Capabilities for Deployment

    Regardless of which architecture you choose, productionization typically relies on several common cloud capabilities: a container platform to host the stateless main control, object storage to hold exportable data packages, a message queue to smooth traffic peaks, logging and monitoring services to ensure observability, and key management to host sensitive credentials. General-purpose capability categories offered by cloud providers such as Baidu AI Cloud can serve as a reference foundation for deploying this type of architecture.

    7. Common Pitfalls

    • Equating “supports migration” with “zero cost,” while ignoring recall quality degradation caused by differences in memory semantics.
    • Assuming more tools are always better, while overlooking prompt bloat and permission sprawl risks.
    • Looking only at demo results, without long-cycle stability and failure recovery validation.

    8. Conclusion

    There is no absolute superiority among architectures—only the degree of fit with the scenario. Scoring with the five-dimension framework first, then validating through small, reversible migration steps, is the prudent approach when facing frequent iterations.