pub struct TokenEstimate {
pub model: String,
pub request_tokens: usize,
pub budget: usize,
}Expand description
Pre-flight estimate of the next request’s token footprint.
Emitted before the provider is contacted so the TUI can render budget-aware warnings (“73 % of 128k window”) and the compaction pipeline can decide whether to run a pre-emptive summary pass.
The budget field is the usable window after the implementation has
subtracted its completion reserve and protocol overhead — it is not
the raw context window from the model card.
§Examples
use codetether_agent::session::TokenEstimate;
let est = TokenEstimate {
model: "anthropic/claude-opus-4-7".into(),
request_tokens: 94_000,
budget: 128_000,
};
assert!(est.fraction() > 0.7);
assert!(!est.is_over_budget());Fields§
§model: StringProvider-qualified model identifier the estimate targets.
request_tokens: usizeEstimated total request tokens (system + messages + tools).
budget: usizeUsable token budget for the request after reserves are subtracted.
Implementations§
Source§impl TokenEstimate
impl TokenEstimate
Sourcepub fn fraction(&self) -> f64
pub fn fraction(&self) -> f64
Fraction of the budget the request is projected to consume.
Returns 0.0 when budget == 0 rather than panicking, so callers
may feed the value directly into UI colour ramps.
§Examples
use codetether_agent::session::TokenEstimate;
let e = TokenEstimate { model: "m".into(), request_tokens: 50, budget: 100 };
assert!((e.fraction() - 0.5).abs() < 1e-9);
let z = TokenEstimate { model: "m".into(), request_tokens: 10, budget: 0 };
assert_eq!(z.fraction(), 0.0);Sourcepub fn is_over_budget(&self) -> bool
pub fn is_over_budget(&self) -> bool
Returns true when the estimate strictly exceeds the usable budget.
§Examples
use codetether_agent::session::TokenEstimate;
let e = TokenEstimate { model: "m".into(), request_tokens: 129_000, budget: 128_000 };
assert!(e.is_over_budget());Trait Implementations§
Source§impl Clone for TokenEstimate
impl Clone for TokenEstimate
Source§fn clone(&self) -> TokenEstimate
fn clone(&self) -> TokenEstimate
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for TokenEstimate
impl Debug for TokenEstimate
Source§impl<'de> Deserialize<'de> for TokenEstimate
impl<'de> Deserialize<'de> for TokenEstimate
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Auto Trait Implementations§
impl Freeze for TokenEstimate
impl RefUnwindSafe for TokenEstimate
impl Send for TokenEstimate
impl Sync for TokenEstimate
impl Unpin for TokenEstimate
impl UnsafeUnpin for TokenEstimate
impl UnwindSafe for TokenEstimate
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
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>
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>
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 moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request