pub struct TokenTracker {
pub provider_id: Option<String>,
pub model_id: Option<String>,
pub context_limit: Option<u64>,
pub latest_input_tokens: Option<u64>,
pub compaction_needed: bool,
/* private fields */
}Expand description
Tracks token usage during a session run to detect context limit threshold.
Fields§
§provider_id: Option<String>Provider ID from message events
model_id: Option<String>Model ID from message events
context_limit: Option<u64>Context limit for the current model (from cached limits)
latest_input_tokens: Option<u64>Latest observed input token count
compaction_needed: boolFlag indicating compaction/summarization is needed
Implementations§
Source§impl TokenTracker
impl TokenTracker
Sourcepub fn with_threshold(threshold: f64) -> Self
pub fn with_threshold(threshold: f64) -> Self
Create a new token tracker with a custom compaction threshold.
The threshold should be between 0.0 and 1.0 (e.g., 0.80 for 80%).
Sourcepub fn observe_event<F>(&mut self, ev: &Event, context_limit_lookup: F)
pub fn observe_event<F>(&mut self, ev: &Event, context_limit_lookup: F)
Observe an SSE event and update token tracking.
The context_limit_lookup function is called to look up the context limit
for a given (provider_id, model_id) pair from the cached limits.
Sourcepub fn observe_tokens(&mut self, tokens: &TokenUsage)
pub fn observe_tokens(&mut self, tokens: &TokenUsage)
Observe token usage and update threshold flag.
Trait Implementations§
Source§impl Clone for TokenTracker
impl Clone for TokenTracker
Source§fn clone(&self) -> TokenTracker
fn clone(&self) -> TokenTracker
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for TokenTracker
impl Debug for TokenTracker
Auto Trait Implementations§
impl Freeze for TokenTracker
impl RefUnwindSafe for TokenTracker
impl Send for TokenTracker
impl Sync for TokenTracker
impl Unpin for TokenTracker
impl UnsafeUnpin for TokenTracker
impl UnwindSafe for TokenTracker
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