Long-Running Online Agent Architecture: System-Level Scheduling and Fault Tolerance

    This article examines how to move from single-task agents to long-running online agents that handle multiple tasks, recover from failures, and reduce the burden on human attention. It analyzes the limitations of session-centric designs and proposes a two-layer, event-driven architecture inspired by operating systems, covering control and execution separation, event queues, asynchronous multi-channel interaction, externalized state, and watchdog-based monitoring. It also discusses cost trade-offs, evaluation metrics, and deployment controls for production use.

    1. Background: From Single-Task Agents to Continuously Online Agents

    Over the past year or two, single-task agents that can call tools and autonomously complete tasks such as coding, retrieval, and data processing have become increasingly common. When a model executes a single task, the need for manual intervention is significantly reduced. The human role shifts from step-by-step operation to goal setting, result review, and decision-making.

    As execution becomes more automated, the system bottleneck begins to shift to human attention. A person who monitors the progress of multiple agents at the same time, judges whether their outputs are reliable, and promptly handles their blocked requests will find that this work itself becomes a new burden. As a result, the industry has begun to explore a new form: agents that stay online continuously, can handle multiple matters at the same time, can proactively discover work, and can recover on their own after errors. This article refers to such systems as long-running online agents.

    2. Core Limitations of Existing Architectures

    Most agents use a “session” as their basic unit. Each session holds independent context, and tasks proceed sequentially within the session. This design is simple and reliable in single-task scenarios, but it exposes several problems in multi-task scenarios.

    1. Synchronous blocking. When a task waits for an external result, the session carrying it is usually occupied. If the system can process other work in parallel only by opening new sessions, resources and context can grow rapidly.

    2. Context confusion. Multiple tasks for the same user are scattered across different sessions, and the information accumulated in each session is invisible to the others. Users need to remember “what information is in a certain session,” which adds cognitive overhead.

    3. Tasks stop when the device or process goes offline. If session state is stored in local process memory, task progress is lost when the process crashes or the device disconnects, and the task must start over.

    The root cause of these three problems is similar: the session serves both as the interaction entry point and as the storage and scheduling layer for task state. Separating these responsibilities is the starting point for the following design.

    3. Design Approach: Borrowing Classic Mechanisms from Operating Systems

    Through decades of development, operating systems have already solved problems such as multi-task scheduling, resource isolation, and failure recovery. Long-running online agents can borrow several core ideas from them.

    3.1 Two-layer architecture: separation of control layer and execution layer

    The system is divided into two layers. The control layer receives events, determines task ownership, maintains global state, and provides a unified interaction entry point. The execution layer handles specific reasoning and tool calls, and each execution unit focuses only on the subtask currently assigned to it.

    With this separation, the user always interacts with the same agent rather than a set of disconnected sessions. Execution units can be created, destroyed, or replaced at any time without affecting the user’s perception.

    3.2 Event-driven: drive workflows with events rather than polling

    In traditional approaches, agents often poll task status at a fixed frequency, which wastes resources and can easily miss time-sensitive information. In an event-driven model, external messages, tool return results, timer triggers, and exception alerts all enter a unified queue as events, and the control layer dispatches them to the corresponding processing logic.

    The benefit of an event queue is decoupling. When a new event source is added, existing execution logic does not need to be modified. At the same time, the queue naturally supports peak shaving: a sudden burst of events can be queued and processed without overwhelming the execution layer.

    1. # Illustrative code only, showing the event dispatch idea
    2. def dispatch(event, task_index):
    3. task = task_index.lookup(event.task_id)
    4. if task is None:
    5. task = task_index.create_from(event)
    6. task.enqueue(event)

    3.3 Asynchronous multi-channel interaction

    Users may interact with the agent through instant messaging group chats, comments on code hosting platforms, email, or other collaboration tools. Asynchronous multi-channel design requires the system to convert input from different channels into internal events, and then return output in the format of each channel.

    Two points require attention in practice. First, the same task may switch between multiple channels, and the system must ensure consistent task identifiers. Second, asynchronous replies should include the necessary context summary so that users do not need to restate their requirements when switching channels.

    3.4 Separation of storage and compute: externalized state

    Execution units should be stateless or weakly stateful. Task context, intermediate results, checkpoints, and pending queues are stored in independent persistent storage, and compute resources are responsible only for reading state, executing one step, and writing back the result.

    Separation of storage and compute brings three benefits. First, after an execution unit crashes, a new unit can recover from the latest checkpoint. Second, the same state can be reused by multiple execution units, which facilitates elastic scaling. Third, centralized state management makes auditing and rollback easier.

    In implementation, common foundational components such as object storage, key-value storage, and message queues can be used. The key is to clarify when state is written and what consistency requirements apply.

    1. # Illustrative code: write a checkpoint after each completed step
    2. def run_step(task_id, state_store, executor):
    3. state = state_store.load(task_id)
    4. result = executor.run(state.next_action)
    5. state_store.save_checkpoint(task_id, state.apply(result))

    3.5 External watchdog

    A watchdog is a monitoring component independent of the execution layer. Execution units periodically report heartbeats, and the watchdog checks whether heartbeats time out, whether a task has made no progress for a long time, and whether output has triggered predefined exception rules. Once a problem is found, the watchdog is responsible for restarting the execution unit, recovering from a checkpoint, or escalating the task to human handling.

    The watchdog must be independent of the monitored object; otherwise, if the execution layer itself fails, monitoring will fail along with it.

    1. # Illustrative code: heartbeat-based timeout detection
    2. def watchdog_tick(workers, timeout_s, now):
    3. for w in workers:
    4. if now - w.last_heartbeat > timeout_s:
    5. w.restart(from_checkpoint=w.latest_checkpoint())

    4. Key Trade-offs: Trading Resources for Time and Stability

    The above design is not without cost. The main costs of long-running online agents usually appear in the following areas.

    Inference and context cost. To allow multiple tasks to proceed in parallel without interfering with each other, the system often needs to maintain independent context for each task and reload the necessary information before each decision. This increases the number of inference calls and the number of input tokens.

    Decision frequency and batching. If routing or scheduling decisions are reasoned about one by one, latency and overhead are both high. Combining multiple pending decision events into a batch can spread the fixed overhead of a single inference call, but it introduces additional waiting time. Batch size and waiting window need to be balanced against business response requirements.

    Cache benefit and consistency. Reusing already-computed context can significantly reduce repeated overhead. However, the more aggressive the cache, the higher the risk of stale or inconsistent state. A reasonable approach is to set explicit invalidation conditions for the cache and force refreshes at key points.

    Passthrough and abstraction level. For simple requests, the system can bypass the full scheduling flow and execute directly to reduce overhead. But the more passthrough paths there are, the harder it is for unified monitoring and auditing to cover all behavior.

    Therefore, architecture choice is essentially a trade-off among “cost, speed, and controllability.” There is no universal optimal solution; the decision needs to be made based on task type, tolerated latency, and budget.

    5. Evaluation: How to Determine Whether the System Is Truly Effective

    Before introducing long-running online agents, teams need to establish a reproducible evaluation method to avoid judging results solely by subjective impression. It is recommended to design metrics from the following dimensions.

    Completion latency. Measure the distribution of time from task submission to completion, focusing on the median and tail percentiles. Tail metrics can reflect the proportion of tasks that are stuck for a long time.

    Stability. Count the number of tasks interrupted by process crashes, timeouts, or dependency failures, as well as the proportion that complete successfully after recovery from checkpoints.

    Context correctness. Sample and check whether the agent references incorrect information in cross-task scenarios, and record the misuse rate.

    Resource efficiency. Count the average number of inference calls, total input and output tokens, and compute time per completed task, and compare them with a single-session baseline.

    Human burden. Count the number of times human intervention is required and the average human handling time. This metric directly reflects whether the system truly reduces the attention burden.

    The evaluation environment should be as close to real workloads as possible. Synthetic workloads help with rapid iteration, but conclusions need to be validated in real scenarios; otherwise, the system’s actual performance may be overestimated.

    6. Deployment Recommendations and Risk Control

    Follow the principle of least privilege. Execution units should be granted only the tools and data access permissions required to complete the current task. Operations involving data deletion, sending external messages, production deployment, or permission changes should require explicit confirmation.

    Set human acceptance checkpoints. Continuous online operation does not mean full autonomy. For high-impact outputs, such as code merges, external document publication, and data writes, human review should be retained.

    Keep complete audit logs. Every event, every decision, and every tool call should record a timestamp, task identifier, and execution result to facilitate later tracing and problem diagnosis.

    Prepare failure degradation. When the watchdog cannot recover a task after multiple restarts, the system should hand the task over to a human and include the completed steps and failure reason, so that users do not have to investigate from scratch.

    Control cost limits. Set budget thresholds for inference calls and token usage per task or per time window, and pause and notify the responsible person when the threshold is exceeded.

    7. Summary

    The core of long-running online agents is to transform the agent from “an executor attached to a session” into “a persistent entity managed uniformly by the system.” By borrowing ideas from operating systems such as layered scheduling, event-driven design, externalized state, and external monitoring, it is possible to solve problems such as synchronous blocking, context confusion, and stopping when offline. At the same time, the system must pay for inference cost, batching latency, and cache consistency.

    In actual deployment, teams should first clarify task types and tolerated latency, then choose an appropriate architecture combination, and continuously validate effectiveness with metrics such as completion latency, stability, context correctness, resource efficiency, and human burden.