pub trait ContextOverflowRecovery: Send + Sync {
// Required method
fn recover<'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
fn max_attempts(&self) -> u8 { ... }
fn name(&self) -> &'static str { ... }
}Expand description
Recovers from a provider context-window rejection MID-RUN.
The token-estimate heuristics that drive ContextTransform are
approximate, so a request can still exceed the model’s real window
and come back as crate::StreamError::ContextOverflow. When one is
installed, the loop hands this hook the current history, the impl
returns a smaller one (typically an aggressive compaction), and the
loop retries the SAME LLM call — bounded by max_attempts, and
with the shrunk history persisted into the live transcript so later
turns don’t immediately re-expand.
Distinct from ContextTransform on purpose: this fires ONLY on an
overflow (never on every round), its result is written back to the
caller’s transcript (not just the request clone), and returning an
unshrunk history ends recovery rather than spinning.
Required Methods§
Sourcefn recover<'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,
fn recover<'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,
Produce a smaller history for the retried request. cx carries the
same observables as a ContextTransform (cancellation signal,
model id, iteration, last provider usage, estimator). Returning a
history no shorter than the input signals “cannot shrink further”
and the loop stops retrying.
Provided Methods§
Sourcefn max_attempts(&self) -> u8
fn max_attempts(&self) -> u8
Maximum recovery attempts within a single run. Default 1.
Sourcefn name(&self) -> &'static str
fn name(&self) -> &'static str
Label for the AgentEvent::ContextTransformApplied diff event
emitted after a successful shrink, so observers can attribute the
history change.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".