AI Agents and On-Device Hardware: Engineering Practices for the Era of Accessible AI
This article explains how the shift from model scarcity to engineering scarcity is reshaping AI development, and presents a practical reference architecture for building reliable agent systems. It covers a four-layer abstraction of application forms, the six core modules of a production agent, retrieval-augmented generation for trustworthy answers, device-cloud collaboration and routing for on-device AI, the unique constraints of embodied intelligence, and cost, observability, and governance practices. Developers will find concrete guidance, code examples, and a staged rollout path for taking AI from the cloud to the physical world.
1. What Has Actually Changed: From Model Scarcity to Engineering Scarcity
Over the past two years, the barrier to accessing large model capabilities has dropped significantly. The industry’s main challenge has shifted from “can we obtain a usable model” to “can we embed the model into business workflows in a stable, low-cost, and governable way.” The in-browser assistants, search Q&A, general-purpose conversational assistants, and task-oriented agents described in the source material, along with form factors such as glasses, phones, personal computers, chips, and robots, are all different facets of the same thing: moving inference from cloud data centers to a position closer to the user, and connecting it to real-world data and actions.
For developers, this means a shift in focus:
- Previously, the concern was which model to call and how large its parameters were.
- Now, the concern is how to organize context, orchestrate tools, degrade gracefully on failure, attribute costs, and measure effectiveness.
In other words, AI engineering is becoming a discipline of “system capabilities” rather than a one-off API integration.
2. Four Layers of Application Forms and a Unified Abstraction
Despite the variety of product forms, they can be abstracted into four layers based on “distance from the physical world,” all sharing the same underlying capabilities:
- Information interaction layer: intelligent search, conversational assistants, and in-browser side assistants. The core challenge is retrieval quality and answer credibility.
- Task execution layer: task-oriented agents that can decompose goals, call tools, and write back to business systems. The core challenge is controllability and rollback.
- On-device carrier layer: personal computers, phones, glasses, and so on. The core challenge is compute, power consumption, and privacy boundaries.
- Physical execution layer: embodied intelligence and robots. The core challenge is real-time performance, safety redundancy, and the sim-to-real transfer gap.
The value of a unified abstraction is that all four layers require the same main pipeline: “context construction + planning and decision-making + tool/executor invocation + state memory + evaluation feedback.” Building this pipeline into a reusable runtime is the only way to avoid rewriting it every time a new form factor is added.
3. A Reference Architecture for Agents: Containing Uncertainty
A production-ready agent typically consists of six modules:
- Context assembler: responsible for assembling and truncation strategies for system instructions, user input, retrieved snippets, and history summaries.
- Planner: decomposes goals into subtasks and decides whether to run them serially, in parallel, or with human confirmation.
- Tool registry and routing: declares tool capabilities and side-effect levels using structured descriptions.
- Execution sandbox: isolates the runtime environment and restricts network, file system, and permissions.
- Memory layer: distinguishes short-term session state from long-term user preferences; writes must be revocable.
- Evaluation and tracing: records the input and output of each step, supporting replay and attribution.
Tool declarations should be kept “narrow and precise”: one tool does one thing and declares its side-effect level explicitly, so the runtime can decide whether human confirmation is required:
{"name": "query_order_status","description": "Query fulfillment status by order ID; read-only operation","side_effect": "none","parameters": {"type": "object","properties": { "order_id": { "type": "string" } },"required": ["order_id"]}}
For write operations, a two-phase “propose first, then execute” flow is recommended, turning high-risk actions from a model’s momentary decision into auditable, explicit steps:
def handle(user_goal):plan = planner.decompose(user_goal)for step in plan:tool = registry.get(step.tool)if tool.side_effect != "none":proposal = executor.dry_run(tool, step.args) # generate a change previewif not human_approve(proposal): # human gatereturn {"status": "rejected", "step": step}result = executor.run(tool, step.args) # execute inside the sandboxmemory.append(step, result)if evaluator.should_stop(result):breakreturn memory.summary()
4. Where Trustworthy Answers Come From: Retrieval Augmentation Is Not Optional
The dividing line between a conversational assistant and intelligent search often lies not in the model but in the retrieval pipeline. A robust retrieval-augmented approach includes at least:
- Document governance: chunking granularity and metadata (source, time, permission tags) must be stored along with each snippet, and permission filtering must happen at the retrieval stage rather than being patched after generation.
- Hybrid recall: keyword recall handles exact matches and proper nouns, vector recall handles semantic similarity, and the two sets of results are fused and re-ranked.
- Re-ranking and pruning: coarse recall followed by fine ranking controls the number of snippets entering the context, reducing noise and cost.
- Citation alignment: every conclusion in an answer should trace back to a specific snippet; content that cannot be supported should be explicitly marked as uncertain.
- Fallback on failure: when recall is empty or confidence is low, return “no supporting evidence found” instead of generating freely.
A schematic retrieval flow:
def answer(query, user):candidates = hybrid_recall(query, top_k=50)candidates = [c for c in candidates if can_access(user, c)] # permission check upfronttop = rerank(query, candidates)[:6]if not top or best_score(top) < THRESHOLD:return {"text": "The available material does not cover this question", "citations": []}resp = llm.generate(prompt=build(query, top), need_citation=True)return {"text": resp.text, "citations": [c.id for c in top]}
5. Device-Cloud Collaboration: The Key Engineering for AI Entering the Physical World
When capabilities move down to personal computers, phones, glasses, or robots, the architecture must explicitly distinguish three types of workloads:
- Always-on device tasks: wake word detection, simple intent recognition, text rewriting, image preprocessing, and other high-frequency, low-complexity tasks that demand low latency and offline availability.
- Bursty device tasks: document summarization, local image understanding, and other medium workloads constrained by memory and thermal power, requiring task queuing and degradation.
- Heavy cloud workloads: complex reasoning, long-context analysis, and cross-system orchestration that push the capability ceiling.
The core of the collaboration strategy is the “routing decision,” that is, determining where a request should execute. Practical criteria include latency budget, context length, data sensitivity level, remaining on-device compute and battery, and network quality. It is advisable to make routing an observable policy layer rather than scattered conditionals in business code:
def route(req):if req.sensitive and device.offline_capable(req):return "on_device"if req.estimated_tokens > DEVICE_LIMIT or req.need_strong_reasoning:return "cloud"if device.battery < 0.2 or device.thermal_throttle:return "cloud"return "on_device"
Model compression is a prerequisite for on-device feasibility. Common techniques include quantization, distillation, pruning, and operator-level optimization. It must be emphasized that compression inevitably causes capability loss, so a two-tier evaluation of “on-device small model + cloud large model” must be established, making clear which tasks allow degradation and which must fall back to the cloud.
Privacy boundaries must also be implemented in the architecture: personally identifiable data is processed on-device first, and the cloud receives only the necessary de-identified snippets; memory writes must be viewable and deletable; and log collection follows the principle of minimization.
6. The Special Constraints of Embodied Intelligence
Robots bring uncertainty from the text world into the physical world, and the engineering focus changes accordingly:
- The closed-loop latency from perception to decision is more stringent, typically using a layered frequency design with low-frequency high-level planning and high-frequency low-level control.
- Safety redundancy cannot be omitted; an emergency stop and torque-limiting mechanism independent of the AI decision chain is required.
- There is a distribution gap between simulation training and real-world deployment, requiring continuous real-data feedback and recalibration.
- Action logs must be traceable for incident review and liability determination.
7. Cost, Performance, and Governance
The cost structure of AI applications differs from traditional services, with the main expenses concentrated in inference and retrieval. Controllable optimization measures include context pruning and summary compression, caching (layered exact and semantic caches), batching and concurrency scheduling, selecting model tiers by task difficulty, and pinning high-frequency simple requests to the device.
Observability should cover four categories of metrics: quality metrics (task success rate, citation accuracy, human takeover rate), performance metrics (time to first token, end-to-end latency, failure rate), cost metrics (per-task inference cost, cache hit rate), and security metrics (blocked unauthorized access attempts, blocked sensitive content). Without quality metrics, an AI system degrades into a black box that “looks usable.”
On the governance side, models and prompts should be treated as deliverables requiring version management, and any change must go through canary release and regression evaluation; tool permissions follow least privilege; and external input content should be treated as “untrusted” to prevent prompt injection from entering the decision chain via retrieved snippets or web content.
8. A Recommended Rollout Path
- Pick a high-frequency scenario with clear boundaries and low failure cost to close the loop, such as internal knowledge Q&A or a read-only query assistant.
- Build the evaluation set before writing features, and drive iteration with real failure samples.
- Turn retrieval and the tool layer into platform capabilities reusable across multiple business lines.
- When introducing on-device processing, run a side-by-side validation first, compare results with the cloud, and then shift traffic.
- Only then expand to write operations and physical execution, and complete auditing and rollback in tandem.
In this process, general cloud capabilities (such as object storage, message queues, container platforms, log services, and monitoring and alerting) and the general infrastructure categories offered by Baidu AI Cloud mainly serve data hosting, asynchronous decoupling, elastic scaling, and observability support. Specific choices should return to the business’s own latency, compliance, and cost constraints.
Conclusion
What the democratization of AI truly brings is not the explosion of any single product, but an overall lowering of the engineering barrier and a raising of responsibility: the easier capabilities are to obtain, the greater the weight of system design, evaluation, and governance. By solidly building the four foundations of the agent runtime, the retrieval pipeline, device-cloud routing, and the evaluation system, both assistants on a screen and robots stepping into reality can evolve stably on the same engineering paradigm.
