route

package
v0.3.3 Latest Latest
Warning

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

Go to latest
Published: Sep 13, 2026 License: MIT Imports: 13 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

View Source
const (
	OutcomeKept       = "kept"
	OutcomeOverridden = "overridden:"
)

Outcomes a decision can have.

View Source
const (
	KindFanout = "fanout"
	KindSpawn  = "spawn"
	KindTurn   = "turn"
)

The kinds of work a rule's "kind" can name.

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

View Source
const SourceRule = "rule"

SourceRule is the Source of a decision a rule made.

Variables

This section is empty.

Functions

func AppendLog

func AppendLog(dir string, entries ...LogEntry) error

AppendLog adds decisions to the log in dir.

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 ClearLog

func ClearLog(dir string) error

ClearLog deletes the log in dir.

func MatchGlob

func MatchGlob(glob, name string) bool

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.

func TierOf

func TierOf(spec agent.Spec, model string) int

TierOf is the rank of a model among the agent's own, and 0 where the agent does not list it or gives it no tier.

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.

func Decide

func Decide(p agent.RoutingPolicy, in Input) Decision

Decide is New(p).Decide(in), for 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.

func ReadLog

func ReadLog(dir string) ([]LogEntry, error)

ReadLog returns every decision in the log in dir, oldest first. A line that does not parse is passed over: the log is the user's to edit or truncate.

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.

func (*Router) Decide

func (r *Router) Decide(in Input) Decision

Decide applies the rules to one piece of work, in order: the first that matches decides, and no match leaves the work exactly as it was. Then the floor, "never downgrade" and what the agent offers bound what that rule may choose.

func (*Router) On

func (r *Router) On() bool

On reports whether the policy routes anything at all.

Jump to

Keyboard shortcuts

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