pub trait ContextTransform: Plugin {
// Required method
fn transform<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
messages: Vec<AgentMessage>,
cx: &'life1 TransformContext<'life2>,
) -> Pin<Box<dyn Future<Output = Vec<AgentMessage>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait;
// Provided method
fn should_run(
&self,
_messages: &[AgentMessage],
_cx: &TransformContext<'_>,
) -> bool { ... }
}Expand description
Hook that transforms the message slice before it’s converted to the LLM provider format.
Common use: token-budget pruning. See crate::budget for the
default implementation.
Contract: must not throw; on failure return the input unchanged. Multiple plugins compose left-to-right.
Required Methods§
fn transform<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
messages: Vec<AgentMessage>,
cx: &'life1 TransformContext<'life2>,
) -> Pin<Box<dyn Future<Output = Vec<AgentMessage>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Provided Methods§
Sourcefn should_run(
&self,
_messages: &[AgentMessage],
_cx: &TransformContext<'_>,
) -> bool
fn should_run( &self, _messages: &[AgentMessage], _cx: &TransformContext<'_>, ) -> bool
Cheap predicate the loop consults before invoking transform.
Default returns true — preserves existing behavior. Plugins that
can decide locally that they have nothing to do (no browser
snapshots in history, history under budget, idle timer not
elapsed, no queued recovery notice, …) should override to return
false in those states.
When false, the loop skips the full message-vec clone + the
ContextTransformApplied diff event — eliminating the
per-transform cost on rounds where the plugin is a no-op. This
shows up most clearly in long-running scenarios: with several
transforms installed, each firing hundreds of times as a no-op,
the full before-clone + event emit otherwise happens every time.
Predicates MUST be O(1) or O(small-constant); a predicate that itself walks the entire history defeats the optimization.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".