pub trait Compactor: Send + Sync {
// Required methods
fn should_compact(
&self,
transcript: &[Item],
point: MutationPoint,
) -> Option<CompactionReason>;
fn compact<'life0, 'life1, 'async_trait>(
&'life0 self,
transcript: &'life1 [Item],
reason: CompactionReason,
cancellation: Option<TurnCancellation>,
) -> Pin<Box<dyn Future<Output = Result<Vec<Item>, CompactionError>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait;
}Expand description
High-level compaction primitive. Implementations decide whether and how to compact, owning their own derived state (e.g. running token totals behind interior mutability) so the framework doesn’t need to plumb a separate observer or shared atomic.
Wire a Compactor into the loop via AgentBuilderCompactorExt::compactor,
which adapts it to a LoopMutator under the hood.
Required Methods§
Sourcefn should_compact(
&self,
transcript: &[Item],
point: MutationPoint,
) -> Option<CompactionReason>
fn should_compact( &self, transcript: &[Item], point: MutationPoint, ) -> Option<CompactionReason>
Decide whether to compact based on the current transcript and
mutation point. Returning None is a no-op.
Sourcefn compact<'life0, 'life1, 'async_trait>(
&'life0 self,
transcript: &'life1 [Item],
reason: CompactionReason,
cancellation: Option<TurnCancellation>,
) -> Pin<Box<dyn Future<Output = Result<Vec<Item>, CompactionError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn compact<'life0, 'life1, 'async_trait>(
&'life0 self,
transcript: &'life1 [Item],
reason: CompactionReason,
cancellation: Option<TurnCancellation>,
) -> Pin<Box<dyn Future<Output = Result<Vec<Item>, CompactionError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Produce the replacement transcript. Called only after
should_compact returns Some.
Implementations should respect cancellation.