pub struct ContextWindow { /* private fields */ }Expand description
Context Window - manages segments within budget
Implementations§
Source§impl ContextWindow
impl ContextWindow
Sourcepub fn new(budget: ContextBudget) -> Result<Self, ContextWindowError>
pub fn new(budget: ContextBudget) -> Result<Self, ContextWindowError>
Create a new context window
Sourcepub fn with_preset_gpt4_128k(
execution_id: ExecutionId,
) -> Result<Self, ContextWindowError>
pub fn with_preset_gpt4_128k( execution_id: ExecutionId, ) -> Result<Self, ContextWindowError>
Create with a preset budget
Sourcepub fn with_preset_claude_200k(
execution_id: ExecutionId,
) -> Result<Self, ContextWindowError>
pub fn with_preset_claude_200k( execution_id: ExecutionId, ) -> Result<Self, ContextWindowError>
Create with Claude 200K preset
Sourcepub fn with_preset_default(
execution_id: ExecutionId,
) -> Result<Self, ContextWindowError>
pub fn with_preset_default( execution_id: ExecutionId, ) -> Result<Self, ContextWindowError>
Create with default (8K) preset
Sourcepub fn execution_id(&self) -> &ExecutionId
pub fn execution_id(&self) -> &ExecutionId
Get the execution ID
Sourcepub fn segments(&self) -> &[ContextSegment]
pub fn segments(&self) -> &[ContextSegment]
Get all segments
Sourcepub fn budget(&self) -> &ContextBudget
pub fn budget(&self) -> &ContextBudget
Get the budget
Sourcepub fn budget_mut(&mut self) -> &mut ContextBudget
pub fn budget_mut(&mut self) -> &mut ContextBudget
Get mutable budget
Sourcepub fn count_tokens(&self, text: &str) -> usize
pub fn count_tokens(&self, text: &str) -> usize
Count tokens for text
Sourcepub fn add_segment_auto(
&mut self,
segment: ContextSegment,
) -> Result<(), ContextWindowError>
pub fn add_segment_auto( &mut self, segment: ContextSegment, ) -> Result<(), ContextWindowError>
Add a segment with automatic token counting
Sourcepub fn add_segment(
&mut self,
segment: ContextSegment,
) -> Result<(), ContextWindowError>
pub fn add_segment( &mut self, segment: ContextSegment, ) -> Result<(), ContextWindowError>
Add a segment to the context window
Sourcepub fn remove_segment(&mut self, segment_id: &str) -> bool
pub fn remove_segment(&mut self, segment_id: &str) -> bool
Remove a segment by ID
Sourcepub fn segments_of_type(
&self,
segment_type: ContextSegmentType,
) -> Vec<&ContextSegment>
pub fn segments_of_type( &self, segment_type: ContextSegmentType, ) -> Vec<&ContextSegment>
Get segments of a specific type
Sourcepub fn used_tokens(&self) -> usize
pub fn used_tokens(&self) -> usize
Total tokens currently used
Sourcepub fn remaining_tokens(&self) -> usize
pub fn remaining_tokens(&self) -> usize
Remaining tokens available
Sourcepub fn needs_compaction(&self) -> bool
pub fn needs_compaction(&self) -> bool
Check if the window needs compaction
Sourcepub fn is_critical(&self) -> bool
pub fn is_critical(&self) -> bool
Check if the window is in critical state
Sourcepub fn health(&self) -> BudgetHealth
pub fn health(&self) -> BudgetHealth
Get health status
Sourcepub fn compact(
&mut self,
compactor: &Compactor,
) -> Result<CompactionResult, ContextWindowError>
pub fn compact( &mut self, compactor: &Compactor, ) -> Result<CompactionResult, ContextWindowError>
Compact the context using the given compactor
Sourcepub fn build_context(&self) -> String
pub fn build_context(&self) -> String
Build the context as a single string (for LLM calls)
Sourcepub fn state(&self) -> ContextWindowState
pub fn state(&self) -> ContextWindowState
Get the current state (for serialization)
Auto Trait Implementations§
impl Freeze for ContextWindow
impl RefUnwindSafe for ContextWindow
impl Send for ContextWindow
impl Sync for ContextWindow
impl Unpin for ContextWindow
impl UnsafeUnpin for ContextWindow
impl UnwindSafe for ContextWindow
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