Documentation
¶
Overview ¶
Package crewroute picks the crew for one task: which model sits the worker, the planner and the checker seat, on which provider's route, for this piece of work and nothing longer.
── THE ONE SENTENCE IT IMPLEMENTS ──
The /crew panel says what is allowed (it persists); the words in the ask say how hard to try this one task. Nothing else sticks. So there is no preset here and no mode: a caller hands over the task, the models the person allows on the providers they have connected, the seats they pinned, and at most one word of effort, and gets back one crew for this task.
── WHY IT ROUTES ON THE CLASS OF WORK ──
The design is in docs/design/model-pool/pareto-crewing.pdf. The rule it follows: narrow fixes use the cheapest qualified crew, and open-ended work gets a stronger checker, the one seat worth paying for there. The policy is read off a table ([prior]) rather than written into branches: classify the task (Classify), then pick each seat to maximise quality minus λ times cost.
── WHAT IT DOES NOT DO ──
It does not escalate on its own. A done-verdict that misses real solves and passes failures would make an escalation loop spend on the wrong tasks, so AutoEscalate is off, and a stronger crew is something a person asks for (`redo stronger`).
It is PURE: no disk, no network, no clock. The same request gives the same crew, in the same order, every time — which is what lets a decision be logged, replayed and argued with. A decision costs well under a millisecond.
Index ¶
- Constants
- Variables
- func Canonical(id string) string
- func DomainTuned(id string) bool
- func Explain(class Class, lambda float64, candidates []Candidate, ...) map[Seat][]Scored
- func IsFree(id string) bool
- func Knee() float64
- func LearnKey(class Class, seat Seat, model string) string
- func Lineage(id string) string
- func Money(usd float64) string
- func Names(candidates []Candidate) []string
- func Pace(spent, cap float64) (multiplier float64, atCap bool)
- func Scorable(m Model) bool
- func Seatable(seat Seat, c Candidate) bool
- func ShortModel(id string) string
- func Tiny(id string) bool
- type Allowed
- func (a Allowed) AdmitsModel(m Model) bool
- func (a Allowed) AdmitsRoute(provider string) bool
- func (a Allowed) Custom() bool
- func (a Allowed) NamesModel(id string) bool
- func (a Allowed) Rebased(base Base, maxIn, maxOut float64) Allowed
- func (a Allowed) RouteToggled(provider string, admit bool) Allowed
- func (a Allowed) String() string
- func (a Allowed) Toggled(m Model, admit bool) (Allowed, bool)
- func (a Allowed) With(add bool, word string) Allowed
- func (a Allowed) Without(word string) Allowed
- type Base
- type Candidate
- type Canon
- type Class
- type Decision
- type Effort
- type Gap
- type Mod
- type Model
- type NoCandidateError
- type Pick
- type Pin
- type ProvidersOff
- type Reading
- type Request
- type Retry
- type Route
- type RouteKind
- type Scored
- type Seat
- type Task
Constants ¶
const AutoEscalate = false
AutoEscalate is whether a crew is ever made stronger without somebody asking. It is OFF, and a constant rather than a setting, because whether an automatic escalation pays for itself depends on how far the checker's verdict can be trusted, which is a property of the checker, not a preference.
const DefaultAllowed = "all"
DefaultAllowed is the rule a profile that never answered reads.
const Unspent = -2.0
Unspent is the actual cost a line is drawn with when there is none worth saying: a task that stopped before anything was spent. The line then names no money at all, rather than a $0.000 that reads as a free success.
Variables ¶
var Classes = []Class{Bugfix, OpenEnded, Other}
var ErrStrongest = errors.New("this is already the strongest crew the models you allow can make")
ErrStrongest is a redo that asked for a stronger crew than the strongest one the allowed models make.
var Seats = []Seat{Worker, Planner, Checker}
Seats lists the three in the order a crew is read out.
Functions ¶
func Canonical ¶
Canonical is the id a model's evidence is kept under, across every provider's spelling of it (CanonicalOf without the variant).
func DomainTuned ¶
DomainTuned is whether a model's own id says it was tuned for one domain other than code and general work — finance, medicine, law, a single subject, role-play — by a tag among the words of its name. Such a model is a poor seat for software work whatever its figures, and a rescue that must take a model it knows little about takes a general or a code model first.
func Explain ¶
func Explain(class Class, lambda float64, candidates []Candidate, learned map[string]float64, n int) map[Seat][]Scored
Explain is each seat's best n candidates at the λ a decision was made at, best first — what a router log row carries so a crew can be explained from the log alone.
func Knee ¶
func Knee() float64
Knee is the default price of a quality point, in points per dollar — see Route for why this is the knee of the quality-cost front.
func LearnKey ¶
LearnKey is the key a learned quality move is kept under: the class, the seat and the model's lineage.
func Lineage ¶
Lineage is the id a model's quality is kept under: its canonical identity across every provider's spelling (CanonicalOf) — lowercase, a provider's namespace and a route suffix (`:free`, `:nitro`) taken off, a thinking level, a floating alias's `~` and `-latest`, and a dated snapshot suffix taken off. `deepseek/deepseek-v4-flash-0731` is the same lineage as `deepseek/deepseek-v4-flash`, and so is its free pool: a route is not a model. A quantised local copy keeps its variant after `@`, so it is never mistaken for the model it was squeezed from.
func Money ¶
Money spells a task's dollars: three places under a dollar, where the difference between routed crews lives, and two above it.
func Names ¶
Names lists the candidate ids a decision chose among, sorted — the field a logged decision carries so it can be analysed after the fact.
func Pace ¶
Pace is how a daily cap moves the price of a quality point: nothing until half the cap is spent, then λ grows as what is left shrinks — twice as stingy with a quarter of the cap left, five times with a tenth — so a day that is running hot drifts to cheaper crews before it reaches the wall. atCap is the wall itself: the day's spend has reached the cap. A cap of zero is no cap.
func Scorable ¶
Scorable is whether the weights can score a model at all from what its row carries — enough metadata for a finite-variance ability — for a caller that offers models and wants to say which the router may pick unpinned.
func Seatable ¶
Seatable is [seatable] for a caller that offers models for a seat — a picker, a rescue — so it offers exactly what the router could seat.
func ShortModel ¶
ShortModel is a model id without its vendor: the half a person reads.
Types ¶
type Allowed ¶
type Allowed struct {
Base Base
// MaxIn and MaxOut are the price rule's two ceilings, dollars per million
// tokens. Zero on every other base.
MaxIn float64
MaxOut float64
// Members are an explicit list's words.
Members []string
// Mods are the `+x` / `-x` words, in the order they were written.
Mods []Mod
}
Allowed is a parsed rule.
func ParseAllowed ¶
ParseAllowed reads a rule. An empty rule is DefaultAllowed. A rule that does not parse is refused with the reason, because a typo that silently allowed everything would be a setting somebody thinks is protecting them.
func (Allowed) AdmitsModel ¶
AdmitsModel says whether the rule allows a model, before routes are asked.
func (Allowed) AdmitsRoute ¶
AdmitsRoute says whether the rule allows a provider's routes. Only a `-x` naming the provider takes them away; a later `+x` gives them back.
func (Allowed) Custom ¶
Custom says whether the rule is more than one of the three plain bases: an explicit list, or a base with exceptions on it. It is the fourth answer the panel's models row walks between, and the one its checklist edits.
func (Allowed) NamesModel ¶
NamesModel says whether the rule speaks about this model by name — a list member or a modifier matching it. It is how a pin outside a price or open rule can still be let in by name.
func (Allowed) Rebased ¶
Rebased is the rule on a new base with nothing carried over — the `‹ open ›` the panel's row steps to is `open`, and not `open` with whatever exceptions the rule it stepped from happened to have. The price ceilings are taken for BasePrice and ignored for every other base.
func (Allowed) RouteToggled ¶
RouteToggled is the rule with one provider's routes given back or taken away, in the shortest spelling, the way Allowed.Toggled says a model.
func (Allowed) String ¶
String writes the rule back in its canonical spelling, which is what the panel shows and what is stored.
func (Allowed) Toggled ¶
Toggled is the rule with one model's verdict flipped to admit, in the shortest spelling: an explicit list gains or loses a member, and any other base loses the exception it already had for the model when that alone gives the wanted verdict, or gains one when it does not. It is what a tick in the panel's checklist writes.
AN EXPLICIT LIST MAY NOT BE EMPTIED. `a, b` less both is not a rule the grammar can spell — an empty rule reads as `all`, which is the opposite of what unticking the last model means — so the second answer is false and the rule comes back as it was.
type Base ¶
type Base string
Base is the first word of a rule: what is allowed before any `+x` or `-x`.
type Candidate ¶
Candidate is a model the person allows, with every route a connected provider offers it on, the caller's preferred route first.
type Canon ¶
Canon is a model's canonical identity: the id evidence is kept under, and the quantisation variant when the id names a squeezed local copy of it.
func CanonicalOf ¶
CanonicalOf reads one id as the model it names — see the file comment for the rules, in order.
type Class ¶
type Class string
Class is the kind of work a task is. It is a string because it is written into the router's event log and onto a task's card, and a script reading either reads the word.
const ( // Bugfix is a NARROW, VERIFIABLE change: a defect, a regression, a missing // check, a test that should exist. It goes to the cheapest qualified crew. Bugfix Class = "bugfix" // OpenEnded is work whose shape the task does not fix: a feature, a // refactor, documentation, a design. It gets a strong checker: the checker // is the seat worth paying for here. OpenEnded Class = "openended" // Other is work that changes nothing in particular — a question, an // investigation, a review. It is read on the average of the other two // classes' links, because the weights carry none of its own. Other Class = "other" )
type Decision ¶
type Decision struct {
Class Class
Why string
Sure bool
Effort Effort
Steps int
// Lambda is the price of a quality point the crew was picked at.
Lambda float64
Crew []Pick
// EstUSD is the crew's estimated cost for an ordinary task of its class.
EstUSD float64
Quality float64
// OneOff is a stronger redo of a crew whose every seat was pinned: the
// pins were stepped over for this one run and are unchanged.
OneOff bool
// Considered is how many candidates the decision chose among.
Considered int
// Ladder is, for each unpinned seat, where the seat goes when its call
// fails to start, in order: the same model on its next routes, then the
// next qualified models at a similar cost. The caller adds what only it
// knows — the last crew that worked, the model the person is talking to.
Ladder map[Seat][]Pick `json:"-"`
// Retried are the seats that moved down their ladder during the task, in
// the order they moved, so the line can say so.
Retried []Retry `json:",omitempty"`
// Rungs are what a redo or an effort word changed against the crew it
// would otherwise have run, seat by seat.
Rungs []Retry `json:",omitempty"`
// Note is one plain sentence the line ends on: an effort word that changed
// nothing, or the free routes taken because nothing paid could be.
Note string `json:",omitempty"`
// Stopped is the one action a task stopped on when a seat had nowhere
// left to go and the failure said why — credit, a key, a limit. The line
// leads with it and offers no stronger redo, which could not help.
Stopped string `json:",omitempty"`
// Redo is whether this crew was asked for by a redo of a task that ran
// before. Its own acceptance is the redo's, not a later task's: it must
// not take back the step the redo just taught.
Redo bool `json:",omitempty"`
// Subclass is, for a bugfix, "complex" or "simple" ([complexFix]), with
// Reach the signals that made it complex. The log keeps it; every line a
// person reads still says bugfix.
Subclass string `json:",omitempty"`
Reach string `json:",omitempty"`
// CostFactor is what this install's own tasks of the class have cost
// against their estimates ([router.CrewLog.CostFactor]); EstUSD carries
// it. Zero is none learned yet.
CostFactor float64 `json:",omitempty"`
}
Decision is one task's crew.
func (Decision) Line ¶
Line is the one line a task card and a headless run's summary print:
bugfix · worker glm-5.3-flash (openrouter) · checker glm-5.3-flash · $0.021 (est $0.023)
pinMark is drawn in front of a pinned seat's model; the chat surface hands its own glyph, and a headless door hands none, so the seat says `(pinned)` in words a script and a plain terminal both read. actual below zero is not known yet, and the line then ends on the estimate alone (the emptiness law: an unknown is absent, never $0.00).
type Effort ¶
type Effort string
Effort is the one word about how hard to try this task.
const ( // EffortKnee is the default: the knee of the quality-cost front. EffortKnee Effort = "" // EffortBest buys the most quality the weights believe in, whatever it // costs (λ → 0, ties to the cheaper). EffortBest Effort = "best" // EffortCheap buys quality only where it is nearly free. EffortCheap Effort = "cheap" )
func ParseEffort ¶
ParseEffort reads a person's word for effort. Empty is the knee; anything else that is not one of the two words is refused by the caller's own form.
type Gap ¶
Gap is one class of work the allowed models leave without a seat the routing rule requires.
func Gaps ¶
Gaps names what the allowed models cannot cover. Today that is one thing, the seat the routing rule depends on: open-ended work with no strong checker — none credible whose ability reaches the middle the open-ended link is centred on.
A PINNED SEAT IS THE SEAT. A pin always runs, so a pinned checker is the only model the question is asked of: a strong pin leaves no gap however weak the rest of the allowed models are, and a weak pin is a gap however strong they are, said with the pin's name because the pin is what a person would change. pins carry each pinned seat's model as the catalog reads it, or only its id when the catalog does not carry it; a candidate of the same lineage is read in its place, the way [pinned] reads it. An unpinned checker is asked of every model allowed, as before.
type Model ¶
type Model struct {
ID string
Open bool
PromptPrice float64
CompletionPrice float64
CacheReadPrice float64
Intelligence float64
Coding float64
Agentic float64
// ArenaElo is the best design-arena Elo the row publishes, zero for none.
ArenaElo float64
Context int
// Released is when the model was released, the zero time when the row
// does not say.
Released time.Time
// Tools is whether the model takes tool calls. A crew seat is an agent
// loop, so a model that cannot call a tool cannot sit one.
Tools bool
}
Model is a catalog row as the router reads it. Prices are dollars per token, as the catalog publishes them.
type NoCandidateError ¶
type NoCandidateError struct{ Seat Seat }
NoCandidateError is a seat nobody pinned and nothing allowed can sit.
func (NoCandidateError) Error ¶
func (e NoCandidateError) Error() string
type Pick ¶
type Pick struct {
Seat Seat
Model string
Provider string
Send string
Kind RouteKind
Pinned bool
Quality float64
// SD is the standard deviation of Quality under the weights.
SD float64 `json:",omitempty"`
// Learned is the part of Quality this install's own outcomes moved.
Learned float64 `json:",omitempty"`
CostUSD float64
// EstUSD is what this seat is expected to cost the task ([table.classCost]):
// nothing on a plan, a local model or a free pool.
EstUSD float64 `json:",omitempty"`
}
Pick is one seat's answer.
type Pin ¶
Pin is a seat the person fixed. Model is the id they wrote, Provider the route they pinned when they wrote `model@provider`, and Send and Kind the route the caller resolved for it.
type ProvidersOff ¶
ProvidersOff is the set of provider ids a person turned off, lower case. The zero value is every provider on.
func (ProvidersOff) Candidates ¶
func (off ProvidersOff) Candidates(candidates []Candidate) []Candidate
Candidates is the candidates with the routes of every provider that is off taken away, and every candidate left with no route dropped. The route order each candidate came with — plans and local first, the default service last — is kept, because it is the order a tie between routes of equal cost is broken in, and a filter is no reason to break it differently.
func (ProvidersOff) On ¶
func (off ProvidersOff) On(provider string) bool
On says whether a provider's routes may be used.
func (ProvidersOff) Routes ¶
func (off ProvidersOff) Routes(routes []Route) []Route
Routes is the routes a provider that is on carries, in their own order.
type Reading ¶
type Reading struct {
Class Class
Why string
Sure bool
// Complex is, for a bugfix, the signals that make it a fix with reach
// ([complexFix]), in words; empty is a simple fix. It names no class of
// its own — the task is still a bugfix on every line a person reads — and
// it moves only the worker ([Decide]).
Complex string
}
Reading is the classifier's answer: the class, the one line saying which signal decided it, and whether the signals were clear. Sure false is the uncertain case, which always reads OpenEnded.
type Request ¶
type Request struct {
Task Task
// Class, when set, is taken as given and the classifier is not asked — a
// replay, or a caller that already knows.
Class Class
// Reading, when set, is the classifier's whole answer as the caller
// already read it — the class, why, how sure, and a fix's reach — and is
// taken as it stands. A caller that classifies first to key its learned
// offset hands the reading on here rather than the class alone, which
// dropped the reach and ran every complex fix on the simple fix's worker.
Reading *Reading
// Candidates are the allowed models reachable on a connected provider.
Candidates []Candidate
// Pins are the seats the person fixed. A pinned seat always runs its pin.
Pins map[Seat]Pin
Effort Effort
// Steps is how many escalation steps above the knee to start: the learned
// offset for this repository and class, which decays as tasks are accepted.
Steps int
// Pace multiplies λ as a daily cap is approached ([Pace]); zero is one.
Pace float64
// Stronger is the crew that ran, when the person asked to redo the task
// stronger: every unpinned seat is picked at least as strong, and the crew
// as a whole strictly stronger, or the decision says it cannot be.
Stronger *Decision
// Again is the crew that ran and NEVER STARTED — its seats' first calls
// were refused — when the person asks to redo it: the task never ran, so it
// is asked again at the same λ on the next-best models, not escalated.
Again *Decision
// Avoid are model lineages that failed to start on this install recently
// ([Lineage]). An unpinned seat is not given one while anything else can
// sit it; a pin is never overruled.
Avoid map[string]bool
// Learned is this install's move to a model's quality in a seat, by
// [LearnKey]: what its tasks kept or redid there ([router.CrewLog]).
Learned map[string]float64
// TaskCap is the most one task may be estimated to cost; zero is none. A
// crew estimated over it is not chosen, whatever the effort word.
TaskCap float64
// CostFactor is this install's learned ratio of what its tasks of the
// class cost to their estimates; zero is none learned.
CostFactor float64
// Rescue is a seat's LAST RUNG being picked — the free pools when nothing
// paid can be reached — rather than a crew being chosen: any model that
// can sit the seat (tools, context, a route) is taken, best first, though
// it publishes too little for the router to trust it as a first pick. A
// seat that runs on a thinly described model says so on its line; a seat
// that does not run at all says nothing useful.
Rescue bool
}
Request is everything one decision reads.
type Retry ¶
Retry is one seat moved from one model to another — down its ladder during a task, or up a rung on a redo — and why, when a failure moved it.
type Route ¶
type Route struct {
Provider string
Send string
Kind RouteKind
// FailRate is this install's learned chance that the route refuses a
// task's first call, zero when nothing is known — a free route then reads
// [freeFailPrior].
FailRate float64
}
Route is one way to reach a model: the provider, the id to send so the call goes that way, and how it bills.
type RouteKind ¶
type RouteKind string
RouteKind is how a route bills.
const ( // Metered is billed per token at the model's published prices. Metered RouteKind = "metered" // Plan is a subscription login — a coding plan, a ChatGPT account — whose // marginal cost for one more task is taken as zero. Plan RouteKind = "plan" // Local is a model on this machine, which costs nothing per token. Local RouteKind = "local" // Free is a provider's free pool for a model (OpenRouter's `:free`): no // price, but rate-limited hard, dropped without notice, and allowed to log // or train on what it is sent. It is weighed at what it is EXPECTED to cost // ([routeCost]), used only when the person turned free routes on, and a // seat on it falls through to the same model's paid route first. Free RouteKind = "free" )
type Scored ¶
type Scored struct {
Model string `json:"m"`
Provider string `json:"p,omitempty"`
Kind RouteKind `json:"k,omitempty"`
Quality float64 `json:"q"`
CostUSD float64 `json:"c"`
Score float64 `json:"s"`
}
Scored is one candidate as a seat weighed it: the model, the route it would ride, its quality and cost as the router read them, and the score (quality − λ·cost) it was ranked by.