pub struct ContextWindow {
pub window_id: Uuid,
pub assembled_at: Timestamp,
pub max_tokens: i32,
pub used_tokens: i32,
pub sections: Vec<ContextSection>,
pub truncated: bool,
pub included_sections: Vec<String>,
pub assembly_trace: Vec<AssemblyDecision>,
pub budget: Option<TokenBudget>,
pub usage: SegmentUsage,
}Expand description
Assembled context window with token budget management.
Fields§
§window_id: UuidUnique identifier for this window
assembled_at: TimestampWhen this window was assembled
max_tokens: i32Maximum token budget
used_tokens: i32Tokens currently used
sections: Vec<ContextSection>Sections in priority order
truncated: boolWhether any section was truncated
included_sections: Vec<String>Names of included sections
assembly_trace: Vec<AssemblyDecision>Full audit trail of assembly decisions
budget: Option<TokenBudget>Segment-based token budget allocation
usage: SegmentUsagePer-segment usage tracking
Implementations§
Source§impl ContextWindow
impl ContextWindow
Sourcepub fn new(max_tokens: i32) -> Self
pub fn new(max_tokens: i32) -> Self
Create a new empty context window with the given token budget.
Sourcepub fn with_budget(budget: TokenBudget) -> Self
pub fn with_budget(budget: TokenBudget) -> Self
Create a new context window with segment-based budget.
Sourcepub fn add_to_segment(
&mut self,
segment: ContextSegment,
content: String,
priority: i32,
) -> Result<(), SegmentBudgetError>
pub fn add_to_segment( &mut self, segment: ContextSegment, content: String, priority: i32, ) -> Result<(), SegmentBudgetError>
Add content to a specific segment.
Returns an error if the segment budget would be exceeded.
Sourcepub fn add_section_to_segment(
&mut self,
segment: ContextSegment,
section: ContextSection,
) -> Result<(), SegmentBudgetError>
pub fn add_section_to_segment( &mut self, segment: ContextSegment, section: ContextSection, ) -> Result<(), SegmentBudgetError>
Add a pre-built section to a segment, preserving section metadata/sources.
Sourcepub fn segment_remaining(&self, segment: ContextSegment) -> i32
pub fn segment_remaining(&self, segment: ContextSegment) -> i32
Get remaining tokens for a specific segment.
Sourcepub fn remaining_tokens(&self) -> i32
pub fn remaining_tokens(&self) -> i32
Get remaining token budget.
Sourcepub fn add_section(&mut self, section: ContextSection) -> bool
pub fn add_section(&mut self, section: ContextSection) -> bool
Add a section to the window. Returns true if the section was added, false if it didn’t fit.
Sourcepub fn add_truncated_section(&mut self, section: ContextSection)
pub fn add_truncated_section(&mut self, section: ContextSection)
Add a truncated section to the window.
Trait Implementations§
Source§impl Clone for ContextWindow
impl Clone for ContextWindow
Source§fn clone(&self) -> ContextWindow
fn clone(&self) -> ContextWindow
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more