pub struct BudgetManager { /* private fields */ }Expand description
Manages budgets for all agents with sliding window reset semantics.
Implementations§
Source§impl BudgetManager
impl BudgetManager
Sourcepub fn set_budget(&self, limit: BudgetLimit)
pub fn set_budget(&self, limit: BudgetLimit)
Sets or updates the budget for an agent.
Sourcepub fn remove_budget(&self, agent_id: &AgentId)
pub fn remove_budget(&self, agent_id: &AgentId)
Removes the budget for an agent.
Sourcepub fn reserve(
&self,
agent_id: &AgentId,
tokens: u64,
) -> Result<(), BudgetExceeded>
pub fn reserve( &self, agent_id: &AgentId, tokens: u64, ) -> Result<(), BudgetExceeded>
Attempts to reserve tokens for an agent.
Returns Ok(()) if the tokens can be reserved.
Returns Err(BudgetExceeded) if the agent has exceeded its token budget.
The usage window is automatically reset if it has expired.
Sourcepub fn release(&self, agent_id: &AgentId, tokens_used: u64)
pub fn release(&self, agent_id: &AgentId, tokens_used: u64)
Releases tokens back (e.g., on retry or error).
Tokens are subtracted from usage. Does not allow negative usage.
Sourcepub fn track_call(&self, agent_id: &AgentId) -> Result<(), BudgetExceeded>
pub fn track_call(&self, agent_id: &AgentId) -> Result<(), BudgetExceeded>
Tracks a call for an agent.
Returns Err(BudgetExceeded) if the call limit has been exceeded.
Sourcepub fn remaining(&self, agent_id: &AgentId) -> BudgetInfo
pub fn remaining(&self, agent_id: &AgentId) -> BudgetInfo
Returns current budget information for an agent.
Sourcepub fn can_schedule(&self, agent_id: &AgentId) -> bool
pub fn can_schedule(&self, agent_id: &AgentId) -> bool
Returns true if an agent can be scheduled (has budget remaining).
Sourcepub fn reset_window(&self, agent_id: &AgentId)
pub fn reset_window(&self, agent_id: &AgentId)
Manually resets the usage window for an agent.
Sourcepub fn full_info(&self, agent_id: &AgentId) -> Option<FullBudgetInfo>
pub fn full_info(&self, agent_id: &AgentId) -> Option<FullBudgetInfo>
Returns full budget information including limits and usage for an agent.
Returns None if no budget is configured for the agent.
Sourcepub fn all_full_info(&self) -> Vec<FullBudgetInfo>
pub fn all_full_info(&self) -> Vec<FullBudgetInfo>
Returns full budget info for all agents with configured budgets.