pub struct ContextManager { /* private fields */ }Expand description
Manages context window by summarizing/compacting when approaching limits. §3.7: “The Context Manager enforces the model’s window via summarization/compaction and a repo-map instead of dumping files.”
Implementations§
Source§impl ContextManager
impl ContextManager
pub fn new(max_tokens: u64) -> Self
Sourcepub fn estimate_tokens(&self, text: &str) -> u64
pub fn estimate_tokens(&self, text: &str) -> u64
Estimate token count for a string
Sourcepub fn needs_compaction(&self, total_chars: usize, reserve_tokens: u64) -> bool
pub fn needs_compaction(&self, total_chars: usize, reserve_tokens: u64) -> bool
Check if we’re approaching the context limit
Sourcepub fn compact_messages(
&self,
messages: &[Msg],
system_prompt_len: usize,
keep_last: usize,
) -> Vec<Msg>
pub fn compact_messages( &self, messages: &[Msg], system_prompt_len: usize, keep_last: usize, ) -> Vec<Msg>
Compact messages: keep system + last N messages, summarize earlier ones
Sourcepub fn repo_map_summary(&self, map: &RepoMap, max_files: usize) -> String
pub fn repo_map_summary(&self, map: &RepoMap, max_files: usize) -> String
Build a compact repo map representation for context
Trait Implementations§
Auto Trait Implementations§
impl Freeze for ContextManager
impl RefUnwindSafe for ContextManager
impl Send for ContextManager
impl Sync for ContextManager
impl Unpin for ContextManager
impl UnsafeUnpin for ContextManager
impl UnwindSafe for ContextManager
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
impl<A, B, T> HttpServerConnExec<A, B> for Twhere
B: Body,
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 more