Agent Architecture Evolution: From Message Routing to State Persistence
This article compares two common agent architectures—routing-based and state-based—and explains why architecture, not marketing claims, determines long-term usability. It breaks down the state-based design into a prompt construction layer, a tool registry layer, and a session storage layer, then examines how memory mechanisms, migration costs, and deployment choices shape real-world performance. Readers will find a practical selection guide and a checklist for separating secrets, memory, and skills from code.
1. The Problem: Why the “Next-Generation Assistant” Deserves an Architectural Review
Agent tools are iterating quickly, and a wave of “next-generation personal assistants” has appeared with nearly identical marketing claims: install with a single command, migrate existing configuration seamlessly, and call tools more effectively. For developers, these claims carry little information. What actually determines the long-term experience is the architecture: how context is preserved, how tools are registered and discovered, where session state lives, and whether migration across environments is feasible.
Setting aside specific product attributes, this article abstracts the discussion into two typical architectures:
- A routing-based architecture, whose core is a message routing layer.
- A state-based architecture, whose core is a long-running agent loop plus persistent storage.
2. Routing-Based Architecture: Clear but Without Accumulation
The typical request path of a routing-based architecture is:
Message ingress → Message parsing → Model invocation → Tool execution → Response routing → Message egress
The advantages are obvious: single responsibility, clear layering, and a low cost of onboarding new channels. Once you implement a channel adapter that normalizes external messages into an internal event format, the same model capabilities can be reused across multiple entry points.
The problem lies in the lifecycle. Each turn is treated as an independent context, and the scene is discarded as soon as tool execution finishes. No intermediate artifacts are retained. This leads to three concrete consequences:
- Repeated explanation cost: Users must restate the background over and over, and a large share of the prompt is spent “restoring context” rather than solving the problem.
- No incremental learning: Even if a user corrects a preference once, it does not take effect automatically in the next turn.
- Difficult troubleshooting: Without a traceable execution trail, debugging relies on guessing from logs.
A routing-based architecture is not a wrong choice. It fits scenarios such as “multi-channel notifications plus lightweight Q&A.” But if the goal is a long-term, companion-style personal agent, the absence of a state layer is a hard constraint.
3. State-Based Architecture: A Three-Layer Decomposition Around the Main Loop
A state-based architecture usually revolves around a long-running agent loop, internally split into three cooperating subsystems:
- Prompt construction layer: Responsible for assembling system instructions, history summaries, retrieved snippets, and tool descriptions into the final context. Its key design is layered assembly with budget control, which prevents the context from growing without bound.
- Tool registry layer: Manages dozens of tools through a registry and groups them into several tool sets by task type. Loading tool sets on demand, rather than injecting every tool description on each turn, is an effective way to control context usage.
- Session storage layer: Uses a local embedded database to store sessions and artifacts, and uses full-text search to recall relevant snippets from history.
Illustrative pseudocode:
def agent_loop(user_input, session_id):memory = store.search(session_id, user_input, top_k=5)tools = registry.select(task_type=classify(user_input))prompt = builder.build(system, memory, tools, user_input)result = llm.invoke(prompt, tools)store.append(session_id, user_input, result)return result
The collaboration among the three can be summarized as follows: the storage layer provides the ability to “remember,” the registry layer provides the ability to “do,” and the construction layer orchestrates both within a limited context budget.
4. Key Difference: Memory Mechanisms Set the Ceiling
The most fundamental divergence between the two architectures is not the model but memory. The industry usually divides agent memory into three types:
| Memory type | Content | Implementation focus |
|---|---|---|
| Short-term memory | The current session window | Sliding window plus summary compression |
| Long-term memory | User preferences and conclusive facts | Structured storage plus retrieval recall |
| Procedural memory | Reusable skills and workflows | Skill files plus parameter templates |
A routing-based architecture generally has only short-term memory; a state-based architecture fills in the latter two through persistence and retrieval. Note that more long-term memory is not necessarily better: incorrect writes continuously pollute the context. The write policy should therefore be conservative—only accumulate confirmed facts and reusable workflows, and keep the source and timestamp for each memory entry to make invalidation and rollback easier.
5. Migration and Installation: Making the Cost Clear
From an engineering perspective, “install with a single command” is only a difference in distribution. What truly affects the experience is the portability of configuration and data. A portable solution must cover at least four asset types:
- Runtime configuration (model parameters and how channel credentials are referenced);
- Memory data (session records and preference entries);
- Skill definitions (templates and constraints for reusable workflows);
- Secret material (injected via environment variables or a secret management service, never committed to version control).
For cross-platform support, Unix-like systems can run in a native environment; on Windows, a Linux compatibility layer usually needs to be prepared before installation. This is a runtime dependency issue, not a matter of architectural superiority.
6. Selection Guidance and a Practical Checklist
- If the need is multi-channel reach and lightweight Q&A: prefer the routing-based approach for its simple implementation and low operational cost.
- If the need is long-term collaboration and continuous accumulation: prefer the state-based approach, but it must be paired with a memory governance strategy.
- In either case, keep the three asset types—secrets, memory, and skills—separate from the code to ensure portability and auditability.
When deploying in the cloud, you can compose general-purpose capabilities as needed: use object storage for skill packages and backups, use a message queue to smooth out channel event spikes, use a container platform to host the long-running loop, and use logging plus monitoring and alerting to close the observability loop. To further reduce self-built costs, you can also evaluate general-purpose capabilities offered by cloud vendors such as Baidu AI Cloud, but the decision should be based on your own data compliance and cost model.
7. Conclusion
Tool popularity changes; architectural constraints do not. To judge whether an agent is worth a long-term investment, answer three questions: Does it remember? Can it do? Can it move? Only when all three hold should you consider anything else.
