Agent Architecture: From Message Routing to Learning Loops

    When enterprises connect conversational AI to multiple channels, the first working system is usually a simple pipeline: receive a message, parse intent, call a model, execute tools, and send the result back to the original channel. This article examines why that stateless routing model breaks down as tasks shift from one-shot Q&A to multi-step workflows, and how to evolve toward an architecture with session memory, tool registries, tenant isolation, and auditable configuration migration. It covers the boundaries between tools, skills, and the runtime; how to migrate sessions and credentials safely; observability requirements and common failure modes; and a practical path for choosing between routing-first and learning-loop designs.

    After wiring conversational capabilities into multiple entry points, most enterprises first land on a clear pipeline: receive the message, parse the intent, call the model, execute tools, and route the result back to the original channel. This chain is easy to understand and easy to debug, but by default it treats every turn as an independent transaction. Once a tool finishes, context is discarded; user preferences, failure reasons, and verified operational steps are all lost. As tasks shift from “answering questions” to “getting things done across turns,” the architecture has to answer harder questions: where does state live, how is experience reused in the next invocation, and how can credentials and skills migrate between environments in an auditable way?

    Break the Problem into Designable Objects

    Before discussing architecture, it helps to split the system into a few stable objects rather than debating the merits of one specific implementation.

    • Channel adapters: Normalize text, attachments, and callbacks from different channels into internal messages.
    • Conversation runtime: Handles turn control, model invocation, tool selection, and stopping conditions.
    • Tool registry: Declares tool names, parameter schemas, permissions, and timeouts, instead of scattering calls across prompts.
    • Sessions and memory: Short-term context, retrievable long-term notes, and preferences bound to a user or tenant.
    • Configuration and secrets: Model access, tool credentials, and skill toggles must be migratable, rotatable, and revocable.

    Message-routing systems focus on the first two; learning-loop systems promote the last three to first-class citizens on top of that. The two are not mutually exclusive slogans—they differ in where they draw the state boundary.

    Message Routing: Central Dispatch, Turn Ends and Everything Ends

    The core of a routing architecture is a centralized dispatch layer. External channels only send and receive; the dispatch layer handles parsing, forwarding, and writing responses back. Conceptually:

    Message intake → normalization → model invocation → tool execution → response assembly → message outbound

    Its advantages are practical: the chain is short and latency is predictable; each channel adapter can scale independently; when something fails, you only need to check the logs for that hop. For customer-service notifications, one-off queries, and stateless form filling, this model is sufficient.

    The limitations are equally clear. Context usually exists only within the current request or a very short cache. If tool results are not written to a queryable store, the next turn cannot reference “the inventory we already checked.” Prompts are reassembled from scratch each time, with no compression of previously successful paths. Under concurrent multi-channel traffic, without tenant-level session keys, fragments from different users can easily bleed into the same generation.

    Therefore, a routing layer needs a minimum set of engineering constraints: generate a correlation ID for every message; record input summaries, output summaries, durations, and error codes for every tool call; make response write-backs idempotent so channel retries do not cause duplicate side effects. These constraints still don’t amount to learning—they just make stateless forwarding traceable.

    Learning Loops: Write Results Back to Retrievable State

    A learning loop does not mean the model rewrites its own weights online. The more common and controllable engineering approach is to have the runtime write reusable information into session storage at the end of each turn, and have the prompt builder retrieve it on demand in the next turn. The conceptual structure can be summarized as three cooperating branches:

    • Prompt construction: Assembles system instructions, recent conversation, and retrieved snippets according to the task, permissions, and budget.
    • Tool registration: Centrally manages the tool catalog; the runtime only invokes the authorized subset.
    • Session storage: Holds messages, tool traces, and retrievable notes, supporting keyword or semantic recall.

    The runtime remains a conversation loop: observe, decide, act, record. The difference is that “record” feeds into the next turn’s “observe.” For example, if a query confirms the user’s time zone, that should be written into preferences rather than left in transient context; if a tool’s parameters were rejected by validation, the failure pattern should be noted so the same call isn’t retried verbatim.

    When designing memory, distinguish three types instead of dumping all text into a retrieval store:

    • Working memory: Messages and incomplete steps for the current task; short-lived, bounded by the model’s context window.
    • Episodic memory: Summaries of completed tasks, key conclusions, and cited sources, reusable for similar tasks.
    • Constraint memory: Permissions, prohibitions, output formats, and tenant policies; these take priority over retrieved chatter.

    Retrieval should filter by tenant and permissions first, then perform full-text or vector recall, and finally let the prompt builder trim the results. In multi-tenant scenarios, unisolated full-text search is more dangerous than having no memory at all.

    The Boundary Between Tools, Skills, and the Runtime

    Once the tool count grows, it no longer makes sense to enumerate every capability in one very long prompt. A registry should at minimum include: a stable name, parameter schema, side-effect level, required credentials, and timeout and retry policies. Read-only queries can execute automatically; writes, payments, deletions, and outbound messages should pass through a confirmation or approval gate.

    A skill can be understood as a bundle of tools, prompt fragments, and acceptance criteria. Enabling a skill should be an explicit configuration step, not the model “claiming it learned something” mid-conversation. The value of a loop system is recording acceptance results after skill execution: which steps tend to fail, which parameters require human input. These records are used to improve prompts and default parameters—not to let the runtime bypass permissions.

    An illustrative registry entry only needs to express the contract, without binding to any specific framework:

    1. tool: query_inventory
    2. side_effect: read
    3. inputs: sku, warehouse
    4. auth: inventory.read
    5. timeout_ms: 3000

    What the runtime sees is the contract plus the current authorization, not hardcoded channel logic. This is what allows the same tool set to serve multiple entry points.

    Migrating Configuration, Memory, and Secrets

    When a team switches runtime environments, what gets lost most easily is not the model itself but three things: session data, skill toggles, and credentials. Migration should be broken into repeatable steps rather than one unauditable bulk copy.

    1. Export non-secret configuration: Model routing policies, tool allowlists, skill toggles, retention periods.
    2. Rotate secrets separately: Write new credentials into the target environment, confirm connectivity, then revoke the old ones. Never embed historical secrets in plaintext inside a migration package.
    3. Migrate sessions: Verify ownership per tenant; skip expired records, or records containing sensitive raw text that policy does not permit retaining.
    4. Replay spot checks: Compare tool selections and final answers between the old and new environments using a small batch of read-only tasks—not just check whether the process starts.

    Local development, staging, and production can use different storage, but the object model should be consistent: messages, tool traces, memory entries, and configuration versions. Version numbers let you answer the question “did this behavior change come from the prompt, the tools, or the data?”

    Where to Run and What to Depend On

    Runtimes of this kind generally fit Unix-like environments best: the combination of processes, standard input/output, local files, and background services is straightforward. If office workstations must run a different desktop OS, use a supported compatibility environment, and make data directories, logs, and secret paths configurable so nothing is tied to one machine’s home directory. The installation method itself is not an architectural virtue; being repeatably deployable, having declarable dependencies, and restricting script permissions are the actual launch criteria.

    If a one-click script asks you to pipe remote content directly into a shell, review the script first, pin the version, and validate it in an isolated environment. The safer production approach is delivery via images or package management, combined with a read-only root filesystem and least-privilege accounts.

    Observability and Failure Modes

    Whichever architecture you choose, you must be able to answer four questions: What did the model see? Which tool was invoked? What did the tool return? Which memory entry was ultimately written? Logs should be redacted; secrets and personal identification numbers must never enter full-text indexes.

    Typical failures include: appending full conversation history even after exceeding context limits; retrieval hitting another tenant’s data; a write tool executing twice due to channel retries; and memory cementing one wrong conclusion that subsequent turns keep reinforcing. The corresponding countermeasures are sliding summaries, enforced tenant filtering, idempotency keys for tools, and human correction or expiration policies for memory. Without a correction path, a loop system propagates errors further than a stateless one.

    How to Choose

    Choose based on continuity rather than a feature checklist.

    • Short tasks, no side effects, many channels: Prioritize routing, idempotency, and auditability; a full memory system is unnecessary.
    • Multi-turn tasks that depend on earlier conclusions, with stable tool combinations: Introduce session storage and tiered memory, and limit the scope of automatic writes.
    • Write operations or sensitive data involved: Define permissions and confirmation gates before talking about “learning.” What gets learned is reviewable records, not expanded model permissions.

    A pragmatic evolution path: first ship the routing layer and tool contracts to guarantee traceability; then add summary memory and retrieval for high-value workflows; finally bring skills, configuration versioning, and secret rotation into the release process. Each step can be validated independently.

    If the system runs in the cloud, object storage suits large attachments, message queues suit peak smoothing and asynchronous write-backs, container platforms suit running the conversation loop, and logging and monitoring suit tracking tool failure rates. General cloud infrastructure such as Baidu AI Cloud can provide these categories of capabilities, but the architectural decisions should still rest on session boundaries, permissions, and data retention—not on binding to a particular console workflow. Composing routing or loop architectures from categories of capabilities matters more to long-term maintainability than switching product names.

    Summary

    Message routing answers “where does the conversation come from and where does it go”; the learning loop answers “does the useful information from this turn still exist in the next one.” The former is a subset of the latter, not an outdated alternative. Once tool contracts, tenant isolation, tiered memory, and secret migration are designed properly, an agent can evolve from a one-shot responder into a business system that is auditable, replayable, and incrementally improvable.