Case Study/AI & Agents/Design, engineering, maintenance
LLM Switchboard Router
- Author
- Aryan
- Client
- Open source
- Published
- 2026
- Length
- 6 min · 1214 words
Abstract
Local router that scores a prompt across 14 signals and picks a model tier in under a millisecond.
Key outcomes
- Routing latency
- < 1 ms
- Signals scored
- 14
- Classifier cost
- $0
The cost shape of an agent product
High-volume AI products have an asymmetry problem. A large share of traffic is greetings, yes/no confirmations, short data extraction and routine summarisation, and every one of those prompts can be answered by a small model at a fraction of the price of a frontier one. A small remainder is systems design, multi-step debugging or formal reasoning, where the expensive model is the only one that produces a usable answer. Sending the whole mix to the top tier pays frontier prices for the easy majority. Sending the whole mix to the cheap tier produces confident nonsense on the hard minority.
The obvious fix is to classify the prompt with another model. That fix is the reason this project exists in the shape it does, because a classifier model is not free in either of the two currencies that matter. It costs a network round trip before the real request can even start, and it costs a second bill that scales with traffic. Worse, it makes routing stochastic. The same prompt can be classified differently on two runs, which means the routing decision cannot be asserted in a test and cannot be reasoned about after the fact when a caller reports a quality problem.
Classification as a pure function
The architectural decision that shapes everything here is that routing is a pure function of the prompt string and the routing configuration. It reads those two inputs and computes from them alone, so the whole decision rests on the prompt text and the routing table. A prompt goes in, a tier comes out, and the whole computation runs in under a millisecond because it is arithmetic over a set of regular expressions and word counts.
The consequence is not only speed. A pure function is testable. Routing behaviour can be asserted in unit tests and exercised against a fixed corpus of prompts, so a change to the weights either keeps the expected tiers or fails the suite. That property is missing from classifier-based routing, where the only way to evaluate a change is to run a sample of live traffic through a model with its own variance, and where a regression is only visible as a slow drift in downstream quality.
Four tiers, one routing table
Prompts are sorted into SIMPLE, MEDIUM, COMPLEX or REASONING, and each tier carries a
primary model plus an ordered fallback list. The library ships defaults, but the routing table is
intended to be set by the host application at startup. configureRouter takes the tier definitions
once, and any call site can then ask for the right model without knowing anything about the
heuristics behind the answer.
The tier boundary is the interesting design surface. SIMPLE covers greetings, boolean answers and
short extraction. MEDIUM covers summarisation, ordinary chat and basic coding. COMPLEX covers
systems design, deep analysis and large context. REASONING covers mathematics, proofs and
multi-step debugging. The names are deliberately about the task rather than the vendor, because
model lineups change faster than workload categories do, and a routing table expressed in task terms
survives a model swap without being rewritten.
What the fourteen signals measure
Scoring runs across weighted dimensions grouped into five families.
Token density estimates semantic weight against raw length, so a long prompt that says very little does not get promoted purely for being long. Syntactic markers catch code fences, mathematical notation and imperative verbs. Instruction depth looks for formatting demands, the requests that ask for JSON, a table or CSV, which tend to correlate with workloads a smaller model handles badly. Agentic signatures look for planning language and tool-use intent. Domain context scans for technical vocabulary and high-entropy keywords that suggest a specialised subject.
Intent detection is multilingual, covering the major languages these workloads actually see rather than assuming English. The signals are summed with per-signal weights and the total is mapped across thresholds to a tier. Nothing in the pipeline calls out to classify the language first, so a mixed-language prompt degrades to a lower-confidence score instead of failing or defaulting to a tier at random.
Agentic detection as a separate axis
One of the fourteen signals deserved its own treatment. A prompt can be short and still describe a multi-step task with several tools used in sequence, and length-based scoring will read that as trivial. Agentic detection looks specifically for planning structure and tool intent so that a compact but operationally heavy request lands in a tier that can follow instructions reliably.
There is also an explicit override. Agentic mode can be forced on globally through configuration, which is what a host application does when every request is already part of an agent loop and the heuristic read of a single turn is less useful than the fact that a tool loop is running.
Configuration, overrides and fallbacks
The routing table is global, but it is not fixed. getProductionModel accepts per-request
overrides, including a whole replacement tier definition. The override exists for prompts with
non-standard requirements, not for prompt-by-prompt tuning.
The clearest use is privacy. A request that must not leave the machine defines a COMPLEX tier
pointing at a local model with an empty fallback array, so the router cannot silently promote it to
a cloud model when the local one is unavailable. Expressing that as configuration rather than as a
branch in application code is what keeps the privacy rule auditable in one place.
Fallbacks themselves are ordered, so a tier can degrade through a preferred model, a secondary provider and a local option without the caller encoding any of that logic.
Determinism as an operational property
The router is deployed in front of several bot and agent workloads where the routing decision needs to be explainable afterwards. Because the score is computed from the prompt and the configuration, a logged prompt can be replayed through the same version of the router and produce the same tier. That is what makes an incident review possible, and it is the property a classifier-based router cannot offer without logging the classifier’s own input and trusting its reproducibility.
It also removes a class of outage. Classification happens locally, so nothing upstream can go down, the classification step cannot be rate-limited, and the first token of the real request starts without added latency.
What was hard, and what I would do differently
The honest difficulty with heuristic routing is that heuristics are easy to write and hard to calibrate. Weighting was originally tuned by reading prompts and adjusting numbers until the results looked right, which is a process that does not survive a new workload or a new language. The correct approach is a labelled evaluation corpus with expected tiers and a per-tier error budget, so a weight change is measured rather than judged.
The second thing worth revisiting is the boundary between MEDIUM and COMPLEX. It carries most of
the traffic and most of the disagreement, and it decides whether a summarisation task gets a cheap
model or an expensive one. A single scalar threshold across fourteen signals is coarse at that seam,
and a two-stage rule, where a borderline score consults one or two additional signals before
committing, would likely separate those cases better than another global weight adjustment.
References
- [Source repository]github.com/Uo1428/llm-switchboard
- [Author]Aryan (Uo1428)
Built with