Documentation
¶
Overview ¶
Package budget enforces the hard caps of a run: tokens, spend, wall time, sandbox runs and agent turns. Caps are mandatory. There is no "unlimited": an agent loop with no ceiling is how a run costs more than the operator meant to spend.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrExhausted = errors.New("budget exhausted")
ErrExhausted is returned (wrapped, naming the cap) when a cap is reached.
Functions ¶
This section is empty.
Types ¶
type Budget ¶
type Budget struct {
// contains filtered or unexported fields
}
Budget tracks spend against caps. It is safe for concurrent use.
func (*Budget) CanAfford ¶
CanAfford reports whether a call estimated at the given size fits in what is left. It lets the engine skip a task it could not finish instead of starting it and cutting it off.
func (*Budget) Check ¶
Check returns nil while the run may make another model call, and an error wrapping ErrExhausted that names the cap otherwise.
func (*Budget) UseSandbox ¶
UseSandbox reserves one sandbox run, or reports that the cap is reached.
type Spent ¶
type Spent struct {
InputTokens int
OutputTokens int
USD float64
SandboxRuns int
ModelCalls int
Elapsed time.Duration
// CostUnknown is true when any call used a model with no known price,
// which means the USD cap could not be enforced for that call.
CostUnknown bool
}
Spent is how much of the budget has been used.
type Stagnation ¶
type Stagnation struct {
// contains filtered or unexported fields
}
Stagnation detects an agent that has stopped making progress: it keeps issuing tool calls it has already made. It is deliberately simple and counts exact repeats, which is how a stuck model actually behaves.
func NewStagnation ¶
func NewStagnation(limit int) *Stagnation
NewStagnation returns a detector that trips after limit repeated calls.
func (*Stagnation) Observe ¶
func (s *Stagnation) Observe(name, args string) (repeat bool)
Observe records a tool call (name plus raw arguments) and reports whether it repeats an earlier one.
func (*Stagnation) Stuck ¶
func (s *Stagnation) Stuck() bool
Stuck reports whether the repeat limit has been reached.