On-Device LLMs in Mobile OS: Architecture, Agents, and Memory
The deployment of large language models (LLMs) directly on smartphones introduces a distinct set of engineering constraints—limited memory, storage, and power. This article breaks down the practical considerations for integrating on-device models into a mobile operating system: how to calculate real memory footprints for dense and MoE models, how to design a personal agent with safe permission boundaries, why local memory is fundamentally a retrieval-augmented generation (RAG) system, and how to approach multi-model runtimes and distribution. It also outlines a checklist for model deployment and performance validation, and clarifies a few assumptions currently circulating in developer communities around system-level AI features.
On-device large language models are gradually making their way into mobile operating systems. Recent reports from a developer community—based on third-party observations of a mobile OS beta—suggest the presence of a self-developed on-device model tied to system-level agent and local memory features. This information is unconfirmed by the vendor, and this article uses it solely as a starting point for technical discussion. Regardless of the specific product, the core engineering problem is clear: with limited memory, power, and storage, how can a mobile system sustainably support reliable AI features?
1. Calculating Memory Before Choosing a Model Size
On-device model specs are usually defined by parameter count. Take a 3B dense model (3 billion parameters) as a reference. Its weight memory footprint can be estimated as follows:
- 4-bit quantization: ~3×10^9 × 0.5 bytes ≈ 1.5GB
- 8-bit quantization: ~3GB
So the weight for a 3B model is on the order of GB, not hundreds of MB. In actual runtime, KV cache (key-value cache for context), activations, and runtime overhead further increase resident memory. The longer the context, the larger the KV cache.
MoE (Mixture of Experts) models behave differently. A 26B-A4B model has roughly 26 billion total parameters, activating about 4 billion per token. Each inference step is computationally close to a 4B dense model, but all experts’ weights must reside in memory or storage, unless the system supports swapping experts in and out. With 4-bit quantization, 26B weights occupy about 13GB; with 8-bit, about 26GB. The primary cost of MoE, therefore, lies in storage and memory, not computation.
| Item | 3B Dense Model | 26B-A4B MoE Model |
|---|---|---|
| Total params / active per token | 3B / 3B | 26B / ~4B |
| 4-bit weight size | ~1.5GB | ~13GB |
| 8-bit weight size | ~3GB | ~26GB |
| Suitable tasks | Text polishing, summarization, simple Q&A | Complex instructions, multi-step reasoning |
| Key constraint | Resident memory usage | Storage space and memory watermark |
The meaning of a specific version number (for instance, whether it indicates an on-device optimized build) has no public evidence at this point and is not discussed here; refer to official documentation. From an engineering standpoint, a common approach is to keep a small model resident for frequent tasks and load larger models on demand.
2. Personal Agent: Moving from Q&A to Action
The core workflow of an agent involves three steps: intent recognition, task decomposition, and system API calls. Taking “summarize yesterday’s meeting recording and send it to attendees” as an example, the flow involves transcription, summarization, contact matching, and message sending—each step may invoke a different local capability.
On-device agents use Function Calling to generate invocation commands. The model outputs structured parameters, while the actual execution is carried out by system services. Therefore, the model should not hold sensitive permissions directly. A practical permission design should follow this checklist:
- Least privilege: The agent only gets the interfaces required for the current task—e.g., read-only calendar access—without default write permission.
- User confirmation for sensitive operations: Show a confirmation dialog before sending messages, deleting files, or modifying permissions.
- API whitelist: Only allow calls to pre-reviewed interfaces, blocking arbitrary model-generated invocations.
- Audit logging: Record the time, interface, parameter summary, and result of every call for later traceability.
- Prompt injection defense: Treat text from web pages and documents as data, not as instructions to execute.
On-device processing keeps data on the device, but this alone is not a security guarantee. Privilege escalation can still occur, making permission isolation mandatory.
3. Local Memory: Essentially a Local RAG System
LLMs are stateless, and their context windows are limited. What is often called “memory” is essentially a local retrieval system, consisting of the following components:
- Ingestion: Chunk historical conversations, user preferences, and local documents, generate embeddings, and store them in a local vector database.
- Retrieval: Before each inference, retrieve the top-k relevant memory entries (typically 3 to 10) based on the query.
- Injection: Concatenate the retrieved content into the prompt, with a length limit so it does not crowd out the contextual space.
- Invalidation: When a document is deleted, user preferences change, or the model is replaced, the corresponding vectors must be cleaned up or rebuilt.
- Desensitization: Remove sensitive fields such as ID numbers and bank card numbers before storage.
A “Memory” app checking whether the model file exists is a reasonable startup step, but checking existence alone is insufficient. Model files typically reach the GB level and can be corrupted during system updates or when storage is low. A more robust approach is to verify the file’s hash; on failure, fall back to a backup model or prompt the user to re-download.
Whether a Memory app should centrally manage model loading and unloading is not publicly documented. A more common design is to let the system’s inference runtime manage memory watermarks, loading and unloading models according to priority to avoid OOM (out-of-memory). Applications should request resources through system interfaces rather than grabbing memory on their own.
4. Multi-Model Runtime and Distribution Strategy
Some evidence suggests the self-developed model coexists with other on-device models, implying a unified inference runtime that supports multiple formats, such as ONNX, TFLite, or vendor-specific formats. The runtime must handle hardware acceleration (NPU, GPU, CPU), operator adaptation, and memory allocation.
When deploying, the following checklist is worth considering:
- Format compatibility: Verify that the model export format matches the runtime and that operator coverage is complete.
- NPU operator fallback: Automatically fall back to GPU or CPU for unsupported operators and log the fallback rate, since frequent fallbacks degrade performance.
- Memory watermark: Define a warning threshold and a hard limit; refuse to load new models beyond the cap.
- Model verification: Perform hash and signature checks after download.
- Canary and rollback: Roll out new models to a small user cohort first; roll back quickly if crash rates or latency anomalies appear.
- Performance baseline: Record first-token latency, tokens per second, and peak memory as a baseline for version comparison.
On the distribution side, a system can preinstall a 3B-class model to guarantee core features and download larger models on demand for complex tasks. Cloud model platforms can follow the same logic: handle routine tasks locally and send only a small fraction of complex tasks to the cloud.
5. What Developers Should Focus On
The direction of on-device AI is broadly apparent: a small model resident, larger models loaded on demand, memory driven by local retrieval, and strict permission control. Specific versions and feature details remain uncertain. Developers can start with three actions: use the formulas above to estimate the memory budget of target devices; design agent interfaces along the principle of least privilege; and record latency and peak memory on actual hardware—letting measured data, not assumptions, decide the model spec.
