Offline On-Device LLMs on Mobile: Engineering Multi-Agent Stability in Practice

    This article explains how to evaluate on-device large language models in mobile personal knowledge management apps. It covers how to define offline task boundaries, isolate faults across cross-platform bridges, manage engine and session lifecycles, schedule multi-agent inference through a unified queue, budget memory, and test for correctness, stability, and privacy.

    1. Evaluate the System, Not Just the Model

    For personal notes, knowledge management, and task assistance on phones, the value of an offline model is not only fewer network requests. It lets part of the intelligent processing happen on the device itself. Users can organize notes, extract to-do items, and summarize text without a network connection, and sensitive content has less chance of leaving the device.

    However, a model that can run and an app that can be used reliably over time are separated by a significant amount of engineering work.

    On-device experience is shaped by at least four factors:

    • Model capability: whether the model understands the task, follows constraints, and produces usable output.
    • Inference runtime: whether the model loads correctly, manages compute resources, and handles cancellation and errors.
    • Mobile integration: whether cross-language calls, thread switching, and lifecycle handling are reliable.
    • Business orchestration: whether multiple agents compete for resources, and whether tasks have priorities and recovery mechanisms.

    For this reason, a single answer’s quality is not enough to judge an on-device solution. App crashes, device restarts, or blocked tasks should not be attributed to the model alone. A more useful evaluation target is the complete system formed by the model, the runtime, the device, and the business workload.

    2. Define the Business Boundaries of Offline Capability First

    Take a personal knowledge management app as an example. A local agent can handle text classification, summary generation, key information extraction, and candidate tag recommendations. Before integrating it, however, you should answer three questions.

    1. Which tasks must be completed offline

    Tasks that are good candidates for local execution usually have a controlled input size, a clear output format, and low consequences when they fail. For example, generating candidate titles for a single note is easier to verify and constrain than letting a model autonomously rewrite an entire knowledge base.

    For tasks such as cross-document analysis or long-context reasoning, measure the resource cost first, then decide whether to include them in the first release. Just because a model accepts text input does not mean every text task is suitable for execution on a phone.

    2. Whether “local execution” really means data does not leave the device

    Local inference is only one part of the privacy path. Log uploads, crash reports, remote backups, attachment handling, and usage analytics can also involve user data.

    If an app claims to work fully offline, check every related module. Confirm the claim with offline tests and network behavior audits. Disabling the model’s remote call entry point is not enough.

    3. Whether any modality is unsupported

    Before you treat image and audio analysis as available, check whether the model and runtime actually support those inputs. A unified business interface does not mean the underlying capabilities are the same. If the current runtime only supports text, you need a separate local preprocessing module or must clearly indicate that the task is unavailable.

    Capability detection must be part of business routing.

    3. Start from a Minimal Reproducible Path Instead of Stacking Abstractions

    Cross-platform apps usually connect to native inference runtimes through plugins. The call path can cross several boundaries:

    App UI → Cross-platform bridge → Native adapter layer → Inference runtime → Compute backend

    Each added wrapper can introduce risks such as lifecycle desynchronization, incorrect thread context, and inconsistent object release timing. This does not mean every wrapper layer is unstable. Calling the lower-level interface directly is not automatically more reliable either.

    The correct approach is controlled-variable troubleshooting:

    1. Fix the device, OS version, model file, and input content.
    2. Establish a baseline with the minimal example provided by the runtime.
    3. Temporarily disable multi-agent workflows, attachment handling, and background tasks.
    4. Verify model loading, single generation, streaming output, cancellation, and release separately.
    5. Gradually restore the cross-platform bridge and business logic.

    If the full app causes a full device restart but the minimal example does not reproduce it, the only conclusion is that the two call paths differ in ways worth investigating. That is not enough to prove that a specific plugin is the root cause.

    Full device restarts and ordinary app crashes need separate handling. A restart may involve the system, drivers, temperature, or resource pressure. Analyze it with system event logs, memory status, and device diagnostics. Without sufficient evidence, do not conclude that “the model caused the restart” or that “the wrapper layer is defective.”

    4. Use Layered Lifecycles for Engines and Sessions

    Loading an on-device model usually involves reading files, mapping weights, initializing the compute backend, and preparing caches. Creating a new engine for every request can add high startup overhead and cause resource fluctuations.

    A common design is:

    • Reuse the engine in a controlled way within the app process.
    • Create sessions by task or conversation scope.
    • Release sessions promptly after a task completes.
    • Shut down and reinitialize the engine serially when switching models.

    However, a “single engine instance” is not a complete solution. You also need a state machine to constrain its behavior:

    Uninitialized → Initializing → Ready → Shutting down → Closed

    If initialization fails, move to a separate failure state and keep the conditions for retrying. If multiple requests arrive while the engine is uninitialized, they should share one initialization process instead of loading the model repeatedly.

    The following is conceptual pseudocode that does not depend on a specific runtime. It is not an actual API:

    1. Run local task(task):
    2. Enter the unified inference queue
    3. Check whether the task has been cancelled
    4. Ensure the engine is in the Ready state
    5. Create a task session
    6. Try:
    7. Run generation and return results incrementally
    8. Finally:
    9. Wait until generation has stopped
    10. Release the task session
    11. Return execution permission

    Two details are easy to overlook.

    First, a session is not necessarily lightweight. It may hold context state, attention caches, and temporary buffers. Its resource usage changes with input and output length.

    Second, canceling the wait in the UI does not mean the underlying computation has stopped. If the upper layer releases the session immediately while the runtime is still accessing related resources, lifecycle errors can occur. Confirm that the task has terminated according to the runtime’s cancellation semantics before cleaning up resources.

    5. Parallel Agents Do Not Mean Parallel Local Inference

    A personal knowledge app may run several agents at the same time, such as card organization, knowledge archiving, and attachment analysis. From a business perspective, these tasks are independent. From a hardware perspective, they often compete for the same memory and compute resources.

    For this reason, design business task concurrency and model execution concurrency separately.

    1. Use a unified queue in the early stage

    If the runtime’s concurrency capability has not been verified, a conservative approach is to build a unified scheduler within a single app process. Multiple agents submit tasks to the scheduler, and the scheduler runs model inference serially.

    Compared with having each module manage its own locks, a unified scheduler makes it easier to ensure that every entry point follows the same resource constraints. The protected scope should not cover only the moment a session is created. It should cover the entire execution phase that the runtime requires to be mutually exclusive.

    If the app uses a multi-process architecture, ordinary in-process locks cannot coordinate across processes. You need an additional design for inter-process scheduling.

    2. Locks handle mutual exclusion, queues handle user experience

    A global lock alone can cause long background tasks to block foreground interactions. You also need:

    • Priority: user-initiated requests take precedence over background organization.
    • Queue limits: cap the number of pending tasks to prevent unlimited backlog.
    • Deduplication and merging: combine repeated analyses of the same note.
    • Cancellation while queued: remove expired tasks before they run.
    • Fairness: prevent low-priority tasks from waiting indefinitely.

    For tasks that have already started, whether they can be preempted depends on whether the runtime supports reliable cancellation. Even with support, decide how to handle partially generated results. Interrupting a task does not mean it succeeded.

    6. Memory Budgets Cannot Rely on Model File Size Alone

    A model file’s size does not equal its runtime memory use, and it certainly does not equal GPU memory use. On mobile devices with a shared memory architecture, the way compute resources are reported can vary by system.

    Actual resource consumption usually includes:

    • Model weights and their memory mappings.
    • Input processing and intermediate computation buffers.
    • Attention caches that grow with context length.
    • Session state and output caches.
    • Preprocessed data such as images and audio.
    • Memory used by the app UI, databases, and other business modules.

    Therefore, confirming that the device can load the model is not enough. Also verify peak memory use with long inputs, long outputs, repeated calls, and switching between foreground and background.

    In practice, you can start with these measures:

    1. Set reasonable limits on input and output length.
    2. Split long documents into segments, extract information from each, and then aggregate structured results.
    3. Limit the number of sessions alive at the same time.
    4. Avoid repeatedly passing entire long texts across the cross-platform bridge.
    5. Merge streaming output moderately to reduce how often the UI updates.
    6. Pause non-essential background tasks when memory pressure rises.

    Segmenting also has a cost: relationships across segments can be lost. Do not treat segment summaries as lossless replacements. Keep source positions based on the business need, and let users check the original text.

    7. Keep Capability Differences Visible in a Unified Interface

    Local and remote models can share a unified business abstraction, which reduces the dependency of upper-layer agents on specific inference implementations. However, the unified interface should express capability differences, not hide them.

    Beyond sending messages and receiving results, the business layer should be able to determine:

    • Whether streaming generation is supported.
    • Whether task cancellation is supported.
    • Which input modalities are supported.
    • The input size currently accepted.
    • Whether structured output with constraints is available.
    • Whether the request is currently loading, queued, or generating.

    For models without native structured output constraints, you can ask for a fixed format through prompting. You must still parse the output, validate fields, and check business rules. If the format is wrong, retry within limits or return a clear failure. Never write arbitrary text directly into the business database.

    For operations such as deleting records, overwriting knowledge content, or modifying tags in bulk, the model is better suited to generating candidate plans. A deterministic program should validate those plans, and the app should ask the user to confirm when necessary.

    8. Build an Acceptance System for Correctness, Stability, and Privacy

    Whether an on-device solution is usable should be decided by test results, not by a single demo.

    1. Functional correctness

    Prepare test samples that cover real business scenarios. Evaluate summary omissions, information extraction accuracy, classification consistency, and the success rate of structured parsing separately. For key fields, define clear rules for judging errors.

    2. Performance and interaction experience

    Record model cold-load time, request queue time, time to first output, and total task time separately. Reporting only the generation speed can hide the effect of loading and queuing on user experience.

    Tests should also cover changes in temperature and power consumption during sustained use. Do not treat short-term peak performance as long-term performance.

    3. Stability

    Repeatedly load models, generate output, cancel tasks, switch models, and exit the app. Watch whether resource usage keeps growing. Add scenarios such as foreground and background switching, low memory, insufficient storage, and dense task submission.

    4. Observability and privacy

    Diagnostic logs should record task IDs, stages, durations, resource status, and error categories. By default, they should not record user text, full prompts, or sensitive generated results. If detailed information must be collected, obtain explicit authorization and set a retention period.

    9. Conclusion: On-Device Value Depends on Clear Engineering Boundaries

    An offline large model on a mobile device opens a new way to build personal knowledge management features. However, reliable experience is not determined by model size or by the quality of a single answer alone.

    A safer rollout order is: limit the first release to low-risk tasks, establish a minimal runtime baseline, then complete the engine and session lifecycle, introduce a unified queue and resource budget, and finally verify performance, stability, and privacy boundaries on real devices.

    A mature local agent does not run as many tasks as possible at once. Under limited resources, it knows which tasks can run, when they should run, how to recover after a failure, and which actions must be returned to the user for confirmation.