The Learning Router ← sugeerth.github.io

The mechanism

Seven compositions, one label, and a hash of what you asked

The arithmetic is about fifty lines. Everything else in the file is the restraint — and the two things that went wrong first are more instructive than the version that works.

The seven compositions

Prompt Studio builds every prompt from two axes. Steer runs across the page and sets how much the prompt is allowed to shape the reply; Depth runs up it. Three by three is nine, but Depth is not live in Native — the model owns the length there — so the three Native cells are one composition wearing three hats. Collapsing them leaves seven real choices and stops the model spending evidence telling identical outcomes apart.

compositionwhat it means
NativeSay the goal, leave the form entirely to the model.
Guided / ×3State how much you want back, at one of three depths.
Shaped / ×3Fix the answer's form as well, at one of three depths.

The bug: it is a classifier, not a bandit

The first version modelled this as a multi-armed bandit. Score the composition that was on screen; when the user dragged somewhere else, score that one too. It is the obvious framing and it is wrong, in a way that only showed up as a number.

A composition you only ever drag to is only ever recorded on the occasions it won. The one on screen absorbs every failure. The dragged-to one absorbs nothing but successes, converges on a perfect record, and the router flips to it — whereupon the roles swap and the two oscillate forever. Scored that way the router finished six points below the last-write-wins baseline it exists to replace.

The fix was the framing

A bandit is for when you only learn the payoff of the arm you pulled. That is not this problem. The axes you settle on before copying reveal which composition was right for that ask — the full label, not one arm's payoff. So every composition is scored on every labelled ask: the one you ended on was right, the other six were wrong.

That change is worth about eleven points of swing, and it has a second benefit that matters more for a tool people can inspect. A composition's mean now means something you can read off the table directly — how often this was the setting you wanted — rather than being an estimate conditioned on the occasions it happened to get shown.

Only one outcome stays bandit-like. If you type a new topic without settling on anything, no label was revealed, so the single weak inference available is that whatever was on screen did not earn a copy — recorded at about a third of a labelled observation's weight.

The second bug: two exploration schemes on one decision

UCB1 was adding a count-based optimism bonus and LinUCB was adding a context-based one, each unaware of the other. Their sum was larger than any composition's evidence could overcome, so the router offered all seven in rotation, forever, and never settled on anything.

One mechanism now, and it has to be the contextual one: the bonus has to shrink in the direction the evidence actually arrived in, not merely with a count. A composition can be well-established for code asks and still appropriately uncertain for cooking ones.

How it reads the ask

Tokens of the ask are hashed into 24 buckets and L2-normalized, plus a constant bias feature so an empty ask still produces a usable vector. Each composition fits a ridge regression over that vector. This is what lets "debug the failing import in this build" inherit from "fix my failing build" without the two sharing a domain label.

The regression is diagonal — per-feature precision, no cross-feature terms — and that is a storage decision rather than a statistical one. A full covariance matrix is 24 × 24 floats per composition, about 40 KB serialized for all seven, which is a lot to ask of localStorage for a convenience sitting next to a 240-token profile. Diagonal costs 2 × 24 per composition, which measures at about 2 KB after a week in one domain and under 8 KB at the twelve-domain cap. It is a real approximation: it cannot learn that two words only matter together.

Three estimates, blended by how much each has earned

termwhat it knowsweight
domain tally How this composition does for this domain specifically. Precise, and the part a person would recognize as "it learned how I like my tax prompts". Grows with domain evidence: n/(n+4)
context model How it does for asks that read like this one, across every domain. The remainder, shared with the global term
global mean How it does overall. The fallback that keeps a cold domain from behaving like a fresh install. The remainder, shared with the context term

What stops it from being annoying

This is the only layer in the engine that moves a control you can see, which is more authority than the rest of its personalization has. The engine's own doctrine is that personalization re-ranks and never decides, so a layer that decides has to be bounded, and each bound is a test rather than a comment.

Where the idea comes from

The same machinery, one level up, routes between agents rather than between settings: self-improving graph agents treats a multi-agent system as a weighted directed graph and learns the edge weights from outcomes — contextual routing, confidence-gated verdicts, and the rule that an edited prompt cannot inherit the old one's win rate all come from there. This is that idea reduced until it fits in a browser tab with no network and a few kilobytes of state.