pub struct DefaultBlockCompaction;Expand description
Default block-based compaction strategy.
Stateless — all parameters come from CompactionConfig.
keep_first: returns turn range0..keep_first_turnskeep_compacted: one-liner summaries of the middle section, bounded bymax_summary_tokenskeep_recent: truncates tool outputs in the recent section totool_output_max_lines
Trait Implementations§
Source§impl BlockCompactionStrategy for DefaultBlockCompaction
impl BlockCompactionStrategy for DefaultBlockCompaction
Source§fn keep_compacted<'life0, 'life1, 'life2, 'life3, 'async_trait>(
&'life0 self,
record: &'life1 LoopRecord,
turn_map: &'life2 TurnMap,
config: &'life3 CompactionConfig,
is_most_recent: bool,
) -> Pin<Box<dyn Future<Output = Option<CompactedSection>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
fn keep_compacted<'life0, 'life1, 'life2, 'life3, 'async_trait>(
&'life0 self,
record: &'life1 LoopRecord,
turn_map: &'life2 TurnMap,
config: &'life3 CompactionConfig,
is_most_recent: bool,
) -> Pin<Box<dyn Future<Output = Option<CompactedSection>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
Basic implementation: generates per-turn one-liner summaries until
max_summary_tokens is exhausted. Remaining turns are dropped.
More sophisticated strategies (e.g. LLM-based) should produce a holistic summary of ALL turns within the budget rather than dropping turns.
Summaries use Message::User role to maintain valid LLM message alternation
(user→assistant→user→…). A summary replaces a full turn sequence
(user + assistant + tool results) with a single user-role “[Summary]” message.
Source§fn keep_first<'life0, 'life1, 'life2, 'life3, 'async_trait>(
&'life0 self,
_record: &'life1 LoopRecord,
turn_map: &'life2 TurnMap,
config: &'life3 CompactionConfig,
) -> Pin<Box<dyn Future<Output = Option<TurnRange>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
fn keep_first<'life0, 'life1, 'life2, 'life3, 'async_trait>(
&'life0 self,
_record: &'life1 LoopRecord,
turn_map: &'life2 TurnMap,
config: &'life3 CompactionConfig,
) -> Pin<Box<dyn Future<Output = Option<TurnRange>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
Determine the keep_first section: turns kept verbatim from the start.
Only called for the most recent loop.
Source§fn keep_recent<'life0, 'life1, 'life2, 'life3, 'async_trait>(
&'life0 self,
record: &'life1 LoopRecord,
turn_map: &'life2 TurnMap,
config: &'life3 CompactionConfig,
) -> Pin<Box<dyn Future<Output = Option<CompactedSection>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
fn keep_recent<'life0, 'life1, 'life2, 'life3, 'async_trait>(
&'life0 self,
record: &'life1 LoopRecord,
turn_map: &'life2 TurnMap,
config: &'life3 CompactionConfig,
) -> Pin<Box<dyn Future<Output = Option<CompactedSection>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
Create the keep_recent section: recent turns with truncated tool outputs.
Only called for the most recent loop.
Source§fn compact<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
record: &'life1 LoopRecord,
config: &'life2 CompactionConfig,
is_most_recent: bool,
) -> Pin<Box<dyn Future<Output = CompactionBlock> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn compact<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
record: &'life1 LoopRecord,
config: &'life2 CompactionConfig,
is_most_recent: bool,
) -> Pin<Box<dyn Future<Output = CompactionBlock> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Assemble a
CompactionBlock from the three sections.
Default implementation calls the three methods above.Auto Trait Implementations§
impl Freeze for DefaultBlockCompaction
impl RefUnwindSafe for DefaultBlockCompaction
impl Send for DefaultBlockCompaction
impl Sync for DefaultBlockCompaction
impl Unpin for DefaultBlockCompaction
impl UnsafeUnpin for DefaultBlockCompaction
impl UnwindSafe for DefaultBlockCompaction
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