On-Device Agent Fine-Tuning: Narrow-and-Deep Tiny Models for Function Calling
On-device agents must balance package size, memory, power, latency, privacy, and cross-platform consistency. This article explains a dual-track deployment strategy using system-level AI and in-app Tiny Language Models (TLMs), a skill registry with on-demand loading, synthetic-data fine-tuning for 100M–200M parameter models, and evaluation practices for reliable function calling. It also covers a function-calling experiment, multi-model chaining for offline transcription, and an engineering checklist for production deployment.
As on-device compute improves, agents are moving from cloud demos to mobile and offline devices. But shipping an on-device agent is not simply a matter of shrinking a general-purpose large model. App size, peak memory, power consumption, first-token latency, privacy compliance, and cross-platform consistency all determine whether a solution can actually launch. Practitioners sharing on-device Agent skill frameworks have outlined a practical path: prioritize system-provided on-device models, distribute Tiny Language Models (TLMs) with the app only when necessary, control model responsibilities through dynamic skill loading, fine-tune 100M–200M parameter tiny models with “narrow-and-deep” synthetic data, and use specialized small models for closed tool sets, where function-calling performance can significantly exceed prompt-only approaches. The following sections cover architecture, fine-tuning, evaluation, and engineering practices.
1. Core Constraints and a Dual-Track Deployment Strategy
The first principle for on-device agents is: do not put every capability into one model. Mobile apps typically face three constraints. First, package size and memory: model weights, vocabularies, and runtimes all consume space. Second, latency and power: long-context inference and repeated tool calls increase battery drain. Third, privacy and offline availability: sensitive data should not leave the device by default. Deployment should therefore follow a dual-track strategy.
System-level AI refers to on-device model capabilities provided by the operating system or device. Its advantage is that apps do not need to carry model weights, which saves package size and allows shared system scheduling, memory management, and updates. For general intent recognition, simple text rewriting, and system-level tool calls, system-level capabilities should be evaluated first. In-app AI refers to tiny models distributed with the application. It fits highly customized tasks, consistent cross-platform delivery, gaps in system capabilities, or scenarios that require fixed version behavior. The cost is larger packages, version maintenance, and competition for on-device resources, so its responsibilities must be strictly limited.
A selection matrix can help:
- General task, sufficient model capability, moderate privacy requirements: prefer system-level AI.
- High-frequency task, fixed format, cross-platform consistency required: use an in-app TLM.
- Sensitive data, fully offline requirement: use an in-app TLM or a chain of multiple models.
- Rapid experimentation, closed tool set: validate with prompts first, then decide whether to fine-tune.
- Complex open-ended reasoning: do not force a 100M–200M parameter model to handle it; split the task or fall back to the cloud.
The key to dual-track deployment is not choosing one track over the other, but layering general capabilities and specialized capabilities. System-level models handle general entry points and lightweight tasks, while in-app tiny models handle high-frequency, narrow-domain, evaluable production tasks.
2. Skill Framework: From Full Preloading to On-Demand Loading
Another common mistake is to have the model preload every function. A better approach is a skill registry: the model handles intent recognition, skill routing, and parameter extraction, while specific capabilities are loaded on demand as skill packages. When a user triggers a map, restaurant recommendation, or calendar creation request, the framework loads the corresponding skill script and tool description. This reduces startup cost and lets skills be versioned, rolled out gradually, and rolled back independently.
An illustrative skill list looks like this:
{"skill": "route_plan","trigger": ["navigate", "route", "directions"],"schema": {"from": "string", "to": "string", "mode": "string?"},"package": "skills/route_plan.skill","permission": ["location_read"]}
Routing pseudocode can be abstracted as:
function handle(userInput):intent = tinyModel.classify(userInput)skill = registry.match(intent)if skill is null: return tinyModel.askClarify(userInput)if not skill.loaded: load(skill.package)args = tinyModel.extract(userInput, skill.schema)if not validate(args, skill.schema): return tinyModel.askClarify(userInput)result = skill.execute(args)return tinyModel.render(result, skill.outputStyle)
Key engineering points include: skill schemas must be strict; when parameters are missing, the model should ask for clarification rather than guess; skill packages need sandboxing and permission declarations; loading must support caching and unloading; script injection should use lightweight, controlled general scripting capabilities rather than arbitrary code execution; and skill versions must be evaluated together with model versions to prevent routing drift after model upgrades. The value of dynamic loading is that it turns the model from an all-purpose question-answering system into a skill scheduler, reducing context length and inference burden.
3. Why Tiny Models Need Narrow-and-Deep Fine-Tuning
When model parameters drop to the 100M–200M level, general capabilities decline noticeably: open-ended QA, long-document reasoning, and multi-tool planning often become unstable. At this point, the model should not be expected to handle ten task types at once. Instead, synthetic data should be used for targeted fine-tuning so the model focuses on a single high-frequency task, such as function calling, parameter extraction, text polishing, format conversion, or intent classification. “Narrow and deep” means a narrow task boundary, stable output format, sufficient evaluation sets, and many boundary samples—not simply more data.
Fine-tuning data should cover: positive tool-call samples, negative samples where no call should be made, confusing multi-tool samples, missing and invalid parameters, multi-turn clarification, synonymous expressions, colloquial noise, long-tail entities, and refusal/fallback cases. A synthetic-data workflow can be designed as follows: first, use a high-performance large model to generate candidate dialogues in batches based on tool schemas; then use rules to validate parameter legality and format; then perform manual spot checks and deduplication; finally split the data into training, validation, and test sets by task, scenario, and difficulty. Test-set leakage into training must be prevented, otherwise success rates will be inflated.
Evaluation metrics should not be limited to accuracy. They should include at least tool-selection accuracy, parameter-extraction F1, execution success rate, end-to-end success rate, clarification rate, false-call rate, P95 latency, peak memory, and offline stability. For on-device models, a false call is more dangerous than no call, so refusal and clarification metrics should be included. After fine-tuning, general capabilities must also be regression-tested to prevent the model from merely memorizing templates.
4. Function-Calling Experiment: From Prompts to Specialized Fine-Tuning
In a system intent invocation experiment, the success rate of a prompt-only approach was about 46%. The reason is usually not that the model cannot understand the task at all, but that on-device small models drift under format constraints, missing parameters, confusing tool names, and context interference. After using a high-performance large model to synthesize a function-calling dataset in batches and fine-tuning a tiny model specialized for function calling, the success rate rose above 90% on about 80% of the test functions. This result shows that, under conditions of a closed tool set, clear task boundaries, and sufficient evaluation data, a narrow-and-deep specialized small model can reach production-level usability.
However, this data depends on the experimental setup and data quality and should not be generalized to “all tasks outperform general large models.” The correct interpretation is: general large models are strong in open-ended generalization, while tiny specialized models are strong in determinism, offline operation, and cost for fixed tasks. Engineering teams should first define the tool set and schemas, then measure the failure distribution with a prompt baseline, synthesize data for failing samples, and finally validate through small-step fine-tuning and gradual rollout. If failures are concentrated in tool selection, add negative samples for confusing tools; if they are concentrated in parameter extraction, add entity and format samples; if they are concentrated in multi-turn clarification, add dialogues with missing parameters.
5. Multi-Model Chaining: Offline Transcription in Practice
An on-device agent does not have to be a single model that handles everything. Offline transcription is a typical multi-model chaining scenario: an ASR engine first outputs raw text, and a text-polishing engine then removes filler words, adds punctuation, applies personal dictionary replacements, and organizes formatting. Both models can be tiny models with hundreds of millions of parameters, enabling high-quality transcription in a fully offline state. The value lies in decoupling recognition from editing: ASR focuses on acoustics-to-text, while the polishing model focuses on text normalization. Each can be fine-tuned narrowly and deeply, and evaluation becomes clearer.
From an engineering perspective, three issues must be handled. First, latency stacking: a segmented pipeline can process completed segments with recognition and polishing in parallel. Second, error propagation: the polishing model must not over-rewrite the original meaning and should use confidence thresholds and conservative strategies. Third, memory contention: time-sliced loading or quantization and compression can help ensure usability on low-end devices. Personal dictionaries should be injected through controlled vocabularies to prevent the model from freely inventing terms.
6. Production Checklist and Risk Control
For on-device agent deployment, proceed with the following checklist: first break down tasks and define tool schemas, clarifying which tasks must be offline; establish a prompt baseline and measure the failure distribution; design synthetic-data and manual spot-check workflows; choose system-level AI or an in-app TLM and retain a fallback strategy; perform narrow-and-deep fine-tuning and quantization evaluation for tiny models; build on-device monitoring for routing failures, clarification rates, latency, and crashes; implement gradual rollout and version rollback; and enforce privacy redaction and least-privilege permissions. If batch synthesis, evaluation pipelines, and release management are needed, general cloud capabilities such as object storage, container platforms, logging, and monitoring—for example, Baidu AI Cloud—can be used, but the core remains the engineering loop between on-device models and the skill framework.
In summary, the path to better on-device agents is not to blindly pursue larger parameters. It is to combine system-level and in-app dual-track deployment, load skills on demand, fine-tune narrowly and deeply with synthetic data, evaluate rigorously, and chain multiple models. Narrow the model’s responsibilities and thicken the engineering boundaries to deliver an agent experience on mobile devices that can launch, be maintained, and be iterated.
