Build a Local On-Device AI Assistant for Mobile Apps
Medical diaries, corporate documents, personal notes—data must not leave the device. On-device LLM is an architectural solution that guarantees privacy. We have implemented such projects for clients in MedTech and FinTech: the local assistant works without internet, using only the smartphone's computational resources. Our team has 5 years of experience in mobile development and over 30 projects with on-device AI.
Modern flagship devices can run 3B models in INT4 quantization at 15–30 tokens/sec—sufficient for a conversational assistant. However, model and runtime selection critically affects performance and compatibility.
Choosing the Right Model and Runtime for On-Device AI
Apple offers two paths for iOS. Core ML is stable, supports iOS 16+, and automatically uses the Neural Engine. The model is converted via coremltools from PyTorch/GGUF. After conversion, Llama 3.2 3B in INT4 is about 1.8 GB.
import CoreML
class OnDeviceLLM {
private let model: MLModel
init() throws {
let config = MLModelConfiguration()
config.computeUnits = .all // CPU + GPU + Neural Engine
model = try LlamaModel(configuration: config).model
}
func generate(prompt: String) -> AsyncStream<String> {
AsyncStream { continuation in
Task.detached(priority: .userInitiated) {
// tokenize → autoregressive decode → yield tokens
let tokens = self.tokenize(prompt)
for _ in 0..<512 {
let nextToken = self.model.predictNextToken(tokens)
continuation.yield(self.detokenize(nextToken))
if nextToken == self.eosTokenId { break }
}
continuation.finish()
}
}
}
}
Apple MLX (Swift framework, iOS 16+) offers a more convenient API but requires iOS 16+ and works best on devices with unified memory. Official converted models from Apple are available on Hugging Face.
llama.cpp provides the widest selection of models in GGUF format, actively supported by the community. Integration via a C++ bridging header is more complex than Core ML but gives access to any GGUF model.
On Android there are more options and less of a single standard. MediaPipe LLM Inference API (Google) is the most mature solution for Android. It supports Gemma 2B/7B, Phi-2, Llama 2, ExportedModels in TFLite format. Integration via the LlmInference class:
val options = LlmInference.LlmInferenceOptions.builder()
.setModelPath("/data/local/tmp/gemma-2b-it-gpu-int4.bin")
.setMaxTokens(1024)
.setResultListener { partialResult, done ->
runOnUiThread { appendText(partialResult) }
}
.build()
val llmInference = LlmInference.createFromOptions(context, options)
llmInference.generateResponseAsync(prompt)
TFLite with a custom LLM runner is more flexible but requires more integration work.
ExecuTorch (Meta) is the official runtime for Llama on Android, supporting Llama 3.x directly without conversion. It compiles via buck2, which is non-trivial to set up in a Gradle project.
| Device | RAM | Recommended Model | Tokens/sec |
|---|---|---|---|
| iPhone 15 Pro / 16 | 8 GB | Llama 3.2 3B Q4_K_M | 20–30 |
| iPad Pro M4 | 16 GB | Llama 3.1 8B Q4_K_M | 15–25 |
| Samsung S24 Ultra | 12 GB | Phi-3 Mini Q4 | 25–35 |
| Budget Android | 4–6 GB | Phi-3 Mini Q2 / Gemma 2B | 5–15 |
| Old devices | 3 GB | Not recommended | — |
Trying to run a 7B+ model on a phone with 4 GB RAM guarantees an OOM crash. We help select the optimal model for your device and scenario. By switching to on-device AI, clients save up to 80% on server infrastructure and cloud computing costs. For example, one client reduced their monthly cloud bill from $3,000 to $600—a savings of $28,800 annually.
Comparison of Runtimes for On-Device AI
| Runtime | Platform | Strengths | Limitations |
|---|---|---|---|
| Core ML | iOS | Stability, Neural Engine support | iOS only, conversion via coremltools |
| MLX | iOS | Simple API, fast prototyping | iOS 16+, requires unified memory |
| MediaPipe LLM | Android | Ready-made API, Google support | Limited model set |
| ExecuTorch | Android | Native Llama support, small size | Complex build, documentation in development |
| llama.cpp | iOS and Android | Maximum model selection | Complex integration, low-level API |
How We Integrate an AI Assistant: Step-by-Step Plan
- Target device analysis—determine minimum specifications (RAM, chipset, OS version) and select a model with the optimal quality/performance ratio.
- Conversion and quantization—use INT4 (Q4_K_M) for size/accuracy balance. For old devices—Q2_K. Convert to Core ML / MediaPipe / ExecuTorch.
- UI and architecture development—create a model download screen with progress, a chat interface with token streaming, set up Deep Link for assistant invocation.
- Runtime integration and testing—connect the selected runtime, write a wrapper for generation and tokenization. Test on 5+ physical devices.
- Thermal optimization—implement monitoring of
ProcessInfo.thermalState(iOS) orPowerManager.thermalStatus(Android) and adaptive load reduction. - Deployment and monitoring—set up remote model update via manifest, add usage analytics and crash reports.
The Importance of Right Model Loading Strategy
The model cannot be bundled in the app—1.5–3 GB would immediately lead to rejection in the App Store and scare users with a large APK size. The correct approach: first launch → offer to download the model → background download with progress bar → checksum verification.
On iOS: URLSession.downloadTask with backgroundConfiguration—download continues when the app goes to background. Store the file in Application Support (not Caches—it may be deleted by the system when space is low). On Android: DownloadManager or WorkManager with NetworkType.UNMETERED constraint—the user won't use mobile traffic.
Model update: the server publishes a manifest with the current version and SHA-256 sum. On app launch, check the manifest; if the version changed, offer to update.
The Importance of Managing Thermal State
Inference on the Neural Engine/GPU heats the device. For long generations (>200 tokens), monitor thermal state via ProcessInfo.thermalState (iOS)—on .serious, reduce n_threads or temporarily switch to CPU-only inference. On Android—PowerManager.thermalStatus. Battery consumption: a 3B model on iPhone 15 Pro uses ~5–8% battery per 100 requests. This is less than video streaming, so no user warnings are needed. Additionally, techniques like key-value caching and speculative decoding can improve inference speed by up to 3x compared to naive cloud-based assistants, reducing both latency and power consumption.
What's Included in AI Assistant Integration
- Target device analysis and model selection based on their specifications.
- Model conversion to Core ML / TFLite / MediaPipe formats.
- UI development for model download and interaction.
- Token streaming and memory management integration.
- Thermal monitoring and adaptive load reduction.
- Testing on physical devices (5+ popular models).
- Maintenance documentation and team training.
Estimated Timelines
Basic on-device assistant (single platform, Core ML or MediaPipe)—4–5 weeks. Cross-platform with download management, updates, and thermal monitoring—8–12 weeks. Cost is calculated individually based on complexity and required performance. Request a consultation—we'll prepare a plan and estimate.
Core ML Documentation See official documentation for more on Core ML.
Contact us to discuss your project. We guarantee stable operation on devices with 4 GB RAM and above.







