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 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.