Class: Mistri::Budget
- Inherits:
-
Object
- Object
- Mistri::Budget
- Defined in:
- lib/mistri/budget.rb
Overview
Optional per-run ceilings: turns, tokens, dollars, wall-clock seconds. Nothing is enforced unless the host sets it; an empty budget never stops a run. Pure limits with no clock of its own, so one Budget shared across agents or runs behaves identically for each: the loop measures and asks between turns, and a run always finishes the turn it is in.
Instance Method Summary collapse
-
#exceeded(turns:, usage:, elapsed: 0) ⇒ Object
The reason the run should stop, or nil to continue.
-
#initialize(turns: nil, tokens: nil, cost_usd: nil, wall_clock: nil) ⇒ Budget
constructor
A new instance of Budget.
- #none? ⇒ Boolean
Constructor Details
#initialize(turns: nil, tokens: nil, cost_usd: nil, wall_clock: nil) ⇒ Budget
Returns a new instance of Budget.
10 11 12 13 14 15 |
# File 'lib/mistri/budget.rb', line 10 def initialize(turns: nil, tokens: nil, cost_usd: nil, wall_clock: nil) @turns = turns @tokens = tokens @cost_usd = cost_usd @wall_clock = wall_clock end |
Instance Method Details
#exceeded(turns:, usage:, elapsed: 0) ⇒ Object
The reason the run should stop, or nil to continue.
20 21 22 23 24 25 26 27 |
# File 'lib/mistri/budget.rb', line 20 def exceeded(turns:, usage:, elapsed: 0) return :turns if @turns && turns >= @turns return :tokens if @tokens && usage.total_tokens >= @tokens return :cost if @cost_usd && usage.cost.total >= @cost_usd return :wall_clock if @wall_clock && elapsed >= @wall_clock nil end |
#none? ⇒ Boolean
17 |
# File 'lib/mistri/budget.rb', line 17 def none? = [@turns, @tokens, @cost_usd, @wall_clock].all?(&:nil?) |