Agent Architecture Evolution: From Message Routing to State Persistence

    This article compares two architectural paradigms for AI agents: a scheduling-based design centered on message routing and a persistence-based design that treats state as a first-class citizen. It explains why routing-only agents lose context across sessions, how to structure memory into working, factual, and procedural layers, and how to close the loop on tool execution with validation, observability, idempotent write-back, and skill distillation. It also covers channel adapters for portability, security and permission boundaries, a quantitative evaluation framework, and practical selection guidance for different requirements.

    Agent Architecture Evolution: From Message Routing to State Persistence

    Discussion around the “next-generation personal agent” has heated up recently. New projects keep appearing, installation has been reduced to a single command, and marketing copy is full of phrases like “seamless migration” and “full replacement.” For developers and technical decision-makers, the more important question is not who is louder, but what these systems actually solve at the architecture level and what they leave unresolved. Setting aside specific products, this article abstracts two typical architectural paradigms and offers reusable design methods and an evaluation framework.

    1. The Essential Difference Between the Two Paradigms

    The first can be called a scheduling-based architecture. Its core is a message routing layer: it receives messages from various instant messaging entry points, parses them, calls a large language model, and routes the model output back to the original channel. The main path looks like this:

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

    This path is clear, easy to implement, and easy to scale horizontally. Its drawback is equally obvious: every conversation turn has an independent context, execution ends as soon as the tool finishes, and task state, user preferences, and historical conclusions are never persisted. The system looks like it is “conversing,” but it is really just stateless forwarding.

    The second can be called a persistence-based architecture. Beyond routing, it introduces an explicit state layer and a skill layer, turning “one-off question answering” into “tasks that keep evolving.” Its abstract path is:

    1. ingress adaptation → intent and task modeling → state read → planning → tool invocation
    2. → write results back to state → skill distillation → multi-channel response

    The difference lies not in model capability but in whether state is treated as a first-class citizen.

    2. How Context Breakage Happens

    The “forgetfulness” of a scheduling-based architecture is not an implementation defect but a design tradeoff. There are four common causes:

    1. Session boundary equals process boundary: when the request ends, memory is released and no external storage takes over.
    2. Limited context window: even if history is concatenated, length limits truncate it and early critical constraints are lost.
    3. No structured memory: all information is stuffed into a single block of text, so retrieval relies only on similarity and precise traceback is difficult.
    4. Tools decoupled from state: tool return values are used only for the current turn and never enter long-term storage, so experience cannot be reused.

    The result: users must repeat background information every time, multi-step tasks cannot progress across days, and the system never gets smarter from corrections.

    3. Three Layers of Persistence

    Fixing these problems requires splitting “memory” into three layers, each addressing a different kind of information.

    • Short-term working memory: intermediate variables, completed steps, and to-do lists for the current task. Its lifecycle is bound to the task and it can be archived once the task ends.
    • Long-term factual memory: stable information such as user role, preferences, environment constraints, and glossaries. It must be precisely readable, updatable, and invalidatable.
    • Procedural memory (skills): successful solution paths abstracted into reusable procedures, including preconditions, step sequences, and failure fallback strategies.

    The three should have different write and read strategies. A sample state structure:

    1. {
    2. "task_id": "t-20260901-001",
    3. "working": {"step": 3, "plan": ["collect", "transform", "verify"]},
    4. "facts": {"preferred_output": "markdown", "locale": "zh-CN"},
    5. "skills": ["table-normalize", "schema-validate"],
    6. "revision": 7
    7. }

    One engineering point matters: state updates must be idempotent. Repeatedly writing back the same tool result should not create ambiguity. Introduce a version number or revision counter with conditional updates to avoid lost overwrites under concurrency.

    4. Closing the Loop on Tool Execution

    Tool invocation is what distinguishes an agent from pure question answering, but “able to call” is not the same as “trustworthy.” A robust loop has at least six stages:

    1. Declaration: describe the tool’s name, inputs, outputs, and side effects with a structured schema so the model can choose.
    2. Validation: check parameter types and business rules before execution; reject unauthorized and dangerous operations.
    3. Execution: set timeouts, retries, and concurrency limits so long-tail requests do not drag down the whole path.
    4. Observability: record call traces, latency, and error codes to form an auditable log.
    5. Write-back: write results into working memory for later steps and the next task to reuse.
    6. Distillation: abstract frequent, stable successful paths into skills to reduce repeated planning overhead.

    Sample pseudocode:

    1. def run_tool(name, args, state):
    2. schema = registry[name]
    3. args = validate(args, schema) # validation
    4. result = invoke(name, args, timeout=30) # execution + timeout
    5. state.working.append({"tool": name, "ok": result.ok})
    6. state.revision += 1 # idempotent write-back
    7. if result.ok and is_reusable(name, args):
    8. state.skills.add(deduce_skill(name, args))
    9. return result

    5. Channel Adaptation and Portability

    Multi-channel support is a common requirement for these systems, but channel differences should not pollute the core logic. The recommended approach is to define a unified message abstraction and confine channel specifics to an adapter layer:

    1. unified message model { sender, channel, text, attachments, reply_handle }

    The core depends only on this model; adding a channel means implementing just an adapter and a reply handle. This keeps business code from being held hostage by platform differences and keeps migration and canary release costs manageable. As for “seamless migration,” in engineering terms it means state can be exported, skills can be serialized, and configuration is separated from data. Only when all three are in place can low-cost relocation be discussed.

    6. Security and Permission Boundaries

    Persistence amplifies both the benefits and the risks. A few baselines are mandatory:

    • Least privilege: grant tools per task, deny by default, and require a second confirmation for sensitive operations.
    • Data classification: encrypt sensitive fields in state, and redact logs before writing them to disk.
    • Rollback capability: keep revision history for state so mistaken writes can be restored to a specified version.
    • Prompt injection defense: treat all external content as untrusted data that must never be executed as instructions.
    • Audit and alerting: trigger monitoring alerts on abnormal call frequency and unauthorized attempts.

    For cloud deployment, these can be assembled from general-purpose capabilities: object storage for state snapshots, a message queue to smooth peaks and decouple long tasks, a container platform for runtime elasticity, and logging plus monitoring and alerting for observability. Baidu AI Cloud offers corresponding capabilities in these general categories, which can be combined as needed rather than binding to a single implementation.

    7. How to Evaluate the Two Architectures

    To avoid being swayed by marketing language, compare them with quantifiable metrics:

    Dimension Observation point Expected direction
    Context retention Cross-session constraint compliance rate Higher is better
    Task completion First-pass rate on multi-step tasks Higher is better
    Tool reliability Call success rate, average latency Success rate up, latency down
    Cost Average model calls per task Lower is better
    Operability Time to locate a failure Shorter is better

    The evaluation set should include three kinds of samples: single-turn factual question answering, multi-step tasks spanning days, and boundary cases involving dangerous operations. Only the third kind exposes the real quality of permission and rollback design.

    8. Selection Guidance

    • If the need is mainly notification forwarding and lightweight question answering: a scheduling-based architecture is enough; focus on channel adaptation and rate limiting.
    • If the need includes long-cycle tasks, personalization, and experience reuse: a state layer and a skill layer are required.
    • If the team is small and lacks operational investment: prefer managed runtimes and general cloud capabilities to reduce self-built burden.
    • If compliance is sensitive: design state encryption, audit trails, and least privilege up front rather than patching them in afterward.

    Conclusion

    The hype around new projects will fade; architectural problems will remain. The standard for judging whether an agent is worth a long-term investment is not complicated: can state be reliably saved and precisely read, can tool invocation form a closed loop, and can skills be distilled from both success and failure. Get these three things solid, and replacing any single layer will not be disruptive. Otherwise, no amount of visibility amounts to more than a short-lived forwarding layer.