On-Device AI Agents in Practice: Fine-Tuning Small Models for Production-Grade Performance

    Running AI agents on mobile and edge hardware means managing memory, thermals, battery, and package size before the first line of code is written. This article compares two deployment paths—reusing the system-level model versus bundling a tiny language model—and describes an agent architecture that treats skills as dynamically loaded plugins. It then explains why small models need a narrow-and-deep fine-tuning strategy centered on synthetic data, and illustrates the approach with two production cases: function-calling accuracy rising from 46% to over 90%, and a fully offline multi-model speech transcription pipeline. The final section distills the engineering methodology into reusable principles for on-device agents.

    1. The Real Constraints and Two Deployment Paths

    Running an AI agent on mobile and edge devices means facing hard resource limits before the first line of code is written. Memory footprint, heat, battery drain, and package size can each break the user experience. The first architecture decision is therefore where the model comes from.

    Path 1: Reuse the system-level model. Modern operating systems are increasingly shipping built-in on-device foundation-model capabilities, and applications can call the inference interfaces provided by the system. This path has clear advantages: model weights do not count against the app package, inference is centrally scheduled by the OS, and memory and power consumption are optimized at the system level. For most “general understanding plus simple task dispatch” scenarios, this is the default choice.

    But it comes at a cost: the capability boundary is defined by the system, the developer cannot optimize for high-frequency business-specific tasks, and there is no full cross-platform control.

    Path 2: Ship a tiny language model (TLM) with the app. When the product needs highly customized behavior—for example, a specific tool-calling protocol, a domain-specific output format, or support for platforms where the OS does not expose a model—a model in the 100M-to-several-hundred-million parameter range can be bundled directly into the application. This gives developers full control, but it also shifts the entire optimization burden to the application side. That is where fine-tuning enters the picture.

    A pragmatic strategy is to run two tracks in parallel: use the system-level model for core general capabilities, and use the in-app tiny model for differentiated, high-frequency, latency-sensitive skills, switching between them as needed.

    2. Skill Framework: Dynamic Loading Instead of Preloading Everything

    On-device hardware cannot support an approach that stuffs every capability into the model. A more elegant design is to treat the agent as a skill scheduler: the model only needs the meta-capability to discover and invoke skills, while concrete skills—such as map queries, recommendation decisions, or calendar operations—exist as plugins and are injected dynamically based on user intent.

    The implementation can be lightweight. The core idea is to use a concise system prompt to describe the contract of currently available skills, then inject the corresponding skill’s JavaScript logic into a sandboxed execution environment.

    1. // Pseudo-code: dynamic skill loading
    2. const skillRegistry = {
    3. "map_query": loadSkill("skills/map.js"),
    4. "recommend": loadSkill("skills/spinner.js")
    5. };
    6. agent.onUserIntent(intent => {
    7. const skill = model.selectSkill(intent, Object.keys(skillRegistry));
    8. const result = skillRegistry[skill].execute(model.extractArgs(intent));
    9. model.summarize(result); // The model generates a natural-language reply
    10. });

    This architecture has three benefits. First, the model context only needs to retain descriptions of the skills currently in use, which keeps token overhead under control. Second, skills can be iterated and hot-updated independently without shipping a new model version. Third, the actual execution of tool calls happens in trusted local code; the model is responsible for deciding, not executing, which makes security more manageable.

    3. Why Tiny Models Must Take the Narrow-and-Deep Fine-Tuning Route

    This is the central engineering judgment in this article. General-purpose large models often have hundreds of billions of parameters, and their broad capability comes from compressing massive, diverse data. When the parameter count drops to 100M–200M, the capacity is simply not enough to maintain dialogue, reasoning, writing, coding, and all the other abilities at the same time. The model ends up mediocre on most tasks.

    The correct approach is to abandon the goal of being general and embrace specialization: use synthetic data for targeted fine-tuning so that the model can do one or two high-frequency tasks extremely well, such as function calling, text polishing, or intent classification. “Narrow” means restricting the task surface to a single skill. “Deep” means training repeatedly on large volumes of high-quality data with thorough boundary coverage until the model reaches production-grade reliability.

    Synthetic data plays a key role here. A larger general-purpose model can batch-generate training samples by enumerating tool-call parameter combinations, colloquial phrasings, ambiguous intents, and erroneous requests, producing instruction/expected-output pairs with very broad coverage. Compared with manual labeling, the cost is nearly negligible, and edge cases can be expanded on demand. This is the dividing line between a small model that holds up in production and one that does not.

    A few practices matter during fine-tuning:

    • Data diversity beats data volume: 10,000 samples generated from one template are worse than 1,000 samples with different expressions.
    • Cover failure modes: turn real online errors into negative samples and correct them deliberately.
    • Fix the output protocol: make the model follow a strict structured output format such as JSON Schema, reducing downstream parsing failures.
    • Keep evaluating: build an automated evaluation set and run regression after every fine-tuning round, so fixing one behavior does not break another.

    4. Case 1: The Leap in Function-Calling Success Rate

    Function calling is the cornerstone of agent capability and one of the easiest places for a small model to fail. In a typical device-capability-calling experiment, prompt engineering alone allowed the tiny model to follow the calling protocol only about 46% of the time. That means more than half of user operations would fail, making the approach effectively unusable.

    After dedicated function-calling fine-tuning on a synthetic dataset, the success rate on an evaluation set of about 80 test functions rose to above 90%. The improvement did not come from a larger model; it came from data. The fine-tuning data covered argument types, optional argument omissions, enum value validation, multi-turn clarification, and other edge cases, allowing the model to internalize the calling protocol instead of relying on prompt text in context as a last-minute workaround.

    This result points to an important conclusion: in the small-parameter regime, data quality delivers far larger gains than structural changes. Prompt tuning has a ceiling; fine-tuning is the way to break through it.

    5. Case 2: Multi-Model Pipeline for Offline Transcription

    The second example shows what can be achieved by combining tiny models. Speech-to-text is a high-frequency mobile need, but users still expect high quality: filler words like “um,” “ah,” or “you know” should be removed, and proper nouns and personal dictionary terms should be recognized correctly. Traditional options either send audio to the cloud, sacrificing privacy and offline availability, or rely on a single model trying to handle everything, often with insufficient quality.

    The on-device solution is a model pipeline: first, a speech recognition engine produces a raw transcript; then, a tiny language model dedicated to text polishing performs post-processing. Both models are only a few hundred million parameters, but each has been fine-tuned around one responsibility. The first focuses on recognition accuracy, while the second focuses on colloquial normalization and personal vocabulary adaptation. The entire pipeline runs fully offline, audio never leaves the device, and both privacy and latency are improved.

    The lesson here is not to try to solve every problem with one model. Instead, decompose a complex pipeline into multiple single-responsibility tiny models, fine-tune each one to be the best at its own stage, and then chain them together. The serialized overall quality can approach or even exceed a single big model forced to do everything, while resource overhead is an order of magnitude lower.

    6. Summary: An Engineering Methodology for On-Device Agents

    These points form a reusable methodology:

    1. Deployment selection: prefer system-level models for general capabilities, and add an in-app tiny model for differentiated capabilities.
    2. Architecture design: let the agent act as a scheduler, load skills as dynamic plugins, and control context growth.
    3. Capability building: give up the illusion of generality in small models, and use synthetic data for narrow-and-deep fine-tuning.
    4. Quality assurance: build automated evaluation sets for every critical task and iterate with data.
    5. Composition: chain multiple specialized models instead of forcing one model to handle everything.

    In the on-device AI era, model size is no longer the only deciding factor. The granularity of data engineering and task design is what makes the difference. In resource-constrained scenarios, a small model fine-tuned to its limit can outperform a general large model that has not been optimized for the task.