pub struct SummarizeStrategy<M> { /* private fields */ }Expand description
Compaction strategy that calls a CompletionModel to summarize
the dropped portion of the history into a single text message,
instead of dropping it outright.
The chosen cut is the same as TruncateStrategy: walk back from
messages.len() - preserve_n_last to the nearest safe boundary
(a User message that does not contain a ToolResult). Pinned
messages from the dropped prefix are preserved verbatim at their
relative position; the unpinned portion is replaced with one
Message::user("[Summary of prior conversation]\n…").
Tool-call / tool-result blocks in the prefix are flattened into
plain text before being sent to the summarizer model. This lets
the strategy run with tools = None regardless of the original
agent’s tool surface, sidestepping provider validation that would
otherwise reject a tool_use block when no tools are declared.
On model failure the strategy returns
CompactionError::SummarizationFailed; the caller decides
whether to fall back to TruncateStrategy or propagate.
Implementations§
Source§impl<M> SummarizeStrategy<M>
impl<M> SummarizeStrategy<M>
Sourcepub fn new(model: Arc<M>) -> SummarizeStrategy<M>
pub fn new(model: Arc<M>) -> SummarizeStrategy<M>
Build a strategy that calls model to summarize dropped
history. Defaults: DEFAULT_SUMMARIZER_PROMPT as the system
prompt and max_tokens = 1024 for the summary output.
Sourcepub fn with_prompt(self, prompt: impl Into<String>) -> SummarizeStrategy<M>
pub fn with_prompt(self, prompt: impl Into<String>) -> SummarizeStrategy<M>
Replace the system prompt fed to the summarizer model. The
default (DEFAULT_SUMMARIZER_PROMPT) is intentionally terse
so the transcript dominates the max_tokens budget.
Sourcepub fn with_max_tokens(self, max_tokens: u32) -> SummarizeStrategy<M>
pub fn with_max_tokens(self, max_tokens: u32) -> SummarizeStrategy<M>
Cap on the summary’s output token count. Lower values produce a tighter summary at the cost of detail; higher values risk the summary itself blowing the budget on the next compaction.
Trait Implementations§
Source§impl<M> CompactionStrategy for SummarizeStrategy<M>
impl<M> CompactionStrategy for SummarizeStrategy<M>
Source§fn name(&self) -> &'static str
fn name(&self) -> &'static str
HistoryCompacted events so callers can attribute compaction
to a specific algorithm in logs/metrics.Source§fn compact<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
messages: &'life1 [Message],
pinned: &'life2 [bool],
preserve_n_last: usize,
) -> Pin<Box<dyn Future<Output = Result<CompactionOutput, CompactionError>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
SummarizeStrategy<M>: 'async_trait,
fn compact<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
messages: &'life1 [Message],
pinned: &'life2 [bool],
preserve_n_last: usize,
) -> Pin<Box<dyn Future<Output = Result<CompactionOutput, CompactionError>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
SummarizeStrategy<M>: 'async_trait,
messages into a smaller history. Read more