The Architecture and Evolution of Agent Operating Systems: A Practical Guide
This article explains why script-based agents struggle in production and introduces the layered architecture of an agent operating system. It covers the perception, gateway, and model layers, declarative definitions for persona, capabilities, and runtime configuration, the end-to-end event-to-action loop, and the practices that make agent runtimes reliable, secure, and cost-efficient. Readers will also find guidance on observability, evaluation metrics, and a phased adoption roadmap.
1. Why Script-Based Agents Fall Short in Production
For the past few years, the typical way to build an agent application has been to write a short program: load a model client, assemble a prompt, register a handful of tool functions, and enter a loop that waits for user input. This approach is extremely efficient for demos and validation, but once it moves into real business use, three structural flaws become apparent.
The first is a lifecycle flaw. The process terminates when the script ends, and the context, task state, and completed intermediate results are all lost. This cannot support “digital workers” that need to run continuously for hours or even days.
The second is a coupling flaw between resources and permissions. Tool invocation logic, permission checks, and business branches are often mixed in the same block of code, so any capability change requires modifying the main flow, making review and rollback expensive.
The third is an environment-awareness flaw. A script can only wait passively for requests; it cannot sense device state, message events, or scheduled conditions, which makes scenarios such as proactive inspection and automated recovery from anomalies difficult to implement.
As a result, the industry has gradually reached a consensus: what agents need is not a longer prompt, but a runtime foundation similar to an operating system—one responsible for scheduling, isolation, persistence, and governance. This article discusses the general technical concept of an “agent operating system” and does not refer to any specific vendor implementation.
2. Layered Architecture: Perception, Gateway, and Model Layers
A mature agent runtime can usually be abstracted into three layers with clear responsibility boundaries that can evolve independently.
2.1 Perception Layer (Node Layer)
The perception layer consists of distributed execution nodes, which can be an edge device, a browser extension, a container instance, or a sensor module on a development board. Its core responsibility is to collect events and execute local actions, such as reading device metrics, capturing user actions, or triggering local scripts. The key design principle of the perception layer is “minimal exposure”: it reports only structured events and never holds model credentials directly.
2.2 Gateway Layer (Runtime Daemon)
The gateway layer is a resident daemon that plays a role similar to a kernel and typically contains five subsystems:
- Tool registration and routing: maintains a capability inventory and maps structured invocation requests from the model to specific executors;
- Permission and policy engine: performs allowlisting, parameter validation, and risk classification before execution;
- Session and state management: stores context, task progress, and intermediate artifacts, and supports resuming from breakpoints;
- Event bus and heartbeat: receives events from the perception layer and triggers proactive tasks on schedule;
- Observability instrumentation: records call chains, latency, token consumption, and failure reasons.
2.3 Model Layer
The model layer connects to different inference services through a unified abstraction, hides interface differences, and handles retries, rate limiting, fallback, and cost accounting. Making the model layer a replaceable component is a key engineering practice for avoiding vendor lock-in.
The three layers communicate through explicit protocols: the model layer never directly touches hardware, and the perception layer never holds keys. This “bidirectional isolation” is the foundation of security.
3. Declarative Definitions: Decoupling Capabilities, Persona, and Permissions
Imperative programming writes “what to do” and “how to do it” together, making agents hard to reuse and audit. A declarative approach splits an agent into three independent description files.
3.1 Persona File: Goals and Boundaries
Use natural language to describe the role, goals, acceptable costs, and escalation path, for example:
# RoleYou are a reliability engineer for a production cluster, and your goal is to maintain the service availability target.# Authorization ScopeWhen probes fail consecutively, you may restart the specified service; all other changes require human confirmation.# Reporting RequirementsWrite all events to the alerting channel immediately, along with the timeline and actions already taken.
3.2 Capability File: Tools and Policies
Capability descriptions use a two-tier structure of “allow list + deny list,” where deny takes precedence over allow:
tools:- name: service_controlpolicy:allow:- "status *"- "restart *"- "logs tail 100 *"deny:- "delete *"- "poweroff"max_params: 3timeout: 30s
3.3 Runtime Configuration: Loop and Model Parameters
runtime:model: <inference service identifier under the unified abstraction>temperature: 0.2loop:heartbeat: 60s # proactive inspection intervalmax_steps: 12 # maximum inference steps per taskbudget: 2000 # token budget per taskstate:persist: truecheckpoint: 5m
This separation brings three direct benefits: capabilities can be governed centrally by the platform team, the persona can be adjusted independently by the business side, and permissions can be reviewed separately by the security team, without blocking one another.
4. The Runtime Loop: The Full Path from Event to Action
A typical proactive operations loop contains six stages:
- Event ingestion: a heartbeat timer or a perception node reports an anomaly event;
- Context assembly: the gateway pulls session history, topology information, and recent change records;
- Inference and decision-making: the model outputs a structured invocation intent rather than free text;
- Policy validation: the engine checks whether the tool is in the allow list, whether parameters are out of bounds, and whether the risk level requires human confirmation;
- Execution and collection: the executor carries out the action and collects the exit code and output summary;
- Review and persistence: write the timeline, update the checkpoint, and trigger an escalation notification if necessary.
The key is steps four and six: the former ensures that “the model does not have the final say,” and the latter ensures that “failures are recoverable and the process is traceable.”
5. Reliability, Security, and Cost Governance
5.1 Reliability
- Idempotent design: all write operations carry a unique request identifier to avoid duplicate execution;
- Circuit breaking and backoff: after consecutive failures reach a threshold, pause automatic actions and hand over to a human;
- Checkpoint recovery: state is persisted periodically, and the process resumes from the most recent checkpoint after a restart.
5.2 Security
- Credentials never enter the model context and are injected by the gateway before execution;
- Least privilege across the entire chain, narrowed along three dimensions: node, tool, and parameter;
- High-risk actions require a second confirmation, and a rollback script is retained.
5.3 Cost
- Set dual budgets of steps and tokens per task;
- Route simple judgments to small models or a rule engine, and escalate to stronger reasoning only when needed;
- Cache results and deduplicate semantically for high-frequency repeated requests.
6. Observability and Evaluation
It is recommended to build three layers of observability: the call layer records the parameter summary and latency of each tool request; the task layer records task success rate, average number of steps, and human intervention rate; the system layer monitors gateway memory, event backlog, and node online rate.
For evaluation, in addition to the accuracy of standard question answering, more attention should be paid to three metrics: “task completion rate,” “unauthorized action interception rate,” and “erroneous action rate.” Use a fixed set of scenarios for regression testing to prevent hidden degradation introduced by persona or policy adjustments.
7. A Phased Adoption Roadmap
In the first phase, implement tool registration, policy validation, and state persistence in the gateway layer, and get the full loop running on a single node. In the second phase, add scheduled heartbeats and an event bus to enable proactive inspection. In the third phase, extend to multi-node perception and a unified observability dashboard. In the fourth phase, introduce canary releases and policy version management so that agent changes follow the same release discipline as code.
8. Conclusion
The move from demo to production for agents is essentially a shift from “a piece of code” to “a runtime.” The layered architecture solves confused responsibilities, declarative definitions solve collaboration efficiency, and the policy engine together with observability solves the trust problem. If an organization wants to host this kind of resident runtime in the cloud, it can build the foundation on general capabilities such as container platforms, message queues, logging services, and monitoring and alerting, so that engineering focus returns to the business goals themselves.
