Architecture and Practices for Mobile LLM Applications

    This article breaks down the architecture of mobile LLM applications, covering intent routing between fast and deep modes, RAG pipelines, multimodal preprocessing, device-cloud collaboration, reliability and cost controls, evaluation, and common anti-patterns. It offers engineering guidance for teams building AI assistants on mobile devices.

    1. From “One Entry Point” to “Two Capability Layers”: Product Abstraction for Mobile AI Assistants

    When delivering LLM capabilities on mobile, the product is often reduced to a single chat box. What actually needs to be designed, however, is two capability layers: one optimized for low-latency instant responses, and one optimized for high-accuracy complex reasoning. Mixing both layers in the same call path is the most common architectural mistake in practice—it slows down simple Q&A with reasoning overhead, while complex questions get truncated too early due to insufficient budget.

    The mature approach is to perform intent routing on the client side: short factual queries, format conversion, and simple rewrites go through the fast lane; questions involving multi-step computation, long-document understanding, or repeated self-verification go through the deep lane. Routing signals can come from input length, whether an attachment is included, whether explicit reasoning trigger words are present, or an explicit user switch.

    1. def route(query, has_attachment=False, user_mode=None):
    2. if user_mode in ("fast", "deep"):
    3. return user_mode
    4. if has_attachment or len(query) > 512:
    5. return "deep"
    6. return "fast"

    2. Engineering Differences Between the Two Modes

    The core metric for fast mode is time to first byte. It relies on streaming output, streamlined prompt templates, a smaller context window, and as short a retrieval chain as possible. In engineering terms, “perceived speed” should take priority over “completeness”: deliver the conclusion skeleton first, then fill in the details.

    The core metrics for deep mode are accuracy and explainability. It requires a longer reasoning budget, multiple rounds of self-checking, and tool calls for verification when necessary. The key here is not to make the model “think longer,” but to decompose the problem into verifiable sub-steps, each with a clear input-output contract.

    Resource quotas for the two modes must be isolated. If they share the same timeout and token budget, deep requests will crowd out capacity for fast requests, showing up as overall jitter during traffic peaks.

    3. Retrieval Augmentation: Decoupling Knowledge Freshness from the Model

    Model weights are static, while user questions are often time-sensitive. Retrieval-Augmented Generation (RAG) decouples freshness from parameters. The pipeline typically has four steps: query rewriting, recall, reranking, and constrained generation.

    Query rewriting addresses the mismatch between colloquial questions and retrieval syntax. The recall stage combines keyword and vector paths—the former excels at proper nouns, the latter at semantic similarity. The reranking stage uses a finer-grained scoring model to compress the candidate set. The generation stage requires the model to answer only based on retrieved snippets and to provide verifiable citation locations.

    1. query -> rewrite -> [lexical recall, vector recall] -> rerank -> grounded prompt -> stream out

    The “no evidence, no answer” strategy deserves emphasis: when recall confidence falls below a threshold, explicitly state that information is insufficient rather than letting the model fill in freely. This is the most effective and lowest-cost means of suppressing hallucinations.

    4. Multimodal Input: The Real Challenges of Photo-Based Problem Solving and Document Parsing

    Capabilities like photo-based problem solving, file uploads, and image text recognition form an independent preprocessing pipeline in engineering, not an add-on feature of the model. It includes image quality validation (blur, glare, skew), layout analysis, text recognition, formula and table structure restoration, and only then does structured text enter the model.

    The difficulty concentrates on structure restoration. A table flattened into plain text loses row and column semantics, and any computation the model performs on it will inevitably be wrong. A workable approach is to define intermediate representations for different content types—for example, converting tables into a structured format with header declarations, converting formulas into parseable expressions, and explicitly instructing in the prompt that “original values must not be altered.”

    1. doc = parse(upload)
    2. payload = {
    3. "text": doc.plain_text,
    4. "tables": doc.tables, # preserve rows, columns, and headers
    5. "formulas": doc.formulas, # structured expressions
    6. "meta": {"pages": doc.page_count, "lang": doc.lang}
    7. }

    5. Device-Cloud Collaboration and Privacy Boundaries

    Mobile does not have to choose between “fully on-device” and “fully in the cloud.” A workable split is: the device handles intent recognition, sensitive information redaction, result caching, and lightweight rewriting; the cloud handles heavy reasoning, retrieval, and multimodal parsing. This both reduces round trips and ensures sensitive fields are processed before leaving the device.

    Data boundaries should be written as auditable rules: which fields are prohibited from upload, retention duration for uploaded content, and the granularity allowed in logs. Log redaction must apply across the entire chain, including retrieval requests and error reports—otherwise leaks are likely during troubleshooting.

    6. Reliability, Cost, and Observability

    Three categories of metrics must be observed simultaneously: latency (time to first byte and overall), quality (citation hit rate, manual sampling pass rate), and cost (input and output volume per session). Missing any one of them will send optimization off course.

    Effective cost control measures include: context compression and deduplication, caps on the retrieval candidate set, tiered caching (exact cache and semantic cache), and allocating different model tiers per mode. Caches need invalidation policies—time-sensitive content should not enter long-lived caches.

    For observability, it is recommended to establish a unified trace identifier spanning device and cloud for a single session, attaching routing decisions, recall results, rerank scores, and timeout retries to the same trace, making it easier to pinpoint whether the issue lies in retrieval or generation.

    7. Evaluation System and Rollout Cadence

    Before launch, prepare at least three evaluation sets: factual Q&A, multi-step reasoning, and multimodal documents. Metrics should look beyond the final answer to whether citations are verifiable, whether formatting is parseable, and whether refusals are appropriate.

    The recommended cadence is gradual rollout: start with small traffic to validate latency and error rates, then expand step by step. Run a fixed regression set on every model or prompt change to avoid “fixing one scenario and breaking three.” Combining the evaluation set with online sampling is what keeps it reflective of the real distribution.

    8. Common Anti-Patterns

    First, handing routing logic entirely to the model, making cost and latency uncontrollable. Second, binding retrieval and generation without constraints, letting the model ignore retrieval results and improvise. Third, doing only text recognition for multimodal input without structure restoration. Fourth, lacking redaction and invalidation policies for logs and caches. Fifth, monitoring only availability, not quality and cost. Avoiding these problems costs far less than reworking after the fact—boundaries and contracts should be fixed at the architecture stage.