crewroute

package
v0.6.1-rc.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 4, 2026 License: Apache-2.0 Imports: 12 Imported by: 0

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

View Source
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.

View Source
const DefaultAllowed = "all"

DefaultAllowed is the rule a profile that never answered reads.

View Source
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

View Source
var Classes = []Class{Bugfix, OpenEnded, Other}
View Source
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.

Seats lists the three in the order a crew is read out.

Functions

func Canonical

func Canonical(id string) string

Canonical is the id a model's evidence is kept under, across every provider's spelling of it (CanonicalOf without the variant).

func DomainTuned

func DomainTuned(id string) bool

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 IsFree

func IsFree(id string) bool

IsFree is whether an id names a free, rate-limited route (`…:free`).

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

func LearnKey(class Class, seat Seat, model string) string

LearnKey is the key a learned quality move is kept under: the class, the seat and the model's lineage.

func Lineage

func Lineage(id string) string

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

func Money(usd float64) string

Money spells a task's dollars: three places under a dollar, where the difference between routed crews lives, and two above it.

func Names

func Names(candidates []Candidate) []string

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

func Pace(spent, cap float64) (multiplier float64, atCap bool)

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

func Scorable(m Model) bool

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

func Seatable(seat Seat, c Candidate) bool

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

func ShortModel(id string) string

ShortModel is a model id without its vendor: the half a person reads.

func Tiny

func Tiny(id string) bool

Tiny is whether a model's own id gives it fewer parameters than a crew seat can use — `lfm-2.5-2.6b`, `gemma-3n-e4b` — read off the largest size tag in its name (`30b-a3b` is thirty billion, three active). A name that gives no size is not called tiny.

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

func ParseAllowed(raw string) (Allowed, error)

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

func (a Allowed) AdmitsModel(m Model) bool

AdmitsModel says whether the rule allows a model, before routes are asked.

func (Allowed) AdmitsRoute

func (a Allowed) AdmitsRoute(provider string) bool

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

func (a Allowed) Custom() bool

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

func (a Allowed) NamesModel(id string) bool

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

func (a Allowed) Rebased(base Base, maxIn, maxOut float64) Allowed

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

func (a Allowed) RouteToggled(provider string, admit bool) Allowed

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

func (a Allowed) String() string

String writes the rule back in its canonical spelling, which is what the panel shows and what is stored.

func (Allowed) Toggled

func (a Allowed) Toggled(m Model, admit bool) (Allowed, bool)

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.

func (Allowed) With

func (a Allowed) With(add bool, word string) Allowed

With is the rule with one more `+x` or `-x` on its end — what `/crew models +x` writes. A word the rule already carries with the same sign is not written twice, and the same word with the other sign is replaced, so the rule stays the shortest spelling of what the person meant.

func (Allowed) Without

func (a Allowed) Without(word string) Allowed

Without is the rule with every `+x` or `-x` naming word taken off, which hands that word's verdict back to the base.

type Base

type Base string

Base is the first word of a rule: what is allowed before any `+x` or `-x`.

const (
	BaseAll   Base = "all"
	BaseOpen  Base = "open"
	BasePrice Base = "price"
	BaseList  Base = "list"
)

type Candidate

type Candidate struct {
	Model  Model
	Routes []Route
}

Candidate is a model the person allows, with every route a connected provider offers it on, the caller's preferred route first.

type Canon

type Canon struct {
	ID      string
	Variant string
}

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

func CanonicalOf(id string) Canon

CanonicalOf reads one id as the model it names — see the file comment for the rules, in order.

func (Canon) String

func (c Canon) String() string

String is the identity as one key: the id, and the variant after `@` when there is one — so a quantised copy is never the model it came from.

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"
)

func (Class) Word

func (c Class) Word() string

Classes lists the three, in the order a report prints them. Word is the class as a person reads it: `open-ended` rather than the logged `openended`, which stays the key the router's log and the evidence table are written in.

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 Decide

func Decide(r Request) (Decision, error)

Decide picks the crew for one task.

func (Decision) Line

func (d Decision) Line(pinMark string, actual float64) string

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).

func (Decision) Seat

func (d Decision) Seat(seat Seat) Pick

Seat is one seat's pick, the zero Pick for a seat the decision has none for.

func (Decision) WithRung

func (d Decision) WithRung(seat Seat, next Pick, why string) Decision

WithRung is the decision with one seat moved to another pick for the rest of the task — a rung of its ladder, or one the caller found — the estimate re-added and the move recorded, with why, for the line.

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

func ParseEffort(word string) (Effort, bool)

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

type Gap struct {
	Class Class
	Seat  Seat
	Line  string
}

Gap is one class of work the allowed models leave without a seat the routing rule requires.

func Gaps

func Gaps(candidates []Candidate, pins map[Seat]Model) []Gap

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 Mod

type Mod struct {
	Add  bool
	Word string
}

Mod is one `+x` or `-x`.

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

type Pin struct {
	Model    string
	Provider string
	Send     string
	Kind     RouteKind
}

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

type ProvidersOff map[string]bool

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.

func Classify

func Classify(task Task) Reading

Classify reads a task's class. It is pure and allocation-light: the rules are compiled once at load, and a task is read in a single pass per rule.

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

type Retry struct {
	Seat Seat
	From string
	To   string
	Why  string `json:",omitempty"`
}

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.

type Seat

type Seat string

Seat is one of the crew's three seats, by the name a person reads.

const (
	// Worker does the work: the leaves of a task, every tool turn of it.
	Worker Seat = "worker"
	// Planner cuts the work into pieces and steers the run.
	Planner Seat = "planner"
	// Checker reads finished work against what it was supposed to do.
	Checker Seat = "checker"
)

type Task

type Task struct {
	Text   string
	Labels []string
}

Task is what the classifier reads: the words a person or an issue gave the work, and the labels the issue carried when it came from a tracker.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL