pub struct CompactionProvider { /* private fields */ }Expand description
A ContextProvider that compacts the accumulated message list —
typically the run’s history, once a HistoryProvider
has prepended it in before_run — down to fit a CompactionStrategy’s
constraint before it reaches the model. Rust equivalent of (a subset of)
upstream’s CompactionProvider (see module docs and UPSTREAM_DRIFT.md
§9).
Register it via AgentBuilder::with_compaction,
which attaches it as one of the agent’s own context providers — those run
after the session’s (which is where a history provider, auto-attached
or explicit, lives — see Agent::combined_providers),
so compaction always sees the full, history-prepended message list for the
run.
Implementations§
Source§impl CompactionProvider
impl CompactionProvider
Sourcepub fn new(strategy: impl CompactionStrategy + 'static) -> CompactionProvider
pub fn new(strategy: impl CompactionStrategy + 'static) -> CompactionProvider
A compaction provider using strategy with the default
ApproxTokenizer.
Sourcepub fn with_tokenizer(
strategy: impl CompactionStrategy + 'static,
tokenizer: impl Tokenizer + 'static,
) -> CompactionProvider
pub fn with_tokenizer( strategy: impl CompactionStrategy + 'static, tokenizer: impl Tokenizer + 'static, ) -> CompactionProvider
A compaction provider using strategy and an explicit tokenizer.
Trait Implementations§
Source§impl ContextProvider for CompactionProvider
impl ContextProvider for CompactionProvider
Source§fn before_run<'life0, 'life1, 'async_trait>(
&'life0 self,
ctx: &'life1 mut SessionContext,
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
CompactionProvider: 'async_trait,
fn before_run<'life0, 'life1, 'async_trait>(
&'life0 self,
ctx: &'life1 mut SessionContext,
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
CompactionProvider: 'async_trait,
Replace ctx.messages (the accumulated history + any earlier
provider-injected messages) with the strategy’s compacted subset.
Source§fn after_run<'life0, 'life1, 'life2, 'life3, 'async_trait>(
&'life0 self,
_request_messages: &'life1 [Message],
_response_messages: &'life2 [Message],
_error: Option<&'life3 Error>,
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
Self: 'async_trait,
fn after_run<'life0, 'life1, 'life2, 'life3, 'async_trait>(
&'life0 self,
_request_messages: &'life1 [Message],
_response_messages: &'life2 [Message],
_error: Option<&'life3 Error>,
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
Self: 'async_trait,
Source§fn is_history_provider(&self) -> bool
fn is_history_provider(&self) -> bool
HistoryProvider). Agent
and WorkflowAgent use this to
detect an already-attached history provider among a session’s
context_providers and avoid auto-attaching a redundant
InMemoryHistoryProvider.
Defaults to false; history providers override it to true.