pub struct ContextBudget {
pub execution_id: ExecutionId,
pub total_tokens: usize,
pub output_reserve: usize,
pub available_tokens: usize,
pub used_tokens: usize,
pub segments: Vec<SegmentBudget>,
pub warning_threshold: u8,
pub critical_threshold: u8,
pub updated_at: DateTime<Utc>,
}Expand description
Token allocation across all segments
Matches contextBudgetSchema in @enact/schemas
Fields§
§execution_id: ExecutionIdExecution this budget belongs to
total_tokens: usizeTotal context window size (model limit)
output_reserve: usizeTokens reserved for output generation
available_tokens: usizeAvailable tokens for input context
used_tokens: usizeCurrent total usage
segments: Vec<SegmentBudget>Per-segment budgets
warning_threshold: u8Warning threshold (percentage, 0-100)
critical_threshold: u8Critical threshold (percentage, 0-100)
updated_at: DateTime<Utc>Last updated timestamp
Implementations§
Source§impl ContextBudget
impl ContextBudget
Sourcepub fn new(
execution_id: ExecutionId,
total_tokens: usize,
output_reserve: usize,
) -> Self
pub fn new( execution_id: ExecutionId, total_tokens: usize, output_reserve: usize, ) -> Self
Create a new context budget
Sourcepub fn preset_gpt4_128k(execution_id: ExecutionId) -> Self
pub fn preset_gpt4_128k(execution_id: ExecutionId) -> Self
Create a GPT-4 128K preset
Sourcepub fn preset_gpt4_32k(execution_id: ExecutionId) -> Self
pub fn preset_gpt4_32k(execution_id: ExecutionId) -> Self
Create a GPT-4 32K preset
Sourcepub fn preset_claude_200k(execution_id: ExecutionId) -> Self
pub fn preset_claude_200k(execution_id: ExecutionId) -> Self
Create a Claude 200K preset
Sourcepub fn preset_default(execution_id: ExecutionId) -> Self
pub fn preset_default(execution_id: ExecutionId) -> Self
Create a default 8K preset
Sourcepub fn get_segment(
&self,
segment_type: ContextSegmentType,
) -> Option<&SegmentBudget>
pub fn get_segment( &self, segment_type: ContextSegmentType, ) -> Option<&SegmentBudget>
Get the budget for a specific segment type
Sourcepub fn get_segment_mut(
&mut self,
segment_type: ContextSegmentType,
) -> Option<&mut SegmentBudget>
pub fn get_segment_mut( &mut self, segment_type: ContextSegmentType, ) -> Option<&mut SegmentBudget>
Get mutable budget for a specific segment type
Sourcepub fn update_segment_usage(
&mut self,
segment_type: ContextSegmentType,
tokens: usize,
)
pub fn update_segment_usage( &mut self, segment_type: ContextSegmentType, tokens: usize, )
Update token usage for a segment
Sourcepub fn add_tokens(&mut self, segment_type: ContextSegmentType, tokens: usize)
pub fn add_tokens(&mut self, segment_type: ContextSegmentType, tokens: usize)
Add tokens to a segment
Sourcepub fn remove_tokens(&mut self, segment_type: ContextSegmentType, tokens: usize)
pub fn remove_tokens(&mut self, segment_type: ContextSegmentType, tokens: usize)
Remove tokens from a segment
Sourcepub fn usage_percent(&self) -> u8
pub fn usage_percent(&self) -> u8
Usage percentage (0-100)
Sourcepub fn is_warning(&self) -> bool
pub fn is_warning(&self) -> bool
Whether usage is at warning level
Sourcepub fn is_critical(&self) -> bool
pub fn is_critical(&self) -> bool
Whether usage is at critical level
Sourcepub fn health(&self) -> BudgetHealth
pub fn health(&self) -> BudgetHealth
Health status
Trait Implementations§
Source§impl Clone for ContextBudget
impl Clone for ContextBudget
Source§fn clone(&self) -> ContextBudget
fn clone(&self) -> ContextBudget
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more