On-Device LLMs in System Kernels: How AI Agents Run Large Language Models Locally

    On-device LLMs are moving into mobile system code. This article takes a test build of a new mobile OS that surfaced in the developer community as a starting point. It sets product specifics aside and explains the general engineering behind running LLMs locally on phones, tablets and cars: why models are shifting from the cloud to devices, how names like E2B, 3B and 26B-A4B reflect model size and architecture, and how devices detect and manage local models. It also covers how on-device AI agents complete multi-step tasks, compares on-device and cloud inference, and outlines cloud-edge collaboration architecture options and practical tips for developers.

    1. What On-Device LLMs Solve

    Recently, developers dug up test code from a new mobile OS release. It contains version identifiers for the latest release of a device vendor’s in-house model family, along with device-side logic for detecting model files. The findings themselves are straightforward, but they clearly point to a trend that is picking up speed: large language models (LLMs) are moving from the cloud down to local execution on devices such as phones. Using this as a starting point, this article sets aside product specifics and looks at the general engineering behind on-device LLMs.

    An on-device LLM is a language model that has been trimmed and compressed to a smaller parameter count and deployed directly on a device, such as a phone, tablet, or car head unit. It runs inference locally instead of sending every request to the cloud. Its core value comes down to four points:

    • Privacy: User data never has to leave the device to complete inference, so sensitive information stays put.
    • Low latency: Local inference removes network round trips, bringing interaction response closer to real time.
    • Offline availability: Basic capabilities keep working with no network or only a weak signal.
    • Cost control: Moving high-frequency, lightweight inference off the cloud reduces compute costs on the server side.

    That is why device vendors are willing to build their own models into the system layer. It strengthens a differentiated user experience and reduces dependence on external cloud services.

    2. What Model Names Tell You About Size: 2B, 3B, and Mixture of Experts

    Identifiers such as “4 E2B,” “3.8 3B,” “26B-A4B,” and “30B” essentially describe model size and architecture. Knowing how to read them helps you estimate what a model needs to run:

    • Numbers (e.g., 3B, 26B): Usually the total parameter count, in billions. More parameters generally means a higher capability ceiling, but also greater memory and compute requirements.
    • E2B: Generally means “equivalent 2B,” a model optimized to run at an overhead close to that of a 2-billion-parameter model.
    • 26B-A4B: A typical Mixture of Experts (MoE) label. It means roughly 26 billion parameters in total, with only about 4 billion activated per inference. This “large total, small active” structure is the mainstream approach for balancing capability and overhead on-device.

    In short, on-device models do not chase the largest parameter count. They aim to keep activated parameters within a manageable range under limited memory and power.

    3. How Devices Detect and Manage Models

    The code’s most notable detail is that the device checks whether model files are present locally and maintains an internal model list. In engineering terms, this is a typical on-device model lifecycle management mechanism:

    • Capability negotiation: Before launching an AI feature, the system first checks whether the local model is ready and the version matches. It then decides whether to use on-device inference or fall back to the cloud.
    • Version management: The list typically retains multiple historical versions to support staged rollouts, rollback, and compatibility.
    • Storage and memory checks: Before loading, the system verifies file integrity and available device memory to avoid runtime crashes.

    The following pseudocode shows how the model is selected:

    1. def resolve_on_device_model(device):
    2. manifest = load_manifest(device.model_store) # Load the local model manifest
    3. candidates = [m for m in manifest if m.is_compatible(device)] # Filter out compatible models
    4. if not candidates:
    5. return fallback_to_cloud(device) # Fall back to the cloud if no local model is available
    6. # Among compatible models, prioritize capability while taking memory usage into account
    7. return max(candidates, key=lambda m: (m.quality_score, -m.memory_mb))

    A simplified model manifest might look like this:

    1. {
    2. "family": "on-device-assistant",
    3. "versions": [
    4. { "ver": "3.8", "sizeClass": "3B", "status": "deprecated" },
    5. { "ver": "4.0", "sizeClass": "E2B", "status": "active",
    6. "quantization": "int4", "minRamMB": 3072 }
    7. ]
    8. }

    4. The On-Device AI Agent Loop

    In the code, the model sits under a core module that supports AI agent features. This suggests that the end goal of on-device models is not simple question answering, but driving agents (Agents) to complete multi-step tasks locally. A typical on-device agent loop has four steps:

    1. Intent understanding: The model parses the user’s natural-language instruction and determines the task type.
    2. Planning and decomposition: The task is broken down into executable sub-steps.
    3. Tool invocation: Local capabilities are called to perform actions, such as calendar, photo library, notifications, and system settings.
    4. Result aggregation and feedback: Execution results are combined and returned to the user in natural language.

    Compared with cloud agents, on-device agents have a clear advantage: they sit close to the data, call local tools quickly, and respond with low latency. The challenge is that the permission boundaries and security isolation of local tool sandboxes must be carefully designed to prevent actions that exceed authorized scope.

    5. On-Device vs. Cloud: Engineering Trade-Offs You Can’t Avoid

    On-device inference is not meant to replace the cloud. Instead, the two divide the work, and the trade-offs need to be weighed deliberately:

    Dimension On-device inference Cloud inference
    Latency Low (no network round trips) Affected by network conditions
    Privacy Data stays on the device Data must be uploaded
    Capability ceiling Limited by memory and power Can use large models
    Cost Spread across devices Server-side compute overhead
    Typical use cases High-frequency, lightweight, sensitive Complex, long-context, compute-intensive

    A mature solution often follows a cloud-edge collaboration model. Lightweight, high-frequency tasks run locally, complex tasks go to the cloud, and both are connected through a unified task scheduling layer.

    6. Deployment Challenges and Cloud-Edge Architecture Recommendations

    Getting on-device AI working in production means tackling these challenges head-on:

    • Memory and power: Reduce overhead with techniques such as quantization (e.g., int4/int8), model distillation, and loading models on demand.
    • Security isolation: Run local tool calls inside controlled sandboxes, and verify model files with digital signatures to detect tampering.
    • Staged rollout and rollback: Rely on the versioned manifest to roll out new models gradually and roll back quickly if problems appear.
    • Cloud collaboration: The device handles real-time interaction and privacy-sensitive steps, while the cloud takes on model training, complex inference, and delivering new capabilities.

    In a cloud-edge architecture, the cloud platform typically serves as the backend that supports on-device capabilities. It can close the loop with general-purpose cloud services: object storage to distribute and host model files, container platforms to run cloud inference services, log services and monitoring and alerting to track the invocation quality and anomalies of on-device models, and model training platforms for iteration and staged releases. Baidu AI Cloud, for example, offers general-purpose services such as object storage, container platforms, log services, and monitoring and alerting. These can serve as a cloud-edge foundation for model delivery, cloud inference, and observable operations.

    7. Practical Tips for Developers

    • Choose the model after defining the use case: Start by putting high-frequency, low-latency, and privacy-sensitive tasks on-device, and leave the rest to the cloud.
    • Manage with a manifest: Use the manifest to handle versions, quantization methods, and compatibility, rather than hardcoding them.
    • Design graceful degradation: Fall back to the cloud seamlessly when the local model is unavailable so the user experience stays continuous.
    • Plan for observability up front: Define logs, metrics, and alerts from the beginning to support ongoing optimization.

    Overall, “finding” on-device models in system code is just one signal of the broader shift toward intelligent devices. What really matters for developers is understanding on-device model naming, the detection and management mechanisms, and the cloud-edge architecture. Whoever strikes the best balance among privacy, latency, cost, and capability will be best positioned for the next phase of on-device AI.