# On-Device Agent in Practice: Fine-Tuning Small Models for Better Function Calling
This article explains how to build agents that run on resource-constrained devices such as phones, wearables, and in-car systems. It shows why edge agents should be specialized rather than simply larger, and walks through a "narrow and deep" fine-tuning approach for tiny language models (TLMs). In a representative function-calling fine-tuning case, the approach raised success rate from roughly 46% to about 90%. It also covers how to chain multiple small models in a pipeline to enable offline transcription, plus key engineering practices such as prioritizing data quality, re-evaluating after quantization, and testing complete end-to-end flows. The article is intended for developers who want to bring agent capabilities to terminal devices.
Why On-Device Agents Must Travel Light
When an agent moves from the cloud to the edge (phones, wearables, in-car systems, offline terminals, and similar devices), the first constraint we face is resources. Edge devices typically have anywhere from a few hundred megabytes to a few gigabytes of usable memory, limited CPU/GPU/NPU compute, and heavy reliance on battery power. A large model that runs well in the cloud often runs into three problems when moved directly onto a device:
- Unacceptable latency: inference can take several seconds per request, which wrecks the interaction experience.
- Doesn’t fit in memory: too many parameters, and even after quantization and compression the model exceeds what the device can handle.
- Depends on the network: many offline scenarios (underground environments, airplane mode, privacy-sensitive situations) don’t allow network access at all.
The industry has gradually reached a consensus: the core of an on-device agent isn’t “bigger” but “more specialized.” Tiny language models (TLMs) typically have parameter counts in the low billions or below. Combined with INT8/INT4 quantization, they can run stably on consumer devices. To make a tiny model genuinely capable of doing agent work, however, you need a special training and fine-tuning approach.
The Core Method: Fine-Tune Tiny Models “Narrow and Deep”
This is the most important idea in this article, and the one most easily overlooked.
“Narrow and deep” means: don’t try to turn a small model into a general-purpose expert; instead, make it excel at an extremely narrow set of tasks.
Why “Broad and Shallow” Fails
Many teams’ first instinct is to take a general-purpose small model, feed it massive amounts of multi-domain data, and expect it to do everything. The usual result is that it knows a little about task A and a little about task B, but isn’t solid on any of them. A small model’s capacity is limited to begin with. When the task space is spread too wide, it falls into a “jack of all trades, master of none” situation: its parameters get diluted, and the key capabilities it actually needs never get learned.
What “Narrow” Means
- Narrow tasks: focus on just 1–3 high-frequency, high-value skills. For example, only function calling / tool selection, not open-domain chitchat.
- Narrow domains: lock down clear business boundaries, such as smart home control, schedule management, or device queries.
- Narrow output format: enforce structured output (e.g., JSON) so the model only needs to learn “which function to pick and what arguments to fill.”
What “Deep” Means
- Deep data: use high-quality, human-reviewed synthetic and real data, and repeatedly refine boundary cases within the same category of samples.
- Deep alignment: through multiple rounds of SFT (supervised fine-tuning), establish a stable mapping for each function’s semantics, trigger conditions, and argument constraints.
- Deep robustness: extensively cover real user input such as colloquial phrasing, typos, vague expressions, and mixed multiple intents.
In short: trade limited capacity for reliability and stability on a single task, rather than spending that limited capacity building a fragile generalist.
Results: Function-Calling Success Rate Rose from About 46% to About 90%
Much of an agent’s capability depends on the accuracy of function calling: whether the model can call the right tool, at the right time, with the right arguments. This is make-or-break for getting on-device agents into real use.
In a representative function-calling fine-tuning case, an unoptimized tiny model had a function-calling success rate of roughly 46%. Nearly half of its requests resulted in the wrong function being chosen, wrong arguments being filled in, or silence when it should have called a function. After “narrow and deep” fine-tuning, the same model achieved a success rate of about 90% on the same kind of test set. That leap makes a fundamental difference to the experience: the former is nearly unusable, while the latter meets a deployable standard.
Note: the exact numbers vary with task complexity, data quality, and evaluation criteria. They are used here to illustrate the relative improvement that “narrow and deep” fine-tuning can offer over a general-purpose model, not as a promise of absolute results for any specific product.
Key Levers for Improving Success Rate
- Concise function descriptions: write clear, unambiguous natural-language descriptions and argument documentation for each callable function. This is the foundation for how the model distinguishes between functions.
- Thorough negative samples: actively construct difficult examples such as cases where the model shouldn’t call anything, or where it should call A rather than B, to correct the model’s wrong preferences.
- Strong constraints on argument filling: use structured output and validation to turn “format correctness” from a soft expectation into a hard constraint.
Example Fine-Tuning Data Structure
The sample code below shows how function-calling fine-tuning data is typically organized. The format is a generic example, not tied to any specific platform’s API:
{"instruction": "Given the user's instruction, determine which function to call and generate valid arguments.","input": "Set the living room AC to 26 degrees","output": {"function": "set_temperature","arguments": {"device": "living_room_ac","temperature": 26}}}
You also need negative samples, such as:
{"instruction": "Given the user's instruction, determine which function to call and generate valid arguments.","input": "I'm feeling a bit down today","output": {"function": "none","arguments": {}}}
Positive samples teach the model when to call and how to fill in arguments; negative samples teach it when to hold back. Both are essential.
Use Case: Chaining Multiple Models for Offline Transcription
Another killer application of tiny models is offline transcription: converting speech to text and processing it afterward on a device that isn’t connected to the internet at all. This is exactly where the pain points of on-device intelligence concentrate, and where a multi-model pipeline delivers its value.
1. Pain Points
Offline transcription faces three competing tensions:
- Accuracy vs. compute: high-accuracy recognition models tend to be large and can’t run on the device.
- General vs. domain-specific: general-purpose transcription does a poor job on technical terms, particular accents, and proper nouns.
- Recognition vs. understanding: many use cases need more than text, such as structured summaries or instruction extraction.
2. The Multi-Model Pipeline Approach
A single model can’t meet all of these needs at once, so a more practical approach is to chain multiple specialized small models in a pipeline, each handling one stage:
Audio input│▼[Speech Recognition Model] ── Audio → text (focuses on accuracy and low latency)│▼[Text Cleaning/Segmentation Model] ── Removes filler words, corrects errors, splits into segments│▼[Intent/Information Extraction Model] ── Structured output (e.g., to-dos, schedules, commands)│▼Final result
3. Advantages of a Pipeline
- Single responsibility: each model is a “narrow and deep” product and does its own stage best.
- Independently replaceable: if you’re unsatisfied with one stage, you only need to retrain that stage’s model without affecting the whole system.
- Controllable total resource usage: chaining several small models often uses less memory and is more stable than forcing a single medium-sized large model to do everything.
- Fault tolerance and graceful degradation: when one stage fails, the system can fall back to an intermediate result (such as outputting only the raw text), keeping the system usable.
At its core, this approach breaks down the hard problem of “one model solves everything” into the engineering problem of “multiple specialized models working together.”
Key Engineering Practices
To put the methods above into practice, pay close attention to the following:
- Data quality matters more than data quantity: small models are extremely sensitive to noise, and a few thousand precisely labeled samples often outperform hundreds of thousands of dirty ones.
- Validate quantization carefully: INT8/INT4 quantization can greatly reduce resource usage but may lose accuracy, so you must re-run the evaluation set after quantizing.
- Build a separate evaluation set: strictly isolate training and evaluation data. The evaluation set should cover edge cases from the real distribution, so you avoid “overfitting-style” metrics that look great but mean little.
- Evaluate end to end, not individual stages: for function calling, evaluate the complete chain of “intent → selection → argument filling → execution,” not just one link.
- Continuously collect real feedback: after launch, collect logs of real interactions and keep feeding the data back into iteration. This is fundamental to keeping the model reliable.
Summary
An on-device agent’s competitive edge doesn’t come from how large its model is, but from whether it is focused enough and reliable enough. The “narrow and deep” fine-tuning approach offers a proven path: by narrowing the task scope and deepening the data and alignment work, tiny models can push success rates on key capabilities like function calling from nearly unusable to deployable. Meanwhile, the multi-model pipeline architecture lets complex scenarios like offline transcription run gracefully under low-resource constraints.
For developers who want to genuinely bring intelligence to terminal devices, the smarter choice is not to chase bigger models, but to carefully polish smaller, more specialized, more stable ones. It’s both a practical choice under engineering constraints and the inevitable direction for on-device intelligence.
