AI Agents at the OS Level: A Framework for Unattended On-Device Task Execution

    As AI hardware proliferates, the conversation around "AI phones" often stops at a voice assistant with a large model bolted on. The real dividing line is whether the AI has operating-system-level authority to execute tasks. This article treats that question as a general engineering problem: how to build an on-device agent system that can run unattended. It walks through the overall architecture, task planning, tool-calling protocols, permissions and sandboxing, failure recovery, observability, and evaluation, with illustrative code that developers can adapt in real projects.

    1. Problem Definition: From Answering to Completing

    The capability boundary of a traditional voice assistant is dialogue: the user asks, the system answers. “Unattended” instead demands closed-loop execution: the user states an intent in one sentence, the system completes a multi-step operation without intervention, and returns a verifiable result at the end.

    This introduces three fundamental shifts:

    • The unit of interaction moves from a “turn” to a “task.” A task may last from tens of seconds to several minutes and span multiple apps and system services.
    • The evaluation criterion moves from “is the answer fluent” to “was the task accomplished.” Semantically correct but failed in execution scores zero.
    • The risk model moves from “saying the wrong thing” to “doing the wrong thing.” A single mistakenly triggered write operation can have irreversible consequences.

    So the core of system-level AI is not model parameters but the completeness of the execution framework.

    2. Overall Architecture: Five Decoupled Layers

    An on-device agent that can run unattended is best decoupled by responsibility into five layers:

    1. Perception layer: collects the screen semantic tree, widget attributes, notifications, sensors, and user history to form structured context, rather than relying on screenshots alone.
    2. Cognition and planning layer: decomposes natural-language intent into an executable task graph (DAG), annotating dependencies, parallelism, and preconditions.
    3. Execution layer: drives system capabilities through a unified tool-calling protocol, abstracting away differences between apps and services.
    4. Governance layer: centrally manages permissions, sandboxing, auditing, rate limiting, and human-confirmation policies.
    5. Observability layer: full-chain tracing, replay, metrics, and alerting to support production debugging and continuous evaluation.

    The value of decoupling: models can be swapped while the tool protocol stays stable; governance policies can be tightened without touching business logic.

    3. Task Planning: Compiling Intent into a Task Graph

    The planner must emit a machine-verifiable intermediate representation. Compared with letting the model generate natural-language steps directly, an explicit task graph is easier to validate and roll back.

    1. {
    2. "task": "Organize today's schedule and send a summary",
    3. "nodes": [
    4. {"id": "n1", "tool": "calendar.read", "args": {"range": "today"}},
    5. {"id": "n2", "tool": "weather.read", "args": {"city": "auto"}},
    6. {"id": "n3", "tool": "llm.summarize", "deps": ["n1", "n2"]},
    7. {"id": "n4", "tool": "message.send", "deps": ["n3"], "confirm": true}
    8. ],
    9. "cancelable": true
    10. }

    Key design points:

    • Every node declares the permissions it needs, so the governance layer can determine at compile time whether authority is exceeded, instead of failing halfway through a run.
    • Write-operation nodes must explicitly state whether human confirmation is required; the default is strict.
    • Tasks must support cancellation and idempotency: re-issuing the same task should not produce duplicate side effects.

    4. Tool Calling: A Unified Protocol Beats UI Simulation

    Early industry approaches relied on simulated clicks, which are brittle and hard to maintain: a UI redesign breaks them, and animations and loading timing introduce substantial nondeterminism. The more robust approach is a unified tool protocol that lets the agent call semantic capabilities rather than pixel coordinates.

    1. tool: calendar.create_event
    2. schema:
    3. title: string
    4. start_at: string(ISO8601)
    5. attendees: array<string>
    6. constraints:
    7. require_confirmation: true
    8. max_attendees: 50

    Protocol-based calling yields three benefits: calls can be statically validated; failures can be attributed to specific parameters; permissions can be granted at tool granularity. Only for scenarios that genuinely expose no open capability should the agent fall back to UI operations, and that path should be treated as a “high-risk channel” with separate rate limiting and auditing.

    5. Permissions and Sandboxing: Unattended Requires Control

    Unattended does not mean unconstrained; on the contrary, it demands a finer-grained constraint model.

    • Least privilege: granted temporarily per task and revoked when the task ends, avoiding long-term possession of sensitive permissions.
    • Capability tiers: differentiated policies across four levels — read, internal write, externally visible write, and operations involving funds or irreversible actions.
    • Sandboxed execution: the agent runs in a restricted process space, sensitive data is injected as a masked view, and raw data never leaves the security boundary.
    • Circuit breaker: exceeding thresholds for call volume, failure rate, or anomalous path deviation within a unit of time automatically pauses execution and hands over to a human.

    A simplified policy decision example:

    1. def authorize(node, ctx):
    2. level = node.risk_level # read / write_internal / write_external / irreversible
    3. if level == "read":
    4. return ALLOW
    5. if level == "write_internal" and ctx.rate_ok():
    6. return ALLOW
    7. if level in ("write_external", "irreversible"):
    8. return CONFIRM if ctx.user_present() else DENY
    9. return DENY

    6. Failure Recovery and Observability

    Long-chain tasks will fail; the engineering focus is whether behavior after failure is predictable.

    • State persistence: the task graph and intermediate results are written to disk so execution can resume after the process is reclaimed.
    • Compensating transactions: define inverse operations for writes and roll back in reverse dependency order on failure.
    • Full-chain tracing: use the task ID to link planning, calls, returns, and latency into a replayable trace.
    • Metrics and alerting: track four core metrics — task success rate, average steps, human takeover rate, and rollback rate — where human takeover rate is the most honest signal of maturity.

    On the cloud side, the common practice is to write task state and traces to object storage, decouple events through a message queue, scale the runtime elastically on a container platform, and rely on logging and monitoring/alerting services for diagnosis and on-call coverage. Baidu AI Cloud offers corresponding product categories for these general capabilities and can serve as a reference during architecture selection.

    7. Evaluation: No Evaluation, No Iteration

    Evaluation of an on-device agent should cover three layers:

    1. Tool layer: parameter extraction accuracy and illegal-parameter interception rate.
    2. Task layer: end-to-end success rate, average steps, and rollback rate.
    3. Security layer: interception rate of privilege-escalation attempts, accuracy of confirmation-flow triggering, and sensitive-information leakage rate.

    It is advisable to maintain a fixed task set and a shadow environment, and run a full regression on every model or prompt change to avoid “fixing one scenario and breaking three.”

    8. Suggested Rollout Path

    • Phase 1: start with read-only scenarios such as information aggregation, summarization, and reminders — lowest risk, fastest validation.
    • Phase 2: internal write operations, paired with confirmation and rollback, accumulating failure samples.
    • Phase 3: limited unattended operation, opened only for whitelisted scenarios and time windows, with one-tap takeover retained.

    Conclusion

    The dividing line for system-level AI is not how strong the model is but how rigorous the execution framework is. Compile intent into a verifiable task graph, converge capabilities into a unified tool protocol, constrain risk within permissions and sandboxing, and turn every execution into observable, replayable data — only then does unattended operation move from demo to usable. For developers, this is an upgrade in capability from “building interfaces” to “building a runtime,” and the next threshold for on-device engineering.