pub struct ContextBudget { /* private fields */ }Expand description
Derived context body budget and the one compaction trigger.
The budget subtracts cacheable stable-prefix tokens and output reserve from
an effective model context window. Automatic compaction starts when the
dynamic body reaches AUTO_COMPACT_THRESHOLD_PERCENT of that body budget.
Whether a request can be sent is still the body budget itself. The budget
does not perform token estimation or mutate runtime state.
Implementations§
Source§impl ContextBudget
impl ContextBudget
Sourcepub fn from_window(
resolved_context_window_tokens: u64,
effective_context_window_percent: u8,
stable_prefix_tokens: u64,
output_reserve_tokens: u64,
) -> Result<Self, ContextError>
pub fn from_window( resolved_context_window_tokens: u64, effective_context_window_percent: u8, stable_prefix_tokens: u64, output_reserve_tokens: u64, ) -> Result<Self, ContextError>
Calculates the dynamic-body budget and its compaction trigger using
AUTO_COMPACT_THRESHOLD_PERCENT.
Sourcepub fn from_window_with_compaction_threshold(
resolved_context_window_tokens: u64,
effective_context_window_percent: u8,
stable_prefix_tokens: u64,
output_reserve_tokens: u64,
compaction_threshold_percent: u8,
) -> Result<Self, ContextError>
pub fn from_window_with_compaction_threshold( resolved_context_window_tokens: u64, effective_context_window_percent: u8, stable_prefix_tokens: u64, output_reserve_tokens: u64, compaction_threshold_percent: u8, ) -> Result<Self, ContextError>
Calculates the dynamic-body budget and its compaction trigger with an
explicit automatic compaction threshold percentage (1..=100).
Sourcepub fn effective_window_tokens(&self) -> u64
pub fn effective_window_tokens(&self) -> u64
Context window after applying the effective window percentage.
Sourcepub fn stable_prefix_tokens(&self) -> u64
pub fn stable_prefix_tokens(&self) -> u64
Tokens reserved for cacheable stable-prefix messages and tool profile.
Sourcepub fn output_reserve_tokens(&self) -> u64
pub fn output_reserve_tokens(&self) -> u64
Tokens reserved for model output.
Sourcepub fn body_budget_tokens(&self) -> u64
pub fn body_budget_tokens(&self) -> u64
Remaining token budget for dynamic body content.
Sourcepub fn compact_at_tokens(&self) -> u64
pub fn compact_at_tokens(&self) -> u64
Dynamic-body size that starts automatic compaction.
Trait Implementations§
Source§impl Clone for ContextBudget
impl Clone for ContextBudget
impl Copy for ContextBudget
Source§impl Debug for ContextBudget
impl Debug for ContextBudget
impl Eq for ContextBudget
Source§impl PartialEq for ContextBudget
impl PartialEq for ContextBudget
impl StructuralPartialEq for ContextBudget
Auto Trait Implementations§
impl Forget for ContextBudget
impl Freeze for ContextBudget
impl Move for ContextBudget
impl RefUnwindSafe for ContextBudget
impl Send for ContextBudget
impl Sync for ContextBudget
impl Unpin for ContextBudget
impl UnsafeUnpin for ContextBudget
impl UnwindSafe for ContextBudget
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.