Building On-Device AI Agents: Unlocking Small Language Models with Narrow-Domain Fine-Tuning
On-device AI agents offer privacy, offline capability, and low latency, but small language models often struggle with instruction following, reasoning, and function calling. This article presents a practical methodology combining skill-based task decomposition at the framework level with narrow-domain, parameter-efficient fine-tuning at the model level. It covers skill framework design, data engineering strategies, training tactics, measurable gains in function call success rates, and a real-world multi-model pipeline for offline voice transcription, showing how to turn a "demo-grade" agent into a production-ready product.
Building On-Device AI Agents: Unlocking Small Language Models with Narrow-Domain Fine-Tuning
The Rise of On-Device Agents — and Their Real-World Limitations
As mobile hardware keeps getting more powerful, an increasing number of inference workloads are moving from the cloud down to the device. On-device agents offer several advantages that cloud-based solutions cannot match: data never leaves the device, so privacy is protected by design; no network connection is required, so they work offline; inference latency is low, delivering a smoother interactive experience; and there are no recurring cloud inference costs.
There is, however, a significant gap between the ideal and the reality. The strength of large general-purpose models depends on tens of billions of parameters or more, while small language models that can realistically be deployed on-device (typically ranging from hundreds of millions to a few billion parameters) lag far behind cloud models in critical capabilities such as instruction following, logical reasoning, and function calling. If you simply port an agent framework designed for large cloud models onto a small on-device model, the results are usually disastrous: the model fails to parse user intent correctly, function call formats break constantly, and multi-step tasks drift off track halfway through.
This leads to the core question of on-device agent development: how do you build a reliable, usable agent with a limited model? The answer is a combination of two approaches — task decomposition at the framework level and deep, narrow-domain fine-tuning at the model level.
Skill Framework Design: Breaking Complex Tasks into Atomic Capabilities
Engineering practice shows that asking a small model to handle the entire pipeline — understanding intent, planning steps, calling tools, and integrating results — yields very low success rates. The right approach is to build a skill framework that decomposes complex tasks into atomic skills, each with a single responsibility and a well-defined, narrow input/output contract.
A typical skill framework includes the following components:
- Intent routing: Takes user input and decides which skill category to activate. This layer performs classification only, not generation, so it places the lowest demands on the model.
- Task planning: Breaks the user’s goal into ordered execution steps and outputs a structured plan.
- Function calling: Generates well-formed function call instructions — function name and arguments — for the current step.
- Result integration: Converts tool outputs into natural language responses.
The input and output of each skill unit should be strictly constrained. For example, the function calling stage can enforce a unified output format:
{"function": "get_weather","arguments": {"city": "Beijing","date": "2025-06-01"}}
The benefit of this “narrow interface” design is that the task space for each skill is drastically compressed. The model only needs to make correct decisions within a small distribution, which significantly lowers the learning difficulty — and creates the conditions for targeted fine-tuning later.
Narrow but Deep: The Core Methodology for Fine-Tuning Small Models
Why Generic Fine-Tuning Falls Short
Fine-tuning a small model for general-purpose capability rarely works. There are three reasons:
- Capacity bottleneck: A small model has limited parameter capacity. Trying to teach it broad, multi-domain competence forces different domains to compete for the same capacity, and every one of them ends up mediocre.
- Data dilution: In generic instruction datasets, samples relevant to your target scenario make up a tiny fraction, so the fine-tuning signal gets diluted by a flood of unrelated data.
- Catastrophic forgetting: Full-parameter generic fine-tuning tends to degrade the model’s existing foundational capabilities, doing more harm than good.
The alternative is the “narrow but deep” approach: pick an extremely narrow task domain and push that single capability to its limit with high-quality, high-density domain data. This aligns naturally with the skill framework — since each skill’s input/output contract is already narrow, the fine-tuning objective narrows with it.
Data Construction: Quality Over Quantity
Data engineering is the key to narrow-domain fine-tuning. Recommended practices include:
- Anchor on the function calling schema: Enumerate all plausible tool combinations and argument values within the target scenario, and synthesize training samples that cover edge cases.
- Add negative and correction samples: Teach the model to reject invalid requests and repair malformed outputs.
- Control diversity instead of blindly scaling up: A few thousand to tens of thousands of high-quality samples are usually enough for a small model to converge on a narrow-domain task.
- Split training/validation sets strictly by scenario: Avoid inflated metrics caused by simple template leakage between sets.
Training Strategy
On the training side, parameter-efficient fine-tuning methods (such as low-rank adaptation) are the preferred choice for on-device scenarios: they update only a small number of parameters, keep training costs low, and make it easy to maintain separate adapter weights for different skills and load them on demand. During training, focus on two metrics for structured outputs — format validity rate and field accuracy — rather than generic text similarity scores.
Results: A Leap in Function Call Success Rate
The payoff from narrow-domain fine-tuning is substantial. In a typical on-device function calling benchmark, an untuned small model hovers around a 50% success rate — meaning one out of every two user requests fails, making the product effectively unusable.
After the full pipeline of “skill decomposition + narrow-domain data + parameter-efficient fine-tuning,” a model of the same size can reach close to 90% success. This order-of-magnitude improvement is not just a metric bump — it changes the product itself, from “works in a demo” to “deliverable in a real-world scenario.”
It’s worth noting that the remaining errors tend to concentrate in a few long-tail scenarios (such as ambiguous multi-argument calls or nested invocations). These can be further reduced by expanding targeted training data and adding rule-based fallback validation. A common fallback strategy in practice: run schema validation on the model’s output first, and if it’s invalid, trigger a retry or degrade to template-based interaction.
Case Study: A Multi-Model Pipeline for Offline Voice Transcription
To show how the framework works in practice, consider an offline voice transcription and organization app. It must complete the full chain of “record → transcribe → summarize → structured export” without any network connection, and it coordinates multiple models:
- Speech recognition model: Converts the audio stream into text in real time. It is a dedicated acoustic/sequence model and does not participate in agent decisions.
- Small language model (routing skill): Receives the transcribed text and the user’s instruction, and decides whether the user wants to “generate a summary,” “extract action items,” or “export as a structured document.”
- Small language model (generation skill): Executes the specific text generation task based on the routing result, producing output in the predefined format.
- Rule-based post-processing layer: Validates the structured output and writes it to local storage.
This case highlights an important principle of on-device multi-model architecture: let specialized models do specialized work, and let the fine-tuned small language model handle only narrow tasks it excels at — decision-making and formatting. With clear responsibility boundaries between components, no single model’s weakness propagates into a system-level failure.
On-device deployment also requires engineering optimizations such as model quantization (e.g., compressing weights to low-precision integer formats), inference cache reuse, and on-demand loading of skill adapter weights, to maintain acceptable response times under memory and power constraints. In hybrid architectures that combine on-device and cloud processing, general cloud services such as object storage and message queues can be used to asynchronously sync and back up the results of offline tasks.
Summary and Outlook
The essential challenge of on-device agents is building a reliable product on top of limited model capability. The methodology in this article boils down to three points:
- Subtract at the framework level: Use a skill framework to decompose complex tasks into atomic capabilities, narrowing the decision space at each stage.
- Add at the fine-tuning level: Build high-density data around narrow-domain tasks, and use parameter-efficient fine-tuning to polish each capability to its limit — achieving the leap from “barely usable” to nearly 90% success rate.
- Combine at the architecture level: Chain multiple models together with rule-based fallbacks so that overall system reliability exceeds the ceiling of any single model.
As the baseline capabilities of small models continue to improve and on-device compute is further unlocked, the “narrow but deep” fine-tuning philosophy will remain relevant for the long run — because product reliability requirements will always run ahead of general model capability.
