Documentation
¶
Overview ¶
Package estimate answers "what will the next `orch run` cost" before it starts (#357): which tasks it would dispatch, what they would cost and how long they would take, from this project's own past attempts.
Pure: everything it reads is an argument, so `orch estimate`, the line `orch run` prints and the dashboard's /api/estimate are the same function.
Index ¶
Constants ¶
const ( // MinSample is the fewest tasks a route needs, on both sides of a // comparison, before anything is suggested. MinSample = 5 // SuccessMargin is how far first-try success may differ and still count // as equal; a stronger route must beat the current one by more. SuccessMargin = 0.05 )
`orch router suggest` (#457): per kind of task, how each route it ran on did — first-try success, attempts, cost and time — and, where the numbers are clear, which route the kind should run on instead. Plain statistics over this project's own spend rows and outcome events; no model is asked.
A kind is the task's route key (its `model` in tasks.json): that is what a suggestion can change, by pointing the key at another backend and CLI model in model_router.yaml.
const (
DefaultDuration = 10 * time.Minute
)
With no history at all an attempt is assumed to take config.yaml's typical_dispatch_tokens of input (Input.TypicalTokens), a twentieth of that as output, and DefaultDuration.
Variables ¶
This section is empty.
Functions ¶
func PromoteCommand ¶ added in v0.31.0
PromoteCommand is the shell command that moves ids to todo: `orch task set` for one, a loop over it for several.
Types ¶
type Estimate ¶
type Estimate struct {
Tasks []string `json:"tasks"`
CostUSD float64 `json:"cost_usd"`
ByBackend map[string]float64 `json:"cost_by_backend"`
// WallS is max(critical path, total agent time / slots).
WallS float64 `json:"wall_s"`
CriticalPathS float64 `json:"critical_path_s"`
Slots int `json:"slots"`
// PastAttempts is how many finished attempts the numbers come from;
// AttemptsPerTask is the project's observed retry multiplier.
PastAttempts int `json:"past_attempts"`
AttemptsPerTask float64 `json:"attempts_per_task"`
// Confidence is "none" (no history: defaults), "low", "medium" or "high".
Confidence string `json:"confidence"`
// Backlog is the selection's tasks in backlog, which a run never
// dispatches until they are promoted to todo (#579), in dispatch order.
Backlog []string `json:"backlog"`
}
Estimate is the answer. Durations are seconds, money is USD.
func (Estimate) BacklogNote ¶ added in v0.31.0
BacklogNote says how many of the selection's tasks wait in backlog and the command that promotes them, or "" when none does (#579). Lines carries it only when nothing else would run: beside work that runs, backlog is the operator's choice.
type Input ¶
type Input struct {
// Tasks carry their runtime status (project.Hydrate / the queue's view).
Tasks []model.Task
Routes router.Router
// Spend is every finished attempt in this project (state.Backend.AllSpend).
Spend []state.Spend
Prices pricing.Table
// Slots is concurrency.global_max; less than 1 counts as 1.
Slots int
// Only and MaxTasks are `orch run`'s flags, with the same meaning.
Only string
MaxTasks int
// TypicalTokens is config.yaml's typical_dispatch_tokens, the no-history
// guess for an attempt's input.
TypicalTokens int
}
Input is everything an estimate reads.
type KindRoutes ¶
type KindRoutes struct {
Kind string `json:"kind"`
// Current is the route the router gives the kind now; "" when it has none.
Current string `json:"current"`
Routes []RouteRecord `json:"routes"`
Suggestion *Suggestion `json:"suggestion"`
}
KindRoutes is one kind's routes, most tasks first, and its suggestion.
func SuggestRoutes ¶
func SuggestRoutes(in SuggestInput) []KindRoutes
SuggestRoutes is the per-kind table, sorted by kind.
type RouteRecord ¶
type RouteRecord struct {
// Route is `backend/cli_model`, what the attempts actually ran on.
Route string `json:"route"`
Current bool `json:"current"`
// Tasks is how many tasks had their first attempt here; FirstTry is the
// share of them that succeeded on it, MeanAttempts their attempts.
Tasks int `json:"tasks"`
FirstTry float64 `json:"first_try_rate"`
MeanAttempts float64 `json:"mean_attempts"`
// Attempts is every attempt on this route, the sample the means below
// come from. A row with no cost to resolve is left out of the cost.
Attempts int `json:"attempts"`
MeanCostUSD float64 `json:"mean_cost_usd"`
MeanDurationS float64 `json:"mean_duration_s"`
}
RouteRecord is one route's record on one kind of task.
type SuggestInput ¶
type SuggestInput struct {
// Tasks give each task's kind (its route key).
Tasks []model.Task
Routes router.Router
// Spend is the window's attempts (state.Backend.AllSpend), oldest first.
Spend []state.Spend
// Events are the outcome events; only `success` is read.
Events []state.Event
Prices pricing.Table
}
SuggestInput is everything SuggestRoutes reads.
type Suggestion ¶
type Suggestion struct {
Key string `json:"key"`
From string `json:"from"`
To string `json:"to"`
// Why is "cheaper" or "stronger"; Reason says it in a sentence.
Why string `json:"why"`
ToBackend model.Backend `json:"to_backend"`
ToCLIModel string `json:"to_cli_model"`
Reason string `json:"reason"`
SuccessFrom float64 `json:"first_try_from"`
SuccessTo float64 `json:"first_try_to"`
}
Suggestion points a route key at another route.