pub struct MaxTokensRecovery {
pub max_attempts: u8,
pub scaling: TokenScaling,
pub ceiling: Option<u32>,
}Expand description
Recovery strategy when the provider returns StopReason::MaxTokens.
On hit, the loop discards the truncated assistant turn (the
MessageStart/MessageEnd events for it still fired — listeners
correlate via the new AgentEvent::OutputTokensEscalation) and
re-streams with a higher cap.
Bounded by max_attempts per turn. Hits the ceiling if set.
Fixed ladders run out by definition once attempts >= caps.len().
Fields§
§max_attempts: u8Hard upper bound on retries within a single turn. The loop
emits at most max_attempts escalation events per turn; the
attempts + 1th call simply uses the ladder’s last cap and
the result is accepted regardless.
scaling: TokenScalingHow to derive the next cap from the previous one.
ceiling: Option<u32>Hard upper bound on the cap itself. None means no ceiling
(relies on max_attempts to bound the spend). Recovery stops
short when the next computed cap would equal or fall below
the previous one (no progress).
Implementations§
Source§impl MaxTokensRecovery
impl MaxTokensRecovery
Sourcepub fn doubling() -> Self
pub fn doubling() -> Self
Default: 3 retries with doubling, no ceiling. Meant as the
“least-config option” for callers who just want the recovery
without tuning. Real deployments usually pin a ceiling
matching their model’s hard max.
Sourcepub fn next_cap(&self, prev_cap: u32, attempt_zero_indexed: u8) -> Option<u32>
pub fn next_cap(&self, prev_cap: u32, attempt_zero_indexed: u8) -> Option<u32>
Compute the cap for retry attempt attempt_zero_indexed
(0 = the first retry, after the original turn). Returns
None when the ladder cannot make further progress (Fixed
exhausted, ceiling reached at the previous step).
Trait Implementations§
Source§impl Clone for MaxTokensRecovery
impl Clone for MaxTokensRecovery
Source§fn clone(&self) -> MaxTokensRecovery
fn clone(&self) -> MaxTokensRecovery
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more