Narrow-and-Deep Fine-Tuning for On-Device Agents: Building Reliable Small Models
This article explains how to fine-tune small language models for on-device agents using a "narrow-and-deep" strategy. It covers why on-device scenarios demand a specialized approach, how to design a skill framework around structured tool declarations and routing, and why function calling is the core capability to optimize. A representative case study shows function call success rate improving from roughly 46% to about 90% through data and methodology changes rather than larger models. The article also details practical guidance for building fine-tuning data, setting up an evaluation and iteration loop, and handling engineering concerns such as inference optimization, timeouts and retries, observability, and version management. Readers will gain a concrete playbook for turning limited-capacity edge models into dependable task performers within well-defined boundaries.
1. Why On-Device Agents Need a Dedicated Fine-Tuning Strategy
With the spread of smart terminals, wearables, and edge gateways, a growing number of agents (Agents) need to run locally and offline. These scenarios come with three hard constraints:
- Limited compute: Devices lack cloud-grade GPUs, so inference latency and memory usage must be tightly controlled;
- Small model size: To keep cost and power consumption in check, on-device deployments generally use smaller models with fewer parameters (often called tiny language models, or TLMs);
- Clear task boundaries: On-device agents typically handle a limited but well-defined set of responsibilities, such as device control, local information retrieval, form filling, and sensor data parsing.
Together, these constraints mean on-device small models cannot simply copy the “general-purpose capability” path of large models. In one sentence: tiny models must follow a “narrow-and-deep” fine-tuning route—trading breadth for high reliability and high success rates within a narrow task domain.
2. What “Narrow and Deep” Really Means
“Narrow” refers to converging the scope of capabilities; “deep” means pushing the chosen capabilities to their limit. Together they form the first principle of on-device fine-tuning.
1. Narrow: Define Clear Capability Boundaries
Rather than training a small model that can “chat about anything,” it is better to make it truly proficient at one or two task types. The more focused the capability scope, the purer the fine-tuning data distribution, and the more fully a small model’s limited capacity can be utilized. In practice, it helps to first draft a “capability list” that enumerates every skill the agent needs to master, then assess each item’s priority.
2. Deep: Bring Core Skills Close to Perfection
For high-priority skills—especially function calling / tool calling, the lifeline of an agent—invest enough labeled data and training rounds, repeatedly refining until you reach a stable, high success rate, rather than aiming for mediocre, all-around coverage.
3. Why “Broad and Shallow” Is Not Recommended
A small model has limited capacity. If it tries to cover too many tasks, the capabilities end up “competing” for parameters, producing the classic catastrophic forgetting effect: old skills degrade while new ones are learned. The narrow-and-deep route, by converging the distribution, lets the model perform within its target domain well beyond what its parameter count would suggest.
3. Designing the Skill Framework
A practical on-device agent skill framework usually contains the following layers:
- Skill definition layer: Declares each tool/function’s name, description, input schema, and return value format in a structured way;
- Intent and routing layer: Lets the model decide which skill to call based on user input and which arguments to extract;
- Execution and result-fill layer: Runs the function locally on the device, then feeds the result back to the model to generate a natural-language reply;
- Fault tolerance and retry layer: Provides fallbacks for missing arguments, failed calls, malformed formats, and similar cases.
Skill declarations typically follow a general structure like the one below (illustrative only; actual fields depend on your business definition):
{"name": "set_device_temperature","description": "Set the target temperature for a specified device","parameters": {"type": "object","properties": {"device_id": { "type": "string", "description": "Unique identifier of the device" },"temperature": { "type": "number", "description": "Target temperature in degrees Celsius" }},"required": ["device_id", "temperature"]}}
The core task the model must accomplish is mapping natural language to a “skill name + valid arguments” pair. This is also the key to function call success rate.
4. Function Calling: The Core Agent Capability
In multi-turn tool-use scenarios, an agent’s reliability depends almost entirely on the accuracy of “choosing the right tool and filling in the right arguments.” A typical call loop looks like this:
User input → Model parses intent → Structured call generated → Local function executed → Result fed back → Model generates reply
An error in any step lowers the overall success rate. Common problems include:
- Choosing the wrong skill (intent recognition bias);
- Missing arguments or wrong types;
- Generating invalid JSON that the parser cannot load;
- Ending early or repeating calls when consecutive calls are needed.
5. The Performance Leap: From ~46% to ~90% Function Call Success Rate
In a representative on-device fine-tuning case, the same small model improved its function call success rate from about 46% to about 90% before and after adopting the “narrow-and-deep” route. This gain did not come from enlarging the model, but from reworking the methodology and data. The key actions can be summarized as:
- Converging the task domain: Focusing training and evaluation on a few high-frequency skills instead of spreading thin across everything;
- High-quality structured data: Building large numbers of “input–correct call” pairs for each skill, covering diverse phrasings and boundary expressions;
- Strengthening format constraints: Explicitly modeling valid JSON structure in training samples to reduce parsing failures;
- Hard-case-driven iteration: Feeding failure samples (especially argument-extraction errors) back into training to form a closed loop;
- Dedicated evaluation: Repeatedly regressing against call accuracy as the core metric, avoiding subjective “it feels better” judgments.
Note that specific numbers vary with model size, task difficulty, and data quality; this case only illustrates the substantial potential of narrow-and-deep fine-tuning for improving call reliability.
6. Building Fine-Tuning Data: Practical Guidelines
Data quality almost determines success or failure. Recommended principles:
- Diversity: Cover different phrasings, colloquial expressions, and subject-omitting variations for the same skill;
- Boundary cases and negatives: Include samples such as “no matching skill,” “missing arguments,” and “needs clarification” to teach the model when not to call;
- Strong consistency: Map the same intent to a consistent call format as much as possible to reduce model ambiguity;
- Difficulty tiers: Grade samples as simple/medium/hard so training objectives stay controllable.
An illustrative training sample format (generic format, not tied to any specific framework):
{"input": "Set the living room AC to 26 degrees","target": {"tool": "set_device_temperature","arguments": { "device_id": "living_room_ac", "temperature": 26 }}}
7. Evaluation and the Iteration Loop
Fine-tuning without quantitative evaluation is blind. Recommended: build a repeatable pipeline:
- Fixed evaluation set: Strictly isolated from the training set, covering all skills and hard cases;
- Multi-dimensional metrics: Track call accuracy, argument accuracy, format validity rate, and end-to-end task completion rate separately;
- Automated regression: Automatically run the full evaluation after each change to prevent capability regression;
- Online feedback: Feed real failure samples back as new training data for continuous iteration.
8. Engineering Deployment and Optimization
When deploying the fine-tuned model to the device, also pay attention to:
- Inference optimization: Reduce latency and memory usage through techniques such as quantization and operator fusion;
- Timeouts and retries: Set reasonable timeouts for local function calls and degrade gracefully on failure;
- Observability: Use logging and monitoring/alerting to trace the call chain and quickly locate the cause of a drop in success rate;
- Version management: Apply canary releases and rollbacks for skill schemas and model versions to keep production stable.
If multi-device coordination or data synchronization is needed, general cloud capabilities such as object storage, message queues, and container platforms can be used to handle model training, evaluation, and distribution on the cloud side, while the device is responsible only for inference and execution.
9. Summary and Best Practices
The value of on-device small models lies not in “doing everything,” but in “being extremely reliable within clear boundaries.” The core conclusions can be distilled as:
- Converge the capability domain: Narrow-and-deep is the first principle of on-device fine-tuning;
- Data is the ceiling: High-quality, structured, diverse data with negative examples determines success;
- Call rate is king: Use function call success rate as the core north-star metric;
- Closed-loop iteration: Feeding failure samples back plus automated evaluation continuously improves capability;
- Engineering safeguards: Inference optimization, timeouts and retries, observability, and version governance are all indispensable.
By following this path, even a parameter-limited on-device small model can achieve a leap from “barely usable” to “stably reliable” on key skills, delivering a real improvement in the on-device intelligent experience.
