Why LLM Agents Need a Router/Worker Layered Architecture

    This article explains why LLM agents that handle long, concurrent, or multi-step tasks can benefit from a Router/Worker layered architecture. It covers the context window constraints behind the design, how the split reduces cross-task context pollution and blocking, the structured contracts and cloud components used in production, and the cases where a single-agent design is still the better choice.

    Early-stage LLM agents often use an “all-in-one” monolithic design. Developers choose a capable large language model, attach a large set of external tools, and write a long prompt covering every rule. They then expect the model to handle every task alone. This approach works well for proofs of concept and simple demos. However, as the number of tasks grows, task chains get longer, and concurrency increases, the weaknesses of the monolithic design become serious. The Router/Worker layered architecture was built for these complex scenarios. This article examines the logic behind the architecture, the problems it solves, and its practical limits.

    1. Core Driver: Scarce Context Windows and Different Requirements

    Many people assume a layered architecture copies human organizations, such as a manager assigning work to employees. That is only the surface. The main technical driver is a conflict between a scarce computing resource, the LLM context window, and the different needs of the Router and the Worker.

    During agent operation, the Router and the Worker need very different context:

    1. The Router (orchestrator agent) needs a “bird’s-eye view.” The Router coordinates the whole system. It tracks the lifecycle of several tasks at once, including each task’s progress, where it is blocked, and which component should receive the next step. It does not need the detailed execution history of each task. It relies on task summaries, status flags, and key milestones. Its context needs are therefore low-bandwidth, and its interaction pattern is short turns of quick judgment and decisions.
    2. The Worker (execution agent) needs a “first-person view.” The Worker advances one task in detail. It calls tools to edit code, run scripts, or investigate errors. During this work, exception stack traces, abandoned approaches, and large raw tool outputs can each determine the next action. Its context needs are therefore high-bandwidth, and its interaction pattern is long turns of deep exploration.

    If one session performs both roles, the high-bandwidth execution data quickly fills the limited context window. The low-bandwidth global coordination information then gets buried or truncated. The system eventually loses control over the overall state.

    2. Core Problems the Layered Architecture Solves

    Separating the Router and the Worker avoids two serious flaws of the monolithic design.

    2.1 Cross-Task Context Pollution

    When a single agent handles Task A and Task B, the logs and abandoned approaches from Task A’s trial and error stay in the context window. When the agent switches to Task B, the model can be affected by attention interference. It may treat Task A’s wrong conclusions or intermediate states as preconditions for Task B.

    Some developers try to prevent this by adding instructions such as “Please ignore the previous content and focus on the current task.” In practice, this soft instruction is unreliable. A single sentence does not free or clear the context budget. The Router/Worker architecture provides physical isolation of context. Each task runs in its own Worker sub-session. When the task ends, the sub-session can be destroyed or archived, so tasks do not contaminate each other.

    2.2 Blocking and Slow Responses

    In a monolithic design, if the main session waits synchronously for a slow tool, such as a full code build or a large test run, the session stays blocked until the result returns. It cannot receive new user messages or track the progress of other parallel tasks. To the user, the agent appears to have frozen.

    With a layered architecture, the Router dispatches slow work to a Worker and immediately switches to asynchronous monitoring. It can keep handling new user requests or schedule other tasks. This non-blocking dispatch is key to improving concurrency and user experience.

    3. Engineering Practice: Boundary Contracts and Cloud-Native Coordination

    Physical isolation alone is not enough. A production system also needs strict boundary contracts and state management.

    3.1 Task State Machine and Boundary Contracts

    Router-Worker communication should not rely on free-form natural language. It should use a well-defined state machine and structured contracts. For example, a task package from the Router must include explicit input parameters and expected output. When a Worker finishes or hits an error, it must return an execution summary and a status code in the agreed JSON format.

    1. // Simplified contract for the Router dispatching a task to a Worker
    2. {
    3. "task_id": "task_1024",
    4. "action": "execute_test_suite",
    5. "payload": {
    6. "repo_url": "...",
    7. "branch": "feature/x"
    8. },
    9. "callback_topic": "agent_router_inbox"
    10. }

    3.2 Decoupling with General Cloud Services

    In large production environments, the Router and Workers usually run on different compute instances. Reliable asynchronous communication and state persistence can be built with general-purpose cloud-native components. A message queue can decouple task dispatch from execution. Object storage can archive intermediate outputs and logs from Workers. A logging service can collect the run details of all Workers in one place for troubleshooting. To build a highly available agent system, Baidu AI Cloud’s general-purpose container platform can scale Worker nodes elastically, so the system can handle peak task loads.

    4. When Not to Use a Layered Architecture

    The Router/Worker architecture has clear advantages, but it does not fit every case. Good system design does not start from a pattern and then search for a problem that fits it.

    If an agent only handles simple single-turn Q&A, or runs short, strictly linear tasks that do not need concurrency, a layered architecture adds communication overhead and maintenance cost. The main value of the layered architecture lies in concurrency and isolation. When task complexity does not fill a single context window, and there is no risk of synchronous blocking, the monolithic design remains the most efficient choice.

    Conclusion

    The Router/Worker layered architecture does not exist to show off or imitate human organizations. It is a fine-grained way to allocate the scarce computing resource of the LLM context window. By physically separating information flows, it removes two persistent problems: cross-task contamination and synchronous blocking. As the field pursues artificial general intelligence, a core skill every developer needs is using system architecture to offset the limits of the models themselves.