Tool routing on-device with a 0.8-billion-parameter model

MLX-LM LoRA on Qwen3.5-0.8B, GBNF grammars that make schema violations impossible, and smoke-test numbers labeled honestly.

kAir (project site: gogosling.ca) is my chat-first iOS app (pre-TestFlight — it has shipped to nobody, and this post is not a launch announcement). Its interesting subsystem is kAir-models: making a small local model decide, on the phone, which tool a user's message should invoke. No cloud round-trip, no key, no telemetry.

Why a small model can hold this job

Tool routing is not open-ended generation. The model reads a message and must emit one structured decision: which of a frozen set of tools, with which arguments. Narrow task, closed vocabulary, hard output contract — exactly where a 0.8B model can be competent if you refuse to let it improvise.

The setup: MLX-LM LoRA fine-tuning of Qwen3.5-0.8B on Apple Silicon, against a frozen contract — tools.yaml, labels.yaml, and a JSON schema that define what a valid routing decision even is.

Grammar-constrained decoding does the heavy lifting

The single highest-leverage decision was GBNF grammar-constrained decoding: the decoder literally cannot emit tokens outside the routing grammar. Schema violations stop being a failure mode you measure and become a failure mode that cannot occur. The fine-tune then only has to learn which valid answer is right, not how to produce valid answers.

Honest numbers, labeled as what they are

The round-1 smoke evaluation is n=22 — a smoke test, not a benchmark, and the README says so in those words. Within that scope:

  • Schema validity and tool-routing accuracy went from 0 → 1.000 (the base model without grammar + LoRA failed the contract; the constrained fine-tune satisfies it).
  • Latency on-device: p50 74 ms, p95 109 ms.

I keep the sample size in the same sentence as the result on purpose. Small-n evaluations are fine as directional gates; they are dishonest as generalization claims.

The export and gating pipeline

Training runs HF + LoRA, then exports to GGUF, Core ML, or ONNX, so one training pipeline feeds whichever runtime the app side needs. An evaluation-gate script sits between "trained" and "shipped": if the contract tests fail, the model artifact does not move.

Small models earn their place when the task is narrow, the output is constrained by construction, and the numbers are labeled honestly. That combination — not scale — is what makes on-device viable.