pub struct ContextWindow { /* private fields */ }Expand description
Context window manager for LLM interactions.
Implementations§
Source§impl ContextWindow
impl ContextWindow
Sourcepub fn new(config: WindowConfig) -> Self
pub fn new(config: WindowConfig) -> Self
Create a new context window with the given configuration.
Sourcepub fn add_message(&mut self, role: Role, content: impl Into<String>)
pub fn add_message(&mut self, role: Role, content: impl Into<String>)
Add a message to the context window.
If the window overflows after adding, the configured truncation strategy is applied automatically.
Sourcepub fn add_pinned(&mut self, role: Role, content: impl Into<String>)
pub fn add_pinned(&mut self, role: Role, content: impl Into<String>)
Add a pinned message that will never be truncated.
Sourcepub fn total_tokens(&self) -> usize
pub fn total_tokens(&self) -> usize
Current total tokens used by messages + summaries.
Sourcepub fn available_tokens(&self) -> usize
pub fn available_tokens(&self) -> usize
Available tokens for new content (excluding reserved space).
Sourcepub fn is_overflowing(&self) -> bool
pub fn is_overflowing(&self) -> bool
Whether the current context exceeds the available budget.
Sourcepub fn fill_ratio(&self) -> f64
pub fn fill_ratio(&self) -> f64
Fill ratio [0, 1] of the usable token budget.
Sourcepub fn state(&self) -> WindowState
pub fn state(&self) -> WindowState
Get a snapshot of the current window state.
Sourcepub fn message_count(&self) -> usize
pub fn message_count(&self) -> usize
Number of messages currently in the window.
Sourcepub fn messages(&self) -> impl Iterator<Item = &ContextMessage>
pub fn messages(&self) -> impl Iterator<Item = &ContextMessage>
Access messages as a slice (deque iteration).
Sourcepub fn summaries(&self) -> &[ContextSummary]
pub fn summaries(&self) -> &[ContextSummary]
Access summaries.
Sourcepub fn build_context(&self) -> String
pub fn build_context(&self) -> String
Build the final context string for sending to the LLM.
Sourcepub fn config(&self) -> &WindowConfig
pub fn config(&self) -> &WindowConfig
Return the current configuration.
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<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreimpl<T> MaybeSend for Twhere
T: Send,
Source§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
The inverse inclusion map: attempts to construct
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
Checks if
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
Use with care! Same as
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
The inclusion map: converts
self to the equivalent element of its superset.Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
The inverse inclusion map: attempts to construct
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
Checks if
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
Use with care! Same as
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
The inclusion map: converts
self to the equivalent element of its superset.