Documentation
¶
Overview ¶
Package policy decides the tier for a step: escalation on a repeated tool failure, holds, votes with hysteresis, cost-gated upgrade and downgrade bars, and the context-fit tier search. Pure: Input in, Result (with the next State) out. Ported from claude-model-router lib/policy.mjs with taxes in uncached tokens.
Index ¶
- Constants
- func FitTier(tier config.Tier, tokens int, window func(config.Tier) (int, bool), ...) (config.Tier, bool)
- func SameTask(p config.Policy, a *classifier.Advice, midTurn bool) bool
- func UpgradeBar(p config.Policy, tax int) float64
- type Estimate
- type Input
- type Reason
- type Result
- type State
- type Vote
Constants ¶
const VotesKept = 3
VotesKept is how many trailing votes a State remembers.
Variables ¶
This section is empty.
Functions ¶
func FitTier ¶
func FitTier(tier config.Tier, tokens int, window func(config.Tier) (int, bool), fill float64) (config.Tier, bool)
FitTier returns the lowest tier at or above tier whose window holds tokens at fill. Routes need not grow in window with rank, so the search falls back to any tier that fits from the bottom. When none fits it returns the tier with the largest known window (tier itself on a tie or when no window is known) and false. An unknown window never fits.
Types ¶
type Estimate ¶
Estimate explains a switch bar: the tax it priced, the bar, the support and the vote streak.
type Input ¶
type Input struct {
Policy config.Policy
Baseline config.Tier
Incumbent config.Tier
Advice *classifier.Advice
FailureSignature string
MidTurn bool
DownAllowed bool
Fresh bool
State State
TaxTokens func(candidate config.Tier) int
Escalate func(incumbent config.Tier) (config.Tier, bool)
}
Input is one decision's facts. TaxTokens prices a candidate tier's next request in uncached tokens; Escalate names the tier a repeated failure moves to, or false when none helps.
type Reason ¶
type Reason string
Reason names why a decision landed where it did.
const ( ReasonEscalation Reason = "escalation" ReasonHold Reason = "hold" ReasonNoAdvice Reason = "no-advice" ReasonUncertain Reason = "uncertain" ReasonSameTier Reason = "same-tier" ReasonUpgrade Reason = "upgrade" ReasonJump Reason = "jump" ReasonUpgradePending Reason = "upgrade-pending" ReasonDowngrade Reason = "downgrade" ReasonDowngradeHeld Reason = "downgrade-held" ReasonDowngradePending Reason = "downgrade-pending" ReasonPinned Reason = "pinned" ReasonPaused Reason = "paused" ReasonManual Reason = "manual" ReasonFit Reason = "fit" ReasonOutOfGroup Reason = "out-of-group" ReasonPassthrough Reason = "passthrough" ReasonError Reason = "error" )
type Result ¶
Result is the decided tier with its reason, the next State and the estimate behind a bar, when one was priced.
func Decide ¶
Decide returns the tier for one step. The incumbent is in.Incumbent, or in.Baseline when that is not a tier. A repeated failure signature escalates once per signature and holds; otherwise the advice votes, and a switch must clear a bar that rises with the candidate's tax. A cheaper tier on the same task also waits for in.DownAllowed.
Unlike the Claude router there is no cash gate: Codex bills the plan's limits, and a downgrade tax has no later-turn savings in tokens, so the downgrade bar prices only the next request.