Fine-Tuning On-Device Agents: Improving Function-Calling Success for Small Models

    This article examines how to make small language models deployed on resource-constrained devices reliably handle function calling, tool selection, and task planning. It covers a layered skill framework, a narrow-and-deep fine-tuning strategy, data construction practices, training configuration, and a four-level evaluation method. It also discusses a post-deployment feedback loop for maintaining call success.

    As agent applications extend from the cloud to end devices, developers increasingly need small language models to handle function calling, tool selection, and task planning reliably in environments with limited compute, memory, and power. Industry practice shows that although general large models are capable, they are difficult to deploy directly on devices. Small models that receive targeted fine-tuning can instead approach or even exceed large-model performance on specific tasks. This article focuses on improving agent performance through fine-tuning and systematically covers skill framework design, fine-tuning strategies, and evaluation methods for on-device agents.

    Why On-Device Agents Need a Dedicated Skill Framework

    The core difference between on-device agents and cloud agents is resource constraints. Available device memory is often only a few GB, inference latency directly affects user experience, and network connectivity may not always be stable. Therefore, the architecture of an on-device agent must answer three questions: which capabilities must run locally, which skills the model needs to master, and how those skills should be combined.

    One effective approach is to build a layered skill framework:

    1. Intent understanding layer: parses user input and determines the task type and required tools.
    2. Function-calling layer: maps intent to a structured function-call request, including the function name, parameter names, and parameter values.
    3. Execution and feedback layer: calls local interfaces to perform operations and returns results to the model for generating a natural-language response.

    In this framework, the model does not need to know everything. It needs to be highly reliable within its responsibility boundary. This understanding directly determines the direction of subsequent fine-tuning.

    Small Models Require Narrow-and-Deep Fine-Tuning

    General fine-tuning often pursues broad coverage: as many task types and conversation styles as possible. For small on-device models, however, this approach yields limited results. There are three reasons:

    • Limited capacity: the parameter scale of a small model means it cannot memorize large amounts of knowledge from many different distributions at the same time. Broad training dilutes each capability.
    • Converged task scope: the function set faced by an on-device agent is usually closed—system APIs, application capabilities, device controls, and similar interfaces. The total number is limited and the format is fixed.
    • Low error tolerance: function calling is a discrete all-or-nothing task. A single incorrect character in a parameter name can cause execution failure.

    The correct strategy is therefore “narrow and deep”: select a clear capability domain, such as local function calling, build high-density and diverse training data around it, and polish that capability to a high level. “Deep” here has three dimensions: covering various parameter combinations for all functions in the domain; covering multiple natural-language expressions of the same intent; and covering confusing scenarios and negative samples so the model learns when it should not call a function.

    Engineering Practices for Fine-Tuning Data

    Data quality is critical to the narrow-and-deep approach. The following principles are recommended in practice:

    1. Organize data around real function signatures. Each training sample should include the function definitions visible in the system prompt (in JSON Schema form), the user request, and the structured call the model should output. The function definitions themselves should also be randomized—changing the order of functions in the prompt and varying the number of visible functions—to prevent the model from memorizing fixed positions.

    2. Diversify user expressions. For the same intent, such as “lower the screen brightness,” the data should cover real input variants including colloquial speech, omissions, typos, and mixed-language input. Template expansion combined with manual review can ensure diversity without distorting the data.

    3. Explicitly construct hard samples. These include samples with parameter-type errors (for example, confusing strings and numbers), disambiguation samples with multiple function candidates, samples where insufficient information should lead to a clarifying question rather than a forced call, and refusal samples for completely irrelevant requests. Negative samples should account for no less than 20% of the total.

    4. Strictly isolate training and evaluation sets. The evaluation set must include expressions and parameter values that never appear in training. Otherwise, the measured success rate will be seriously inflated.

    A typical training sample structure is shown below (illustrative):

    1. {
    2. "tools": [{"name": "set_brightness", "parameters": {"level": "integer 0-100"}}],
    3. "user": "The screen is too bright; make it dimmer",
    4. "assistant": {"name": "set_brightness", "arguments": {"level": 30}}
    5. }

    Training Strategy and Key Details

    Several lessons are worth emphasizing in training configuration:

    • Choose a small-parameter base model that supports instruction fine-tuning. Prioritize its native performance on structured output rather than overall leaderboard rankings.
    • Prefer parameter-efficient fine-tuning methods such as low-rank adaptation. This controls the model size increment for on-device deployment and makes it easier to maintain multiple pluggable adapter modules for different skills.
    • Weight training on the output portion. The loss function should focus on the tokens for function names and parameters rather than the user input, so the model spends its capacity where it matters most.
    • Control training epochs and use early stopping. Overtraining on small data can harm the model’s instruction-following generalization.

    Evaluation: A Jump from 46% to 90% Call Success

    Function-calling capability should not be evaluated only by a single final success rate. It is better to split evaluation into four levels: function selection accuracy, parameter-name completeness, parameter-value accuracy, and overall call success rate (all three previous conditions satisfied). Without fine-tuning, a base small model usually has an overall success rate of only 40–50%. The main failure points are parameter-value format errors and function misselection.

    After targeted narrow-and-deep fine-tuning, industry practice shows that the overall success rate can rise to around 90%, with remaining errors concentrated in “insufficient information, should ask a clarifying question” scenarios where training-data coverage is insufficient. This jump validates the core conclusion: within a closed task domain, data quality and coverage depth matter far more than model scale.

    After launch, a continuous feedback mechanism should also be established: sanitize online failure cases, add them to the training set, and iterate the model regularly to form an “evaluation—data supplementation—retraining” loop. At the infrastructure layer, general container platforms can be used to run training tasks, object storage to manage dataset versions, and monitoring and alerting to track online call success rates, ensuring iteration efficiency.

    Conclusion

    Model optimization for on-device agents is essentially an engineering tradeoff of depth for breadth. Defining skill boundaries, building high-quality data around function signatures, using parameter-efficient fine-tuning, and establishing a layered evaluation system form a complete path for small models to achieve reliable function calling on devices. For teams that want to deploy agent capabilities on end devices, this narrow-and-deep fine-tuning path has controllable investment and clear returns, and is worth trying first.