Documentation
¶
Overview ¶
Package route decides which model a piece of work runs on, from rules the user can read and edit in agents.json.
Deciding is pure: it reads no file and makes no request. It is given the policy, the task, and the agent and model the work would run on without it, and answers with a model and a sentence saying why. The caller shows that before the work starts -- a fan-out row's select is pre-set to it, and the user confirms -- so a choice shown is the choice run. The one thing here that touches the disk is the routing log (log.go), which holds rule names and model ids and never the task.
Index ¶
- Constants
- func AppendLog(dir string, entries ...LogEntry) error
- func BuiltinRules() []agent.RoutingRule
- func ClearLog(dir string) error
- func MatchGlob(glob, name string) bool
- func RulesOf(p agent.RoutingPolicy) []agent.RoutingRule
- func TierOf(spec agent.Spec, model string) int
- type Decision
- type Input
- type LogEntry
- type Router
Constants ¶
const ( OutcomeKept = "kept" OutcomeOverridden = "overridden:" )
Outcomes a decision can have.
const ( KindFanout = "fanout" KindSpawn = "spawn" KindTurn = "turn" )
The kinds of work a rule's "kind" can name.
const LogName = "routing.jsonl"
LogName is the routing log, in Flockdeck's state directory.
It is how the user, and later the spend view, can tell whether routing saves anything and how often its choices are overridden. It stays on this machine: nothing reads it but Flockdeck, on the user's behalf, and Settings clears it. It holds no task text and no prompt -- only the name of the rule that chose -- because the task is already in the user's own transcripts, and a log of prompts would be one more copy of them to leak.
const SourceRule = "rule"
SourceRule is the Source of a decision a rule made.
Variables ¶
This section is empty.
Functions ¶
func BuiltinRules ¶
func BuiltinRules() []agent.RoutingRule
BuiltinRules are the rules a policy that names none of its own applies.
They are deliberately timid. They move clearly mechanical work down and clearly hard work up, and leave everything else exactly where it would have been: a rule set that routes a third of a typical fan-out is doing well, and one that routes everything is a bug. The rules for hard work come first, because the first rule to match wins, and a task that reads as both -- "move the session store behind a lock to fix the race" -- is the one a cheap attempt would cost most to get wrong.
func MatchGlob ¶
MatchGlob matches a path against a glob: path.Match for each part, with "**" standing for any number of directories. A glob with no slash in it is matched against the path's last part, so "*.sql" finds db/0003.sql as well as 0003.sql. Case is not compared, since the same path is written both ways on Windows and macOS.
func RulesOf ¶
func RulesOf(p agent.RoutingPolicy) []agent.RoutingRule
RulesOf is the rules a policy applies: its own, or the built-in ones when it names none. An empty list is a policy that deliberately has no rules.
Types ¶
type Decision ¶
type Decision struct {
// Model is the model to run, and Tier its tier; both are empty, and
// Routed false, when the work is left alone.
Model string
Tier string
Routed bool
// Up says the work was moved to a stronger model than it would have had.
Up bool
// Source is what chose (SourceRule), and Rule the rule's name.
Source string
Rule string
// Reason is one line a person reads: why the model was chosen, or why a
// rule that matched changed nothing.
Reason string
}
Decision is what routing made of one piece of work.
type Input ¶
type Input struct {
Kind string // KindFanout, KindSpawn or KindTurn
Task string // the row, the spawn task, or the prompt
// Agent is the agent the work will run on. Routing never changes it:
// another agent is another login, other tools and another transcript,
// which is far more than a model.
Agent agent.Spec
// Current is the model the work would get without routing.
Current string
// NoDowngrade says the work may only be moved to a stronger model.
NoDowngrade bool
}
Input is one piece of work to decide a model for.
type LogEntry ¶
type LogEntry struct {
At time.Time `json:"at"`
Kind string `json:"kind"`
Project string `json:"project,omitempty"`
Pane string `json:"pane,omitempty"`
Agent string `json:"agent,omitempty"`
Source string `json:"source"`
Rule string `json:"rule,omitempty"`
// Baseline is the model the work would have run without routing, and
// Routed the model routing chose for it.
Baseline string `json:"baseline"`
Routed string `json:"routed"`
// Outcome is what became of the choice: "kept", or "overridden:<model>"
// when the user chose another before it started.
Outcome string `json:"outcome"`
}
LogEntry is one decision, as the log records it.
type Router ¶
type Router struct {
// contains filtered or unexported fields
}
Router is a policy made ready to decide with: its rules compiled once, for a fan-out that asks about a dozen rows at a time.
func New ¶
func New(p agent.RoutingPolicy) *Router
New makes a Router of a policy. A rule that cannot be used -- a pattern that does not compile, a tier that is not one -- is left out; the catalog has already named it in its notice when agents.json was read.