Documentation
¶
Overview ¶
Package budget provides iteration budget management for long-running tasks. Inspired by Hermes Agent's IterationBudget, this package prevents infinite loops and provides fine-grained control over agent execution iterations.
Index ¶
- Constants
- type Budget
- func (b *Budget) Consume() bool
- func (b *Budget) ConsumeN(n int) int
- func (b *Budget) GetStats() Stats
- func (b *Budget) IsExhausted() bool
- func (b *Budget) MaxTotal() int
- func (b *Budget) Refund()
- func (b *Budget) RefundN(n int)
- func (b *Budget) Remaining() int
- func (b *Budget) UsagePercent() float64
- func (b *Budget) Used() int
- type Manager
- type Stats
Constants ¶
const ( // DefaultMaxIterations for parent agents DefaultMaxIterations = 90 // DefaultSubagentMaxIterations for subagents DefaultSubagentMaxIterations = 50 // DefaultSimpleTaskMaxIterations for simple tasks DefaultSimpleTaskMaxIterations = 30 // DefaultComplexTaskMaxIterations for complex tasks DefaultComplexTaskMaxIterations = 150 )
Default budget configurations
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Budget ¶
type Budget struct {
// contains filtered or unexported fields
}
Budget tracks iteration consumption for an agent or subagent. Each agent gets its own Budget instance to prevent resource exhaustion.
func New ¶
New creates a new Budget with the specified maximum iterations. Parent agents typically use maxIterations (default 90), subagents use delegation.maxIterations (default 50).
func (*Budget) Consume ¶
Consume attempts to consume one iteration. Returns true if the iteration was allowed, false if budget is exhausted.
func (*Budget) ConsumeN ¶
ConsumeN attempts to consume N iterations atomically. Returns the number of iterations actually consumed (may be less than N if budget runs out).
func (*Budget) IsExhausted ¶
IsExhausted returns true if the budget is exhausted.
func (*Budget) Refund ¶
func (b *Budget) Refund()
Refund returns one iteration to the budget. Useful for execute_code iterations that shouldn't count against the budget.
func (*Budget) UsagePercent ¶
UsagePercent returns the percentage of budget used (0.0 - 100.0).
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager manages budgets for multiple agents/tasks.
func (*Manager) GetGlobalStats ¶
GetGlobalStats returns aggregated statistics across all budgets.