pub struct TokenBudgetManager { /* private fields */ }
Expand description
Token budget manager
Implementations§
Source§impl TokenBudgetManager
impl TokenBudgetManager
Sourcepub fn new(config: TokenBudgetConfig) -> Self
pub fn new(config: TokenBudgetConfig) -> Self
Create a new token budget manager
Sourcepub async fn count_tokens(&self, text: &str) -> Result<usize>
pub async fn count_tokens(&self, text: &str) -> Result<usize>
Count tokens in text
Sourcepub async fn count_tokens_for_component(
&self,
text: &str,
component: ContextComponent,
component_id: Option<&str>,
) -> Result<usize>
pub async fn count_tokens_for_component( &self, text: &str, component: ContextComponent, component_id: Option<&str>, ) -> Result<usize>
Count tokens with component tracking
Sourcepub async fn get_stats(&self) -> TokenUsageStats
pub async fn get_stats(&self) -> TokenUsageStats
Get current usage statistics
Sourcepub async fn get_component_breakdown(&self) -> HashMap<String, usize>
pub async fn get_component_breakdown(&self) -> HashMap<String, usize>
Get component-level token breakdown
Sourcepub async fn is_warning_threshold_exceeded(&self) -> bool
pub async fn is_warning_threshold_exceeded(&self) -> bool
Check if warning threshold is exceeded
Sourcepub async fn is_compaction_threshold_exceeded(&self) -> bool
pub async fn is_compaction_threshold_exceeded(&self) -> bool
Check if compaction threshold is exceeded
Sourcepub async fn usage_percentage(&self) -> f64
pub async fn usage_percentage(&self) -> f64
Get current usage percentage
Sourcepub async fn remaining_tokens(&self) -> usize
pub async fn remaining_tokens(&self) -> usize
Get remaining tokens in budget
Sourcepub async fn deduct_tokens(&self, component: ContextComponent, tokens: usize)
pub async fn deduct_tokens(&self, component: ContextComponent, tokens: usize)
Deduct tokens (after compaction/removal)
Sourcepub async fn generate_report(&self) -> String
pub async fn generate_report(&self) -> String
Generate a budget report
Trait Implementations§
Auto Trait Implementations§
impl Freeze for TokenBudgetManager
impl !RefUnwindSafe for TokenBudgetManager
impl Send for TokenBudgetManager
impl Sync for TokenBudgetManager
impl Unpin for TokenBudgetManager
impl !UnwindSafe for TokenBudgetManager
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> 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