pub struct ContextWindow {
pub window_id: Uuid,
pub assembled_at: DateTime<Utc>,
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: DateTime<Utc>When 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) -> ContextWindow
pub fn new(max_tokens: i32) -> ContextWindow
Create a new empty context window with the given token budget.
Sourcepub fn with_budget(budget: TokenBudget) -> ContextWindow
pub fn with_budget(budget: TokenBudget) -> ContextWindow
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 moreSource§impl Debug for ContextWindow
impl Debug for ContextWindow
Source§impl<'de> Deserialize<'de> for ContextWindow
impl<'de> Deserialize<'de> for ContextWindow
Source§fn deserialize<__D>(
__deserializer: __D,
) -> Result<ContextWindow, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<ContextWindow, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
Source§impl Display for ContextWindow
impl Display for ContextWindow
Source§impl PartialEq for ContextWindow
impl PartialEq for ContextWindow
Source§impl Serialize for ContextWindow
impl Serialize for ContextWindow
Source§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
Source§impl ToSchema for ContextWindow
impl ToSchema for ContextWindow
impl StructuralPartialEq for ContextWindow
Auto Trait Implementations§
impl Freeze for ContextWindow
impl RefUnwindSafe for ContextWindow
impl Send for ContextWindow
impl Sync for ContextWindow
impl Unpin 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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
§impl<T> ToStringFallible for Twhere
T: Display,
impl<T> ToStringFallible for Twhere
T: Display,
§fn try_to_string(&self) -> Result<String, TryReserveError>
fn try_to_string(&self) -> Result<String, TryReserveError>
ToString::to_string, but without panic on OOM.