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.
A glob is read with forward slashes, and from the project root without a leading "./", as the paths it is matched against already are: one written the way Windows writes a path, "db\migrations\**", or "./migrations/**", matched nothing at all and said nothing about it.
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
// Agent is the agent the work moves to, and empty when it stays on the
// one it was going to run on. Set only by a rule naming a model of
// another agent, and only when Input.OtherAgent allowed it.
Agent string
// 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 would run on without routing. A rule may
// still move it to another agent -- see OtherAgent -- but routing never
// does that on its own: 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
// OtherAgent resolves an agent id to its Spec, but only when work could
// be handed to it here and now: installed or keyed, trusted for the
// project, and, for an endpoint of its own, answering. It is the
// caller's to supply, because deciding stays pure and does no I/O of its
// own. Nil means work is never moved to another agent, whatever a rule
// asks for -- which is also true for any Kind other than KindFanout and
// KindSpawn, and for a policy whose CrossAgent is off: a running
// conversation cannot change agent under it, and a switch nobody turned
// on for this project is not one routing takes on its own.
OtherAgent func(id string) (agent.Spec, 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 is the agent the work ran on, as it always has been. BaselineAgent
// is the agent it would have run on without routing, and is left empty
// unless a rule moved the work to another agent -- so an old log line,
// and every same-agent decision since, still reads as it always has.
Agent string `json:"agent,omitempty"`
BaselineAgent string `json:"baselineAgent,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.