A Practical Guide to Fine-Tuning Small Models for On-Device AI Agents

    Deploying AI agents on resource-constrained edge devices requires a shift from relying on large, general-purpose models to fine-tuning small models for specific skills. This article explores the design of an on-device agent skill framework, explains why a narrow and deep fine-tuning approach is essential, and details practical methods to improve function call success rates from 46% to over 90%. It also covers a multi-model chaining architecture and engineering practices like quantization, modularity, and fallback strategies to help developers build reliable on-device AI applications.

    As the capabilities of large language models continue to evolve, an increasing number of applications are attempting to bring agent capabilities from the cloud down to edge devices. However, on-device environments face inherent constraints in computing power, memory, and power consumption, making the direct deployment of models with tens of billions of parameters impractical. A growing consensus is that the correct approach to on-device agents is not to use small models like large models, but rather to make micro-models achieve the ultimate performance in specific skills through a narrow and deep fine-tuning path. This article will systematically outline the design philosophy of the on-device agent skill framework, fine-tuning methodology, performance optimization paths, and engineering practices for multi-model chaining.

    1. On-Device Agent Skill Framework Design

    The core responsibilities of an on-device agent can be broken down into three basic capabilities: intent understanding, tool calling (function calling), and result organization. Unlike cloud-based agents that pursue general intelligence, an on-device agent is more like a highly specialized “skill executor”—it does not need to write poetry or master encyclopedia Q&A, but it must achieve near 100% reliability within a limited set of functions.

    A typical on-device agent skill framework contains the following layers:

    1. Perception Layer: Receives user input, which could be text, speech-to-text results, or system events.
    2. Decision Layer: Managed by a small language model responsible for mapping user intent to structured function call instructions.
    3. Execution Layer: Calls device-local capabilities such as file read/write, app control, or sensor data retrieval.
    4. Feedback Layer: Returns the execution results to the user in natural language to form an interaction loop.

    The key design principle of this architecture is: compress “intelligence” into the decision layer and delegate “complexity” to the deterministic execution layer. The smaller and more singular the model in the decision layer, the more controllable the entire system becomes.

    2. Why Micro-Models Must Take a Narrow and Deep Fine-Tuning Path

    For small models with parameters ranging from 2 billion to 9 billion, attempting to equip them with general agent capabilities through prompt engineering is often counterproductive. There are three main reasons:

    First, the context window is a scarce resource. Constrained by memory, on-device models typically have a small context window. Relying on lengthy system prompts to describe tool specifications and output formats severely crowds out effective context, and prompt-following capabilities are inherently unstable in small models.

    Second, there is a trade-off between general and specialized capabilities. The parameter count of a small model dictates its limited “knowledge capacity.” Rather than having it perform mediocrely across a broad range of tasks, it is better to focus its entire capacity on a narrow skill domain through fine-tuning—for example, solely responsible for converting natural language instructions into a few dozen predefined function calls.

    Third, fine-tuning brings deterministic format output. The biggest fear in an agent system is unstable model output formats, which lead to downstream parsing failures. By constructing a large number of “instruction-structured output” sample pairs in the training data, the fine-tuned model can develop a muscle-memory-like format habit, pushing the parsing error rate to extremely low levels.

    Therefore, the core strategy for on-device agent fine-tuning can be summarized as: narrow task boundaries, deepen data depth, and strengthen format constraints.

    3. From 46% to 90%: The Leap in Function Call Success Rate

    In practice, when an un-fine-tuned small open-source model directly takes on function calling tasks, the success rate is often only around 40%—meaning one out of every two interactions fails, making it completely unusable for real-world applications. Through a systematic fine-tuning process, the success rate can be elevated to over 90%. This leap typically comes from improvements in the following areas:

    1. High-Quality Training Data Construction

    Data is the primary factor in the success of fine-tuning. For function calling tasks, a dataset covering the following dimensions must be constructed:

    • Positive samples: User instructions correspond exactly to the correct function name and parameter combinations.
    • Ambiguous samples: Multiple natural language expressions for the same intent, training the model’s robustness.
    • Negative samples: Requests outside the skill scope, training the model to refuse or ask for clarification.
    • Multi-step samples: Compound instructions requiring the sequential calling of multiple functions, training planning capabilities.

    Data can be generated in bulk through rule templates or synthesized using a more powerful teacher model followed by manual cleaning. Special attention must be paid to the accuracy of parameter types—errors in strings, numerical values, and enums are the primary cause of function call failures.

    2. Strong Constraint Training for Structured Output

    Uniformly adopt structured formats such as JSON as output targets, and maintain high consistency in the training data format. During the inference phase, combine this with constrained decoding (constrained sampling) technology to ensure the output is always legal structure from the vocabulary level, further eliminating format errors.

    3. Iterative Evaluation and Error Analysis

    Establish an automated evaluation set and categorize statistics by error type: Was the wrong function selected? Were parameters missing? Was the format illegal? Targeted supplementary training data should be added for the error type with the highest proportion, undergoing multiple rounds of iteration. The process of increasing the success rate from 46% to 90% is essentially a loop of “evaluate—attribute—supplement data—retrain.”

    4. Practical Case: Multi-Model Chaining for Offline Speech Transcription Apps

    The complexity of on-device scenarios often cannot be handled by a single model. Taking an offline speech transcription and organization app as an example, a reasonable architecture is the collaborative chaining of multiple small models, each with its own specific duties:

    1. Speech Recognition Model: Responsible for converting audio streams into raw text, running entirely locally to ensure privacy and offline availability.
    2. Text Cleaning Model: A small language model responsible for removing colloquial redundancies, correcting recognition errors, and adding punctuation.
    3. Structured Organization Model: Extracts key points based on intent from the cleaned text, generates summaries, or executes user-specified operation instructions.

    The advantage of this chaining architecture is that each model only needs to achieve high precision in its narrow domain, and the reliability of the overall system is the product of the reliability of each link. Fine-tuning can push the success rate of each link above 90%, thereby guaranteeing an end-to-end experience. In contrast, expecting a general-purpose model to do everything well at once is almost impossible under on-device resource constraints.

    5. Engineering Implementation Recommendations

    Finally, here are several engineering recommendations for on-device agent deployment:

    • Quantization First: On-device deployment typically requires INT8 or even INT4 quantization. Fine-tuning should be conducted under a quantization-friendly precision scheme, and whether the capability degradation after quantization is within an acceptable range should be verified.
    • Skill Modularity: Maintain independent fine-tuned weights (such as lightweight fine-tuning schemes based on Low-Rank Adaptation) for each independent skill, facilitating on-demand loading and independent iteration.
    • Retain Fallback Paths: When the model’s confidence is insufficient or a request exceeds the skill scope, there should be a clear fallback strategy, such as asking the user for clarification, or using cloud-based general capabilities as a backup with user authorization (e.g., via model inference services on intelligent cloud platforms).
    • Continuously Collect Real Data: Real failure cases post-deployment on the device are the most valuable source of training data. Establish a compliant data feedback mechanism to allow the model to continuously evolve with usage.

    Conclusion

    The competition for on-device agents lies not in how large the model is, but in how deep the skill goes. Through a narrow and deep fine-tuning path, small models can entirely achieve production-grade reliability on specific tasks. The leap from a 46% to 90% success rate proves that fine-tuning is not just an add-on, but a necessary path for on-device agents to transition from demos to practical use. For developers, establishing a methodology of “task decomposition, data-driven iteration, and iterative evaluation” early on will be a core competitive advantage in building next-generation intelligent terminal applications.