pub struct Compactor {
pub threshold_chars: usize,
pub keep_recent_n: usize,
}Expand description
Configuration for LLM-driven transcript compaction.
Fields§
§threshold_chars: usizeCharacter-count threshold above which compaction is triggered.
Defaults to usize::MAX (disabled).
keep_recent_n: usizeNumber of most-recent messages to keep verbatim during compaction.
Implementations§
Source§impl Compactor
impl Compactor
Sourcepub fn new(threshold_chars: usize) -> Self
pub fn new(threshold_chars: usize) -> Self
Create a new compactor with the given threshold and default keep_recent_n (8).
Sourcepub fn keep_recent_n(self, n: usize) -> Self
pub fn keep_recent_n(self, n: usize) -> Self
Set the number of recent messages to preserve verbatim.
Sourcepub fn estimate_chars(transcript: &[Message]) -> usize
pub fn estimate_chars(transcript: &[Message]) -> usize
Estimate the prompt character count of a transcript.
This is a rough proxy for token count. The agent uses this to decide whether compaction is needed before the next LLM call.
Sourcepub async fn apply_to_transcript(
&self,
provider: &dyn LlmProvider,
transcript: &mut Vec<Message>,
) -> Result<Option<(usize, usize)>>
pub async fn apply_to_transcript( &self, provider: &dyn LlmProvider, transcript: &mut Vec<Message>, ) -> Result<Option<(usize, usize)>>
Apply compaction in-place to transcript, returning (removed, summary_chars).
Finds the correct split point (never splits inside a tool-call pair),
calls compact() to get the summary message, splices the transcript,
and returns how many messages were removed and the summary char count.
Returns None when the transcript is too short to compact
(< keep_recent_n + 2 messages).
Sourcepub async fn compact(
&self,
provider: &dyn LlmProvider,
transcript: &[Message],
) -> Result<Message>
pub async fn compact( &self, provider: &dyn LlmProvider, transcript: &[Message], ) -> Result<Message>
Compact the transcript: summarize older messages into a single system
message, keeping the last keep_recent_n messages verbatim.
Returns the summary Message that should replace the older portion.
The caller is responsible for splicing it into the transcript.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Compactor
impl RefUnwindSafe for Compactor
impl Send for Compactor
impl Sync for Compactor
impl Unpin for Compactor
impl UnsafeUnpin for Compactor
impl UnwindSafe for Compactor
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<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>
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>
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