Before every single prompt, the router would first ask a cloud LLM which cloud LLM it should actually ask. The classification step itself ran through a model in the cloud. That cost seconds instead of milliseconds, money on every single prompt, and it shipped the prompt text off to a third-party provider before any local model had even been consulted. Laya, the local decision model that now does this job, fixes all three.

That cloud classifier was not my first attempt, it was my second. The original plan was local from day one: Gemma 4 through Ollama or similar, running next to the models it was routing to, classifying every prompt on the machine. In practice it regularly pushed the CPU to its limit, and classification is the one job that fires on every single prompt, so a machine busy with its own classifier is a machine that answers slowly. Moving the classifier to the cloud, deliberately a weak and cheap model, fixed the CPU load. What it bought me instead: seconds of latency, a paid call before every prompt, and prompt text leaving the machine before any local model got a say.
As of version 2.0.0 of the Dynamic Model Router project, that’s over. Quick context for anyone joining here: the router is an open-source extension for the Pi coding agent, and its whole job is deciding which LLM should answer a given prompt. I introduced it in June. The third attempt at that decision is the one that stuck: a model that was actually built to classify. The router no longer asks a language model to classify at all. The qualification is now done by a dedicated, purpose-trained decision model, a fine-tuned encoder called Laya, the same pattern Jev made familiar for LLM routing, except here it runs locally and is trained on the router’s own taxonomy. Laya plugs in as a single virtual Pi model (router/dynamic) that routes prompts across five clearly separated groups.
The actual change: a decision model, not an LLM
The part I find genuinely new in 2.0 is not the local-vs-cloud swap. It’s what kind of model makes the decision. „Which group does this prompt belong to?“ is a classification problem, not a language-modeling problem. Both of my earlier attempts used an LLM for it anyway, first a local one that ate the CPU, then a cloud one that ate latency, money, and privacy, because, well, what else would you classify text with? A purpose-built decision model, as it turns out.
The best-known take on doing it properly is Jev, a decision model you put in front of your LLMs to route traffic. Instead of prompting a generative model with „classify this and return JSON“, and hoping it doesn’t hallucinate a category or mangle the structure, a decision model returns a typed answer: one category, plus probabilities, designed to be consumed by conditional logic. In LiteLLM’s benchmark that pattern came out 5.43× as fast as Haiku at 96% lower cost. The classifier in front of your models stops being the thing nobody prices.
Laya (based on convaiinnovations/laya-multilingual) is my version of that idea, with two twists: it runs entirely on my machine, and it is trained on a taxonomy that matches the actual purpose, model routing, not a generic one. It is not a generative LLM. It’s an encoder with a decision head, built on mmBERT-base with a ModernBERT architecture: it reads a prompt once and answers, instead of writing tokens until an answer somehow exists. That shape is what makes the whole plan work. At 322M parameters it is small enough to sit next to the models it routes to, loads in under half a second warm, and settles at roughly 1.1 GiB of memory. It would accept up to 8,192 tokens of context, but it ships with a 1,024-token limit, and I left it there: router prompts rarely need more, and a fixed window keeps latency predictable, which matters when classification fires before every prompt.
Each prompt yields exactly one category plus a confidence score. That was a deliberate farewell to the earlier multi-label idea: one category per prompt is enough. The taxonomy was streamlined to seven categories, and each of them exists for a reason:
| Category | What it means | Where it routes |
|---|---|---|
simple | One-liners, no reasoning: greetings, factual snippets | simple, the cheap pool |
code_simple | Tiny mechanical code changes | the same simple group |
standard | Normal tasks, medium effort | standard |
code_complex | Demanding coding: architecture, debugging, multi-file work | code_complex |
design | API and architecture design deliberation | design, the top tier |
planning | Task decomposition, step planning | planning, the reasoning tier |
continue | A short „keep going“, only recognizable with the previous turn as context | inherits the previous category, keeps the model that was just answering |
Seven categories, five groups: the two cheap ones share one pool, continue is not a destination but a memory, and the two top tiers, design and planning, never route to a free model.
trivial and exploration were dropped, the evidence said they were noise, not signal: identical texts got different owner labels in different sessions.
The honest numbers
Let me start with the uncomfortable part: Laya got smarter, but it is not (yet) smarter than a big cloud LLM acting as a classifier. Which sounds like an argument against decision models, until you look at what that cloud LLM was being asked to do: a job a classifier should have had all along.
- Zero-shot was unusable. Untrained, Laya hit the correct category on 3.9% of my golden set, 180 prompts I had labeled by hand, and the correct group on 17.2%. Without fine-tuning, this would have gone nowhere.
- After fine-tuning (r2: 2,019 corpus items, labeled by a teacher LLM plus 85 of my own owner labels weighted 3×, trained locally on Apple Silicon), held-out accuracy against my own labels was 43.2%.
- The cloud teachers (GLM-5.3, Opus 5.5) reached 53.4% on the same set. Interesting detail: Opus was not measurably better than GLM, McNemar test p = 0.51.
On paired live items the picture was better: Laya scored 47.3% against 36.4% for the classic classifier chain. But that gap of almost 11 percentage points is not statistically significant (CI −7.9 to +29.7).
So why Laya? Because the actual comparison looks different:
| Classifier chain (cloud) | Laya (local) | |
|---|---|---|
| Latency (median, live, 54 pairs) | 13,188 ms | 935 ms |
| Cost per prompt | one paid cloud call | zero |
| Prompt text | leaves the machine before routing | stays local |
| Offline | no | yes |
That’s an order of magnitude faster (about 14×), free, private, and works offline. Add to that the finding that sealed it for me: agreement between Laya and the cloud chain sits at only about 46–50%. The chain itself is not a reliable ground truth. For a routing decision that fires before every single prompt, the local encoder is the better deal.
So Laya decides, and the old chain is demoted to a last resort: Laya → local Ollama → cloud. The October post still routed cloud-first; 2.0 flips that order. Turn the cloud classifier off, and prompt text never leaves the machine.
What didn’t work
More data made it worse. After r2, the obvious next step was more of everything: more training items, a longer run. r3 got 3,162 items instead of 2,019 and 41 minutes of training. The result: continue detection doubled, but group accuracy stayed at exactly 43.2%, and calibration got worse. r3 was never shipped, r2 is what runs in production. Sometimes the model isn’t the bottleneck, the labels are.
Slow must not mean down. At one point the median live latency sat at 1,460 ms, with the timeout at 1,500 ms, and the logs collected 56 timeout warnings in a single month: Laya was permanently on probation, one bad answer away from being switched off. The fix changed the semantics of failure. A single timeout now hands off exactly that one prompt to the chain, only three timeouts in a row count as „Laya is down“. A local component that hiccups degrades the system one prompt at a time, instead of flipping routing back to the cloud.
The lesson from both: measure, don’t believe.
Engineering: from Python duct tape to a one-command install
Shipping a neural network inside an npm package turned out to be its own project. The interesting part is everything that has to be true before installing the router becomes boring again.
Make it run everywhere. The first prototype was Python glue around MLX, Apple’s machine-learning framework, which works on Apple Silicon and nowhere else. ONNX runs on Linux, Windows, and macOS, so that’s what ships. But swapping a backend can shift probabilities in the fourth decimal, so parity isn’t claimed, it’s gated: three test suites compare every prediction between the old and the new stack before anything is released. The gates came back green, 180/180 on the golden set and 99.6% on live traffic, and the single outlier was a near-tie.
Download nothing uninvited. If you never use Laya, the package downloads nothing. If you do, the runtime, about 115 MB, arrives on demand. And there are no install scripts at all: npm resolves straight from a committed lockfile with scripts disabled, so every integrity hash is checked and a third-party postinstall that would pull CUDA libraries from an unverified feed simply never runs.
A helper that stays home. Laya runs as a small separate process next to the router, and it can only talk to the router: it listens on localhost and never sees a provider key. The prompt text it reads has nowhere else to go.
Turning it on. None of this is forced on anyone: Laya ships disabled, and a fresh install of the router routes exactly as it did before. /router laya install runs a wizard that asks before every step, downloading the weights, fetching the runtime, and writing the config entry, and once it is done the classifier is active. /router laya shows what is installed and whether the sidecar is actually running, serve and stop control it.
The rest of 2.0, quickly
- One virtual model instead of a model zoo:
/modelnow shows a single entry, „Router (dynamic)“. Pi keeps that choice on the session branch across--continue,/resume,/fork, and/tree. An old bug meant a session afterpi --continuesilently kept running on the last concrete model and was never routed at all. - A fresh session when the cache stops paying off: a long session is cheap as long as the model keeps recognizing its own context, the prompt cache carries most of the cost. At some point the cache goes cold while the context keeps growing, and in-place compaction only keeps the already-paid context alive: full price for a huge context that stopped earning its keep. The router notices when that point is reached and says so.
/router freshthen does the move: it compacts the session into a handover summary, opens a new session linked to the old one, and hands the summary over as the first prompt. Continuity without the ballast. - Cache warming now works in router sessions: providers charge far less for context they have seen before, and Pi can pre-warm that cache in idle moments, so the next real request arrives cheaper. In router sessions that setting was silently ignored: the virtual model groups declared no cache lifetime and no cost, so Pi’s warmer never knew what to warm. 2.0 declares the served model’s cache economics on the fly, and the warm request goes to exactly the model that just answered, not through the classifier, not through any fallback.
worker_step, or: not every step needs the expensive model: a long turn on a top-tier group runs hundreds of steps, and most of them are mechanical, running gates, grepping logs, applying an edit that is already fully specified. Measured: in long turns, 83% of the steps are mechanical and consume 52% of the tokens. The newworker_steptool hands exactly one such task to the cheap group as a text-only sub-call, while the expensive model keeps doing what it is there for: planning, deciding, judging. That is the idea the October post introduced for file reads, extended to every mechanical step.- A real config surface:
/router configopens a guided menu that shows every key with its effective value and its default. Unknown models are rejected, typos get a „did you mean …?“, and unknown keys are reported instead of silently ignored. For a router that decides a lot on its own, being properly configurable is the other half of the deal. - Mutation testing, the one hygiene habit that paid off: mutation testing plants artificial bugs in the code and checks whether the test suite notices. In the routing core, 468 of them survived. Triaging every single survivor found real gaps, which got new regression tests, and dead code, which got deleted. A green suite says the code works. A mutation-tested suite says the tests do.
Outlook
What remains open, above all, is continue detection (r3 showed the problem isn’t data volume), confidence calibration (Laya’s confidence score is not yet a probability: a 0.8 does not mean 80% right), and building a pipeline that turns my manual category corrections into training data for the next fine-tuning round. And at some point I want to dig into whether perceived and benchmarked model quality even correlate.
Conclusion
The most interesting finding of these months, for me, is that routing in front of an LLM is not a job for an LLM. The purpose-built decision model is not even better at classifying than the cloud models it replaced: 43.2% against 53.4% on the same held-out set, the numbers from earlier in this post. But that gap is small enough that latency, cost, and privacy flip the equation. The prerequisite is that you measure: decision logs, parity gates, held-out sets, and honest confidence intervals.
It also closes a loop this blog series has been circling since June, making AI-assisted development professional without vendor lock-in and without a token bill on every request: the classifier itself was the last component still paying both. Which is exactly why the router now runs 14× faster, free, entirely local, and the thing deciding where a prompt goes is finally what it should have been all along: a classifier.

Schreibe einen Kommentar