Architecture and Engineering Practices for Mobile LLM Applications

    This article abstracts the product form of a mobile AI assistant into a technical blueprint for building large-model capabilities from scratch. It covers the dual-mode interaction design that trades latency against quality, a four-layer client-cloud architecture, and three core workflows: mode routing and inference scheduling, retrieval augmentation with web search, and multimodal input handling for files and images. It also addresses engineering governance for performance, cost, and stability, along with security, compliance, and an evaluation framework, showing how retrieval-centric context assembly and observability-driven iteration determine the product's upper bound.

    1. Introduction: From “Working” to “Controllable” Mobile AI Assistants

    Over the past two years, delivering large language model capabilities to everyday users through mobile clients has become one of the most common product forms in the industry. An AI assistant that uses a mobile app as its entry point is typically distributed for free in app stores and works immediately after installation against a cloud-hosted foundation model, with no self-deployment required. The core competitiveness of such products lies not in “whether a model is connected,” but in how mature the interaction design, inference mode scheduling, context management, retrieval augmentation, and engineering governance are.

    Setting aside specific product attributes, this article abstracts the topic into “the technical architecture and engineering practices of mobile LLM applications.” It discusses the key problems a team must solve to build similar capabilities from zero, how to design the system in layers, and how to evaluate quality and cost. Cloud capabilities referenced here are expressed as generic categories, such as object storage, message queues, container platforms, logging services, and monitoring and alerting.

    2. Abstracting the Product Form: Dual-Mode Interaction and Capability Boundaries

    Mobile AI assistants generally offer two interaction modes, and the difference between them is essentially a trade-off between “latency first” and “quality first.”

    • Fast mode: aimed at instant question answering, pursuing low time-to-first-token and a brisk interaction rhythm. It typically uses a model with a smaller parameter count or a distilled model, and disables or weakens the explicit reasoning process.
    • Deep thinking mode: aimed at complex problem analysis, allowing the model to output an explicit chain of thought, trading longer latency for higher accuracy and explainability.

    Beyond conversation, the common capability set also includes web search augmentation, content generation and rewriting, document parsing and summarization, photo recognition and problem solving, file and image upload, and optical character recognition (OCR). Together these capabilities cover three high-frequency scenarios: learning, office work, and daily life.

    It is worth emphasizing that capability boundaries must be made explicit at the product layer: capabilities the model does not have (such as real-time database queries, precise numerical computation, or strongly time-sensitive information) should be supplied through tool calls or retrieval, rather than relying on the model to “answer from memory.”

    3. Overall Architecture: A Layered Design for Client-Cloud Collaboration

    A robust implementation is usually divided into four layers.

    1. Client layer: responsible for the conversation interface, streaming rendering, local caching, permission requests (camera, photo library, files), and reconnection over weak networks.
    2. Access layer: responsible for authentication, rate limiting, canary routing, and protocol conversion (turning mobile requests into a unified inference request).
    3. Capability orchestration layer: responsible for mode selection, tool-call orchestration, retrieval augmentation, context assembly, and result post-processing.
    4. Model and data layer: includes the inference service cluster, vector retrieval service, object storage (raw files and images), and logging and monitoring.

    The key to client-cloud collaboration is “do not put on the cloud what should be done on the device.” For example, initial OCR cropping, image compression, pre-filtering of sensitive information, and incremental maintenance of conversation summaries can all be done on the client side, which both reduces bandwidth and cuts cloud compute consumption.

    4. Key Workflow 1: Mode Routing and Inference Scheduling

    Mode routing should not be left entirely to manual user switching; it should be decided jointly by “explicit intent + automatic determination.” In engineering terms, a combination of rules and a lightweight classification model can be used:

    1. def choose_mode(query: str, has_file: bool, user_pref: str):
    2. # Explicit preference takes priority
    3. if user_pref in ("fast", "deep"):
    4. return user_pref
    5. # Complexity signals: multiple constraints, reasoning needed, long document
    6. complex_signals = ["why", "compare", "reasoning", "prove", "steps", "evaluate"]
    7. score = sum(1 for s in complex_signals if s in query)
    8. if has_file or score >= 2 or len(query) > 200:
    9. return "deep"
    10. return "fast"

    The scheduling layer must also handle three engineering problems. First, timeout and fallback: when deep mode times out, it automatically falls back to fast mode and shows a notice. Second, concurrency isolation: the two modes use separate resource pools so that long reasoning requests do not crowd out instant question answering. Third, observability: record mode hit rate, time-to-first-token, full response duration, and failure reasons.

    Model knowledge has a boundary of timeliness, and web search together with retrieval-augmented generation (RAG) is the means to fill that gap. The recommended flow is as follows:

    1. Query rewriting: rewrite colloquial questions into retrieval-friendly keywords, splitting them into multiple sub-queries when necessary.
    2. Parallel retrieval: launch web retrieval and local knowledge base vector retrieval at the same time.
    3. Reranking and filtering: rerank by relevance, source credibility, and publication time, and remove low-quality content.
    4. Context assembly: control the injected length and keep source identifiers for later citation.
    5. Generation and citation: require the model to answer based on the given material, and to state uncertainty explicitly when the material cannot support an answer.

    Illustrative pseudocode:

    1. sub_queries = rewrite(query)
    2. docs = parallel_search(sub_queries, top_k=8)
    3. docs = rerank(docs, query)[:5]
    4. prompt = template(query, docs, require_citation=True)
    5. answer = llm(prompt, mode="deep" if need_reasoning else "fast")

    One engineering concern is the “retrieval noise” problem: injecting too much weakly related content significantly degrades answer quality, so reranking and truncation strategies are often more effective than switching to a larger model.

    6. Key Workflow 3: Files, Images, and Multimodal Input

    Document and image input is a high-frequency need on mobile, and the processing pipeline typically includes upload chunking, format detection, text extraction, layout reconstruction, structured splitting, and vectorization and retrieval.

    • Document processing: split long documents into sections first, then generate summaries and indexes; during question answering, recall fragments on demand instead of stuffing the full text in at once.
    • Images and photo-based problem solving: first run a quality check (blur, glare, occlusion), then perform OCR and formula recognition, and finally hand off to the model for step-by-step solving.
    • Privacy and compliance: prompt the user on the client before upload, make the data usage and retention period explicit, and provide a deletion entry point.

    A common misconception is treating “file upload” as equivalent to “stuffing the full text into the context.” This not only wastes compute but also dilutes key information because the context is too long. The correct approach is retrieval-centric, taking content on demand.

    7. Engineering Governance: Performance, Cost, and Stability

    On performance, the core metrics of the mobile experience are time-to-first-token and streaming stability. These can be improved through pre-connection, request coalescing, nearby access via edge nodes, and model quantization and batching optimizations.

    On cost, it is advisable to build a “cost per request” dashboard, with statistics broken down by mode, scenario, and user tier to identify high-consumption paths. Common measures include trying a small model first, caching high-frequency questions, applying semantic caching to repeated questions, and reusing summaries for long documents.

    On stability, a complete monitoring and alerting system is needed: inference failure rate, timeout rate, number of rate-limit triggers, and empty retrieval rate should all be covered by alerts. Fallback plans should also be prepared, for example switching to a backup model or returning a summary of retrieval results when the model is unavailable.

    1. metrics:
    2. - first_token_latency_p95
    3. - total_latency_p95
    4. - failure_rate
    5. - empty_retrieval_rate
    6. alerts:
    7. - name: high_timeout
    8. threshold: "> 5% in 5m"
    9. action: fallback_to_fast

    8. Security and Compliance Essentials

    Mobile applications involve personal information and user content, so compliance requirements must be built in from the design stage: minimal collection, encryption in transit, encrypted storage at rest, access auditing, retention periods, and one-click deletion. Generated content should be governed by safety policies that filter illegal and harmful information, and high-risk scenarios (medical, legal, financial) should include disclaimers and a recommendation to escalate to a human. In addition, complete invocation-chain logs (after de-identification) should be retained to support problem tracing and quality review.

    9. Evaluation Framework

    Evaluation should cover three dimensions:

    • Quality: build scenario-based evaluation sets, combining human ratings with automated metrics, focusing on factuality, completeness, and actionability.
    • Efficiency: time-to-first-token, overall duration, and task completion rate.
    • Cost: average cost per session, cache hit rate, and share of retrieval calls.

    It is advisable to establish a canary release mechanism: validate a new model or new strategy on a small traffic share first, and ramp up gradually only if metrics do not degrade.

    10. Conclusion

    The technical difficulty of mobile AI assistants has shifted from “connecting a model” to “orchestrating capabilities.” Dual-mode scheduling, retrieval augmentation, multimodal input handling, and engineering governance together determine the product’s upper bound. For developers, the pragmatic path is to first define clear capability boundaries and fallback strategies, then organize context around retrieval, and finally drive continuous optimization with observable metrics. If a team builds the foundation on generic capabilities such as the container platform, object storage, logging service, and monitoring and alerting offered by Baidu AI Cloud, it can focus its energy on orchestration and experience itself, delivering stable, controllable, and compliant intelligent applications faster.