pub struct AgentTokenBudget { /* private fields */ }Expand description
Agent token budget
AI agents get token budgets instead of simple rate limits. This allows for burst operations while enforcing daily/hourly limits.
Implementations§
Source§impl AgentTokenBudget
impl AgentTokenBudget
Sourcepub fn hourly(agent_id: impl Into<String>, tokens: u64) -> Self
pub fn hourly(agent_id: impl Into<String>, tokens: u64) -> Self
Create a new hourly token budget
Sourcepub fn new(agent_id: impl Into<String>, tokens: u64, period: Duration) -> Self
pub fn new(agent_id: impl Into<String>, tokens: u64, period: Duration) -> Self
Create a new token budget with custom period
Sourcepub fn with_warning_threshold(self, threshold: f64) -> Self
pub fn with_warning_threshold(self, threshold: f64) -> Self
Set warning threshold (0.0 - 1.0)
Sourcepub fn with_hard_limit(self, hard: bool) -> Self
pub fn with_hard_limit(self, hard: bool) -> Self
Set hard limit behavior
Sourcepub fn with_operation_costs(self, costs: HashMap<String, u64>) -> Self
pub fn with_operation_costs(self, costs: HashMap<String, u64>) -> Self
Set operation costs
Sourcepub fn add_operation_cost(&mut self, operation: impl Into<String>, cost: u64)
pub fn add_operation_cost(&mut self, operation: impl Into<String>, cost: u64)
Add operation cost
Sourcepub fn consume(
&self,
operation: &str,
estimated_tokens: u64,
) -> Result<(), BudgetExceeded>
pub fn consume( &self, operation: &str, estimated_tokens: u64, ) -> Result<(), BudgetExceeded>
Consume tokens for an operation
Sourcepub fn check(
&self,
operation: &str,
estimated_tokens: u64,
) -> Result<(), BudgetExceeded>
pub fn check( &self, operation: &str, estimated_tokens: u64, ) -> Result<(), BudgetExceeded>
Check if budget is available (without consuming)
Sourcepub fn usage_percentage(&self) -> f64
pub fn usage_percentage(&self) -> f64
Get usage percentage (0.0 - 1.0)
Sourcepub fn is_warning(&self) -> bool
pub fn is_warning(&self) -> bool
Check if over warning threshold
Sourcepub fn time_until_reset(&self) -> Duration
pub fn time_until_reset(&self) -> Duration
Get time until reset
Trait Implementations§
Source§impl Clone for AgentTokenBudget
impl Clone for AgentTokenBudget
Auto Trait Implementations§
impl !Freeze for AgentTokenBudget
impl !RefUnwindSafe for AgentTokenBudget
impl Send for AgentTokenBudget
impl Sync for AgentTokenBudget
impl Unpin for AgentTokenBudget
impl UnsafeUnpin for AgentTokenBudget
impl UnwindSafe for AgentTokenBudget
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more