Building an Always-On AI Agent Architecture with Router and Worker
This article explains how to move AI agents from a traditional request-response model to an always-on architecture using a separated Router and Worker design. It covers the core design principles, a minimal implementation built from six general-purpose components, and key mechanisms such as asynchronous execution, event triggers, and a lightweight watchdog. It also outlines the current limitations and a three-step evolution path toward observability, scheduling, and governance.
1. From Request-Response to Always-On: A Shift in Agent Architecture
Most traditional AI coding tools follow a request-response model: the user issues a command, the system completes a single task, and returns the result. The problem with this model is that the agent cannot proactively sense environment changes, long-running tasks block interaction, and multiple tasks tend to share the same context, causing states to contaminate each other.
An always-on agent architecture treats the system as a long-running process: it continuously receives tasks, maintains context, schedules concurrent execution, and proactively raises alerts on exceptions or timeouts. The core idea is not to make a single model “smarter,” but to solve three problems through engineering structure: unblocked interaction, isolated task context, and observability for long-running tasks.
2. Core Design Principle: Separating Router and Worker Responsibilities
The most critical step in this architecture is splitting “communication and scheduling” from “concrete execution” into two types of roles.
- Router (persistent scheduling layer): Only responsible for receiving instructions, understanding intent, decomposing tasks, selecting executors, and aggregating results. It stays lightweight and does not personally handle time-consuming code modifications or long-chain tool calls.
- Worker (execution layer): Each Worker runs in an independent session with its own context and lifecycle, focused on completing a single assigned task.
This separation brings three direct benefits:
- Low interaction latency: The Router is always responsive, while long tasks proceed in the background.
- Context isolation: Different tasks do not interfere with each other, avoiding context “cross-contamination.”
- Controllable failures: An exception in a single Worker does not drag down global scheduling.
A schematic division of responsibilities can be expressed as:
User / Remote Entry|[Router] —— Task understanding, decomposition, dispatch, aggregation|+---+---+| |[Worker] [Worker] —— Independent sessions and contexts
3. Minimal Implementation: Six General-Purpose Components for the Core Loop
To validate the feasibility of the architecture, a minimum viable version can be built with as few general engineering components as possible. The goal is to run through the “schedule-execute-supervise” loop, not to replicate all mechanisms.
- Persistent session: Hosts the Router, entry gateway, and each Worker, ensuring process persistence so tasks are not lost after disconnection.
- Remote entry: Submit tasks and return results through an instant messaging bot, enabling mobile operation.
- AI coding executor: Use a command-line AI coding tool as the Worker to perform specific development tasks.
- Scheduled trigger: Use periodic tasks to check Worker status, forming a lightweight watchdog.
- Shared workspace: Point to a shared directory on the host machine, directly accessing existing project files, forming a minimal form of storage-compute separation.
- Virtualized environment: The entire system runs in an isolated virtual machine, ensuring security and resource boundaries.
The value of this combination is: the core assumptions of the always-on architecture can be validated without relying on any proprietary platform capabilities.
4. Key Mechanism Breakdown
4.1 Persistent Router: Unified Entry and Task Translation
The Router runs in a persistent session. After receiving remote messages, it uses system prompts and a message mirroring mechanism to convert natural language into structured tasks, then starts the corresponding Worker. The key design point is “the Router does not do the work”: once the Router personally executes long tasks, interaction is blocked and context is contaminated.
4.2 Asynchronous Execution: Backgrounding as the Prerequisite for Low Latency
After a task is dispatched to an independent session, it runs in the background and the Router is released immediately. Results are returned via files, logs, or messages. Asynchronization decouples “submit-execute-return” and is the cornerstone of the always-on architecture.
4.3 Event Triggers and Watchdog: From Passive Waiting to Active Progress
Periodic checks give the system the ability to “proactively inspect”: verify whether long-running tasks are still progressing, whether they have timed out, and whether reminders or retries are needed. This addresses the observability problem in always-on scenarios.
4.4 State and Context Management: Files as State
Persisting plans, logs, and task records as files is the simplest state management approach. It is naturally auditable and recoverable, and leaves room for later introduction of a task registry, thread association, and fine-grained event routing.
5. Capability Boundaries and Evolution Direction
The shortcomings of the current minimal implementation are equally clear: it lacks a complete task registry, a mechanism for associating tasks with threads, fine-grained event routing, and an independent state management service. The evolution path is recommended in three steps:
- Step 1: Observability — Unify logs and metrics, and integrate with general logging services and monitoring/alerting capabilities.
- Step 2: Schedulability — Introduce task registration and priority queues, supporting retries and idempotency.
- Step 3: Governance — Improve permissions, auditing, and resource quotas to support multi-tenancy and team collaboration.
6. Practical Recommendations
- First run through the minimal loop, then gradually add governance capabilities, avoiding over-engineering.
- Stick to the responsibility boundary of “light scheduling, heavy execution”; this is the key to preventing architecture degradation.
- Use file-based state as the starting point, then smoothly migrate to professional state storage later.
- Treat the watchdog as a first-class citizen; the stability of always-on systems is mainly guaranteed by supervision mechanisms.
Overall, the layered design of Router and Worker, combined with asynchronous execution, event triggers, and lightweight supervision, provides a path with minimal components and practical engineering feasibility for building always-on, scalable agent systems.
