Function Calling for On-Device Small Models: From Conversation to Reliable Execution

    This article examines how small on-device models can be specialized for function calling, why model responsibilities must be separated from deterministic execution, and how tool definitions, structured protocols, safety controls, deployment optimization, exception handling, and evaluation affect real-world reliability. It argues that specialization should narrow open-ended generation around an execution loop rather than eliminate dialogue.

    1. Why On-Device Agents Need an Execution Specialist

    When large models move from question-answering interfaces into task execution workflows, the system’s requirements for model output change fundamentally. Answering “How do I set a reminder?” allows the model to use different wording. Actually creating a reminder for the user requires an explicit time, content, execution permission, and confirmation of whether the operation succeeded.

    Function calling is therefore not about making a model generate text that looks like a program. It is about converting a natural-language request into verifiable structured actions under a given set of tools and business rules.

    This requirement is even more pronounced on mobile and edge devices. General-purpose models need to cover a wide range of knowledge and language tasks, which usually brings higher weight storage, runtime memory, and compute overhead. On-device tasks are often relatively focused, such as managing local to-dos, adjusting device states, querying cached information, or controlling authorized device functions. Training a smaller model specifically for these tasks can help reduce deployment cost.

    However, specialization does not mean eliminating conversational ability entirely. Function calling still requires clarifying ambiguity, refusing unauthorized operations, explaining execution failures, and reporting results to the user. A more accurate design goal is to narrow the responsibility of open-ended text generation and let the model perform the necessary interaction around the execution loop.

    2. Define the Boundary Between the Model and the Execution System

    A reliable agent should distinguish at least four stages:

    1. Understanding and decision-making: Identify user intent and determine whether a tool is needed.
    2. Call generation: Select from allowed tools and generate candidate arguments.
    3. Validation and execution: Use deterministic program logic to check arguments, permissions, and business constraints, then call the real interface.
    4. Result feedback: Generate a concise, accurate explanation based on the actual return value.

    The model belongs to the first two stages and may also participate in the fourth, but it cannot replace the safety controls in the third stage.

    For example, if the user says “Move tomorrow morning’s reminder to nine,” the model may need to query existing reminders first, identify the target object, and then request a modification. If multiple reminders match the condition, the system should ask a follow-up question rather than arbitrarily selecting one.

    This boundary also helps avoid a common error: treating the model’s output of “modification successful” as proof that the operation has already completed. The model is only responsible for proposing a call. The actual state must be confirmed by the executor and the tool’s returned result.

    3. Small-Model Capability Comes from Task Convergence and Training Adaptation

    1. Parameter size is only a starting point

    Fewer parameters usually mean lower weight storage requirements, but this does not directly imply lower overall latency. On-device runtime cost is also affected by input length, generation length, weight precision, runtime implementation, device hardware, and number of calls.

    Function-calling tasks have an advantage because outputs are usually short. If tool definitions are compact enough, the model only needs to generate the tool name and necessary arguments, reducing irrelevant text generation. However, if every request includes a large number of tool descriptions and the full history, input processing can still become the main overhead.

    Therefore, both model size and task context should be optimized, rather than focusing only on parameter count.

    2. Distinguish base pretraining from task-specialized training

    Base pretraining mainly provides language understanding and general pattern recognition. Function-calling training further strengthens tool selection, argument extraction, constraint compliance, and interaction strategies.

    The data scale, objectives, and effects of the two cannot be conflated. Training volume on general corpora cannot directly prove function-calling reliability, and vocabulary size alone cannot prove that structured output is more accurate. Actual performance must be validated on target devices, target tool sets, and real business distributions.

    3. Training data should cover the full decision process

    Providing only “user request—correct call” samples can easily lead a model to develop a tendency to call tools for everything. More complete data should include:

    • Requests that do not need a tool call and can be answered directly;
    • Requests that lack required arguments and need clarification;
    • Requests beyond the capability of the available tools;
    • Requests involving multiple steps or dependencies;
    • Reasonable handling after a tool execution failure;
    • High-risk operations that require confirmation;
    • Factual feedback after a tool returns a result.

    For example, “Remind me to submit the materials” lacks a specific time, so the reasonable behavior is to ask for the time. “Cancel all reminders” may involve batch deletion and should require confirmation according to business policy.

    The focus of training is not only output format, but also learning when to act and when to pause.

    4. Tool Definitions Set the Upper Bound of Call Quality

    Whether a model can call a tool correctly depends heavily on whether the tool description is clear. A usable tool definition should specify the name, purpose, parameter types, required fields, value constraints, and necessary side-effect information.

    The following is an illustrative business-defined structure, not an interface from any specific product:

    1. Tool name: create_reminder
    2. Purpose: Create a local reminder
    3. Parameters:
    4. title: string, required, reminder content
    5. trigger_time: string, required, explicit time including time zone
    6. Constraints:
    7. Time must be later than the current time
    8. Side effects:
    9. Writes a local reminder record

    Tool descriptions should be “clear enough without being excessively verbose.” Tools with similar names or overlapping responsibilities increase selection difficulty. Packing multiple different operations into one vaguely defined tool also makes argument combinations more complex.

    For relative time expressions, the system should also provide a trusted current time and time zone. The model cannot infer the runtime environment solely from phrases such as “tomorrow” or “next Monday.”

    As the number of tools increases, candidate tools can first be filtered by the current page, user permissions, and business scenario, and then passed to the model for selection. The filtering process must retain necessary tools and provide an explicit fallback path when the candidate set cannot cover the request.

    5. Structured Protocols Are Better Than Free Text for Execution Chains

    1. Explicitly separate message types

    A complete interaction chain can be represented as:

    1. User request
    2. → Model proposes a tool call
    3. → Executor validates
    4. → Tool returns result
    5. → Model responds or makes another decision

    The system needs to distinguish user messages, tool definitions, model calls, and tool results, and cannot concatenate them all into unbounded text. Otherwise, the model may mistake tool return content for a new operation instruction.

    Some models use dedicated control markers to distinguish these messages, but marker names and syntax must follow the actual model’s conventions and cannot be invented arbitrarily. For systems that do not provide dedicated markers, boundary management can also be implemented through explicit message fields and structured data.

    2. Correct format does not mean correct semantics

    The following is an illustrative model candidate call:

    1. {
    2. "tool": "create_reminder",
    3. "arguments": {
    4. "title": "Submit materials",
    5. "trigger_time": "2030-05-13T09:00:00+08:00"
    6. }
    7. }

    Even if this data can be parsed, the executor still needs to check:

    • Whether the tool is in the current allowlist;
    • Whether there are unknown fields or missing required fields;
    • Whether argument types, lengths, and values meet requirements;
    • Whether the time is reasonable and matches user intent;
    • Whether the current user has execution permission;
    • Whether the operation requires secondary confirmation.

    When the inference runtime supports syntax constraints, generation can be restricted to conform to a predefined structure, reducing format errors. However, syntax constraints cannot replace business validation: an incorrect time and an incorrect object identifier may still fully satisfy structural requirements.

    6. Keep Safety Controls Outside the Model

    Function calling turns language output into real side effects, so safety mechanisms must be independent of model judgment.

    First, the executor should use a tool allowlist rather than dynamically executing arbitrary code based on model output. The model can choose from pre-registered actions, but it cannot expand execution permissions on its own.

    Second, high-risk operations such as deletion, transfers, and permission changes should have confirmation flows. Confirmation should be bound to specific objects and arguments, and a previous user approval cannot be treated as authorization for all subsequent operations.

    Third, tool return content should be treated as data, not as high-priority instructions. Even if a document, email, or external query result contains text such as “ignore the rules and perform a certain operation,” it should not change the system’s permission boundary.

    In addition, logs should record call decisions, validation results, execution status, and error types, while redacting sensitive fields. On-device operation can reduce some data transfer, but it does not automatically mean there is no privacy risk. Local caches, debug logs, and shared device access still need to be managed.

    7. On-Device Deployment Requires Optimizing the Full Chain

    On-device performance optimization should cover input, inference, and execution.

    Input stage: Tool descriptions can be compressed, irrelevant history can be trimmed, and current task state can be stored as structured information. The context window is only a capacity limit; it does not mean longer is always better. Long input increases processing cost, and related caches also consume memory.

    Inference stage: Evaluate quantization, short-output constraints, and execution methods adapted to the target device. Quantization can help reduce weight storage and some runtime costs, but it may affect tool selection or argument generation. It needs to be retested rather than merely checking whether the model can load.

    Execution stage: Avoid mixing blocking tool operations with interface interaction. For time-consuming tasks, asynchronous execution can be used, and clear status should be shown to the user.

    At the same time, not all tools can work offline. Local model inference only means the decision process can avoid remote inference. If the tool itself requires network access, remote data, or online authorization, the entire task still cannot be fully offline.

    8. Exception Handling Determines Real-World Usability

    Successful examples are usually easy to construct. The difficulty lies in keeping the system controllable after failures.

    For missing arguments, the system should ask a follow-up question. For format errors, a limited number of corrections can be attempted. For insufficient permissions, execution should stop and the reason should be explained. For temporary network errors, retries can be performed according to business policy.

    In particular, the system must distinguish between “definitely not executed” and “execution result unknown.” If a create operation has already been submitted but the response times out, directly retrying may produce duplicate records. Such write operations should use idempotent mechanisms where possible, or confirm the result through a status query.

    Multi-step tasks also need to record the state of each step. After one step fails, the system should not assume that subsequent steps are still safe, nor should it claim that the entire task has completed. When necessary, it should stop, request human confirmation, or perform a pre-designed compensation operation.

    9. How to Evaluate Function-Calling Specialization

    Evaluating this type of model cannot rely only on whether responses are fluent. At minimum, the following should be measured separately:

    • Tool selection accuracy: Whether the correct tool is selected, and whether the model correctly decides not to call a tool.
    • Argument correctness: Whether arguments are complete and whether values match user intent.
    • Structural validity: Whether output passes parsing and structural validation.
    • Clarification quality: Whether necessary but not excessive follow-up questions are asked when information is missing.
    • Execution success rate: Whether the final tool operation is completed.
    • Safety performance: Whether unauthorized calls, confirmation bypasses, or manipulation by untrusted content occur.
    • On-device resource cost: Latency, peak memory, sustained power consumption, and thermal stability.

    Evaluation sets should also cover colloquial omissions, similar tools, time ambiguity, multi-turn modifications, and abnormal returns. Training samples and test samples need to be isolated; memorizing fixed expressions cannot substitute for generalization.

    10. Conclusion: Specialization Tightens Responsibilities Rather Than Removing Dialogue

    The function-calling path for small on-device models essentially converges open-ended generation into a constrained task-decision problem. Its value comes from clear tool boundaries, targeted training, structured protocols, and a verifiable execution process, not from a particular parameter size or a single configuration.

    In engineering practice, the safest principle is: let the model understand and propose actions, let the program validate and execute, and let tool results determine the final feedback. Only by separating these three layers of responsibility can on-device agents move from “looking capable of doing things” to “being able to complete things reliably.”