Persistent Routing and Background Execution: A Minimal Multi-Agent Architecture

    This article explains a minimal multi-agent architecture that separates a persistent routing layer from background execution units. It covers why the traditional one-shot request-response model breaks down in real engineering workflows, the design principles behind routing and execution separation, and six common components used to build a runnable skeleton. It also details the task ledger, context isolation, asynchronous execution with a watchdog, and remote result delivery, along with the current limitations and a practical evolution path.

    1. Background: From One-Shot Q&A to Continuous Operation

    Most traditional agent interactions follow a closed loop: the user issues a command, and the system returns a single response. This works well for demos and lightweight Q&A, but it exposes three structural flaws once it enters real engineering collaboration.

    First, interaction gets blocked. When a task involves heavy file I/O, command execution, or long reasoning chains, the main interactive session is occupied for a long time. The user cannot see intermediate progress or inject new requirements.

    Second, contexts contaminate each other. If multiple tasks share the same session context, intermediate conclusions, failed attempts, and irrelevant details from earlier tasks linger and cause “memory bleed” in later tasks, making output quality unpredictable.

    Third, tasks lack lifecycle management. One-shot calls have no notion of state, so you cannot query progress or automatically detect and recover from a stuck task.

    As a result, the industry is shifting focus from “stronger single-shot reasoning” to “task systems that keep running.” The core abstraction is to split the system into two roles: one for communication and scheduling (the routing layer) and one for actual execution (the execution layer). With event triggering, asynchronous execution, state persistence, and external polling, the system evolves from passive answering into continuously receiving and advancing tasks.

    2. Design Principles: Why Routing and Execution Must Be Separated

    Keeping the routing layer lightweight is the first principle of the whole architecture. The reason is concrete: if all the actual work is piled into one persistent session, long-running tool calls block interaction directly, and contexts from different tasks stack on top of each other. The result is a system that gets slower and more error-prone the more you use it.

    After separation, the benefits compound:

    • Interaction stays available: the routing process only handles understanding, decomposition, and dispatch, so response latency stays stable.
    • Contexts are isolated by design: each execution unit has its own session and working directory, with no interference.
    • Concurrency becomes a default capability: multiple tasks can progress at the same time without manual queuing.
    • The failure radius is contained: one misbehaving execution unit does not drag down overall scheduling.

    It is worth stressing that separation does not mean “complete detachment.” The routing layer must still retain the task ledger, progress queries, and fallback handling for exceptions. Otherwise, the system degrades into “fire and forget.”

    3. Minimal Implementation: A Skeleton From Six General Components

    Without trying to replicate every mechanism, you can build a runnable skeleton from six categories of general engineering components:

    1. Persistent routing process: a long-running intelligent session that receives instructions, understands intent, decomposes tasks, and dispatches them.
    2. Persistent terminal session management: use a terminal multiplexer to maintain multiple long-lived sessions, hosting the routing process, the message gateway, and each execution unit separately, so disconnects do not lose the current state.
    3. Remote message entry point: use an instant messaging bot as the unified entry point, where tasks are submitted remotely and results are returned remotely.
    4. Intelligent coding CLI execution unit: handles the actual code reading, modification, and verification work. Any intelligent coding tool that supports CLI invocation can be plugged in.
    5. Periodic scheduled polling: use scheduled jobs to trigger inspections periodically and prompt the routing layer to check the status of each execution unit.
    6. Virtual machine and shared working directory: the whole system runs in a virtual machine, with the working directory pointing to a shared path on the host, giving direct access to existing project files. This forms a minimal separation of storage and compute.

    The overall data flow can be summarized as:

    1. Remote entry -> Persistent routing -> Dispatch to an independent terminal session (execution unit)
    2. -> Background asynchronous progress
    3. Scheduled inspection -> Routing checks status -> Results returned to the remote entry

    4. Key Mechanisms in Detail

    4.1 Persistent Routing: Unified Entry and Task Ledger

    The routing process runs in a persistent terminal session, with its behavior constrained by a system prompt: it only performs intent recognition, task decomposition, dispatch, and aggregation, and avoids doing the actual coding work itself. To compensate for the “stateless” limitation, the routing layer should persist plans, logs, and task records to files, forming the simplest possible task registry.

    A minimal usable ledger structure looks like this:

    1. {
    2. "task_id": "t-20260801-01",
    3. "goal": "Add unit tests for a specified module",
    4. "worker": "session-worker-1",
    5. "status": "running",
    6. "created_at": "2026-08-01T10:00:00Z",
    7. "updated_at": "2026-08-01T10:12:30Z",
    8. "artifacts": ["logs/t-20260801-01.log"]
    9. }

    With the ledger in place, progress queries, failure retries, and manual takeover all have a basis to work from.

    4.2 Execution Units and Context Isolation

    Each execution unit starts in an independent terminal session, bound to its own working directory and its own log file. This solves three things at once: contexts do not bleed, concurrency does not conflict, and logs remain traceable. In practice, generate a unique identifier for each task and use it to name the session and log, which makes inspection and retrospective analysis easier.

    4.3 Asynchronous Progress and Watchdog

    Long tasks must be made asynchronous: dispatch returns immediately, and execution results are reported back through a return channel. At the same time, an external watchdog is needed to cover the risk that “asynchronous means out of control.” Scheduled polling periodically checks the ledger for tasks that have timed out without updates, then triggers a reminder, retry, or termination, and records the decision basis in the logs. The thresholds should be configurable to avoid killing legitimate long-running tasks.

    4.4 Remote Entry and Result Delivery

    The value of the remote message entry point is turning the system from a “local toy” into an “always-available assistant.” The implementation points are message deduplication, session identifier mapping, and targeted result delivery, which prevent results from being misrouted when multiple people and multiple tasks are involved.

    5. Boundaries of the Current Approach

    The gaps in this minimal implementation must be clear: there is no complete task registration and dependency management, no correlation tracking between sessions and tasks, no fine-grained event routing, and no independent state machine management. It validates the feasibility of the main trunk, not the full set of capabilities.

    6. Evolution Path

    There are four directions for future expansion. First, introduce an independent state management service to lift state out of files. Second, build an event bus to enable fine-grained routing and subscription. Third, fill in task dependencies and priority scheduling. Fourth, connect logs and metrics to a general logging service and a monitoring and alerting system for visualization and automatic loss mitigation. If elasticity is needed, execution units can be migrated to a container platform and scaled on demand.

    7. Conclusion

    The core conclusion of this architecture is a single sentence: separate “communication and scheduling” from “actual execution,” trade persistent sessions and asynchronous mechanisms for continuous operation, and use scheduled inspections to cover the risk of losing control. The fewer the components, the clearer the boundaries, and the faster the subsequent evolution.