The Architecture and Evolution of Agent Operating Systems: From Scripts to Resident Runtimes
This article explains why script-based agents struggle to serve as long-term "digital employees" and how resident agent runtimes address that gap. It covers the three-layer architecture of a persistent runtime (the model/reasoning brain, the gateway daemon, and distributed perception nodes), declarative definitions that separate capabilities, persona, and permissions, scheduling and lifecycle mechanics such as heartbeats, event triggers, idempotency keys, and graceful recovery, plus security, auditing, observability, and cost controls. It also contrasts resident runtimes with chain-based orchestration frameworks and outlines a staged adoption path from read-only tools to controlled writes, multi-node deployment, resilience, and eventual autonomy.
1. The Starting Problem: Why Script-Style Agents Struggle to Become “Digital Employees”
In early agent practice, developers typically wrote a script, loaded a model client, registered a handful of tool functions, and ran it to completion. This pattern is essentially a “one-shot task”: the process exits, the context disappears, and periodic perception is out of the question. Put such a script into production to handle long-term duties like on-call coverage, inspections, or data reconciliation, and three categories of defects surface immediately.
The first is a lifecycle defect. A task-oriented process cannot express the semantics of “continuous watch.” Any periodic behavior has to be assembled from external timers, leaving state and scheduling split apart. The second is a state defect. Sessions, memory, and task queues are scattered across temporary variables or local files, lost on process restart and impossible to synchronize across devices. The third is a permission defect. Imperative code couples “what can be done” with “when it is done” in the same block of logic, so permission boundaries drift as the code evolves and auditing becomes difficult.
As a result, the industry has gradually moved the agent runtime from a “library” to a “resident service,” using a daemon to carry long-term online presence, configuration to describe behavior, and a node network to extend the range of perception. The following sections discuss the general architecture and engineering essentials of such systems from a neutral perspective.
2. The Target Shape: The Three-Layer Structure of a Resident Agent Runtime
A mature resident runtime can usually be abstracted into three layers with clear responsibilities and stable boundaries.
- Brain layer (model and reasoning): Connects to general-purpose large model capabilities and handles planning, reasoning, and decision-making. Architecturally, the model should be abstracted so that the inference interface is decoupled from business logic, making it easy to switch between different capability tiers and different latency and cost constraints.
- Body layer (gateway daemon): Resides in memory and handles tool registration and discovery, session persistence, task scheduling, permission checks, audit trails, and I/O to hardware or external systems. It is the trusted core of the entire system.
- Perception layer (distributed nodes): Can be a collector running on another server, a container instance, a browser extension, or an edge device. It reports environmental signals and executes authorized actions.
The value of this layering is that cross-device state persistence is managed centrally by the body layer, proactive environmental perception is continuously supplied by the perception layer, and the brain layer stays stateless and replaceable. The three communicate through explicit protocols, so the evolution of any one layer does not break through into the others.
An illustrative directory and responsibility layout:
agent-runtime/gateway/ # Resident daemon: scheduling, permissions, auditingagents/ops_monitor/SOUL.md # Role goals and code of conductTOOLS.yaml # Tools and permission allowlistconfig.yaml # Runtime parametersnodes/ # Perception and execution nodeslogs/ # Structured logs and audit records
3. Declarative Definition: Fully Decoupling Capabilities, Persona, and Permissions
The biggest problem with imperative implementations is that “three things are written together”: what to do, in what tone to do it, and what is allowed to be done. A declarative approach splits them into three readable, reviewable, and versionable configuration files.
Role and goals (example):
# RoleYou are a reliability engineer for a production cluster, tasked with maintaining service availability targets.# Authorized actionsWhen a service is detected as unresponsive, you may restart the specified service.# Reporting requirementsWrite every event to the alerting channel immediately, including the time, impact scope, and actions already taken.
Tools and permissions (example, following a least-privilege and allowlist approach):
tools:- name: service_controlpolicy: allowlistallow:- "status *"- "restart *"- "logs tail 100 /var/log/*"deny:- "delete *"- "poweroff"
Runtime parameters (example):
runtime:model: <inference model identifier>temperature: 0.2loop:heartbeat: 60s # Periodic self-checkmax_steps: 8 # Maximum reasoning steps per roundtimeout: 30s
This style brings three direct benefits. First, permissions are data rather than code, so review and rollback costs are extremely low. Second, persona and goals can iterate independently without affecting the tool surface. Third, configuration can be brought into version control and pipeline validation, reducing “out-of-bounds actions” at the source.
4. Scheduling and Lifecycle: Heartbeats, Events, and Idempotency
The core of a resident runtime is the loop. A common approach is dual-channel driving: a time channel uses periodic heartbeats for inspection and convergence, while an event channel is triggered by node reports for immediate response. To avoid side effects from repeated execution, every action must be designed with an idempotency key, for example “node identifier + event fingerprint + time window,” and the gateway maintains a short-term deduplication table.
Restart and recovery are equally critical. The gateway process should support graceful shutdown: stop accepting new tasks, wait for in-flight steps to converge, persist checkpoints, and then exit. On startup, it should prioritize restoring the context of unfinished tasks rather than starting from scratch. Only this satisfies the continuity requirements of long-term watch.
5. Permissions, Security, and Auditing
Being constantly online means a larger attack surface, so security design must be front-loaded.
- Least privilege: Tool allowlists precise to commands and parameter patterns, default deny; high-risk actions require secondary confirmation.
- Isolated execution: Tools run in a restricted sandbox or separate container, limiting filesystem and network egress.
- Full-chain auditing: Record “who, at what time, based on what context, called what, and got what back.” Logs use a structured format and connect to logging services and monitoring alerts.
- Cost control: Set limits on steps per round, timeouts, and concurrency to prevent runaway reasoning loops.
6. Observability and Operations
It is advisable to break runtime observability into four categories of metrics: scheduling metrics (heartbeat latency, task backlog), tool metrics (call volume, failure rate, latency distribution), model metrics (latency, retry rate, context length), and business metrics (mean event response time, false-positive rate). Logs and metrics should uniformly carry session and node identifiers to enable cross-layer tracing. On the alerting side, distinguish “system anomalies” from “business anomalies” so noise does not drown out critical signals.
7. The Essential Difference from Chain-Based Orchestration Frameworks
Chain-based orchestration frameworks excel at expressing the composition of steps within a single reasoning process, and their lifecycle typically ends when the call ends. Resident runtimes emphasize continuous online presence, state management, and external perception. The two are not replacements but a layered relationship. A common pattern in engineering practice is to use an orchestration framework to carry complex reasoning flows and a resident runtime to carry scheduling, permissions, and node management, letting the “thinking loop” and the “body’s nervous system” each do their job.
8. A Recommended Adoption Path
- Start read-only: Open only query-type tools to validate the scheduling, auditing, and alerting loop.
- Then open controlled writes: Open a small number of reversible actions via an allowlist, with mandatory secondary confirmation.
- Connect nodes: Expand from a single container node to multiple nodes, validating state synchronization and deduplication.
- Improve resilience: Add graceful shutdown, checkpoint recovery, and rate limiting and degradation.
- Only then discuss autonomy: After metrics are stable and false positives are under control, gradually expand the scope of autonomous decision-making.
9. Conclusion
The move of agents from “script” to “operating system” is essentially about making lifecycle, state, permissions, and perception first-class citizens. Declarative definition reduces complexity, the three-layer architecture provides extensible boundaries, and security and observability determine whether it can truly go to production. If an enterprise wants to build such a runtime on top of general-purpose capabilities like the container platform, logging service, and monitoring and alerting offered by Baidu AI Cloud, it can follow the path above and proceed in small steps, closing the loop first and pursuing autonomy later.
