#[non_exhaustive]pub enum FallbackTrigger {
Retryable,
ModelNotFound,
QuotaExhausted,
Refusal,
ContextOverflow,
AuthFailure,
}Expand description
A condition that moves a FallbackLlm on to its next model.
Only a failure the model reports counts: an error from the run’s budget, spend ledger or kill switch is never a reason to try another model, and is returned as is.
| Trigger | Default | Matches |
|---|---|---|
Retryable | on | Rate limiting, timeouts, server errors and provider outages (AdkError::is_retryable), once the model’s own retries are used up |
ModelNotFound | on | The provider does not serve the model: an unknown, retired or unavailable model id (ErrorCategory::NotFound) |
QuotaExhausted | on | The provider account’s quota, credit balance or spend limit is used up (ErrorCategory::ResourceExhausted) |
Refusal | off | The model declined the request (FinishReason::Refusal) before any output |
ContextOverflow | off | The request is longer than the model’s context window |
AuthFailure | off | The provider refused the credentials or the permission (ErrorCategory::Unauthorized, ErrorCategory::Forbidden) |
§Example
use adk_model::fallback::FallbackTrigger;
assert!(FallbackTrigger::DEFAULT.contains(&FallbackTrigger::Retryable));
assert!(!FallbackTrigger::DEFAULT.contains(&FallbackTrigger::Refusal));
assert_eq!(FallbackTrigger::ModelNotFound.as_str(), "model_not_found");Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
Retryable
A transient failure the model’s own retries did not clear.
ModelNotFound
The provider does not serve the requested model.
QuotaExhausted
The provider account’s quota or credit is used up.
Refusal
The model declined the request before producing any output.
ContextOverflow
The request does not fit the model’s context window.
AuthFailure
The provider refused the credentials or the permission.
Implementations§
Source§impl FallbackTrigger
impl FallbackTrigger
Sourcepub const DEFAULT: [FallbackTrigger; 3]
pub const DEFAULT: [FallbackTrigger; 3]
The triggers a FallbackLlm uses unless configured otherwise: the failures another
model can serve without a change to the request or to its permissions.
Sourcepub fn as_str(self) -> &'static str
pub fn as_str(self) -> &'static str
The trigger’s name in tracing and in FALLBACK_METADATA_KEY metadata.
Sourcepub fn for_error(error: &AdkError) -> Option<Self>
pub fn for_error(error: &AdkError) -> Option<Self>
The trigger error matches, if any.
Only an error from the model (ErrorComponent::Model) matches, so a refusal by the
run’s budget, spend ledger or kill switch never moves a chain on.
§Example
use adk_core::{AdkError, ErrorCategory, ErrorComponent};
use adk_model::fallback::FallbackTrigger;
let overloaded = AdkError::new(
ErrorComponent::Model,
ErrorCategory::Unavailable,
"model.anthropic.api_error",
"overloaded",
);
assert_eq!(FallbackTrigger::for_error(&overloaded), Some(FallbackTrigger::Retryable));
let budget = AdkError::new(
ErrorComponent::Agent,
ErrorCategory::ResourceExhausted,
"budget.model_calls_exceeded",
"the run's model-call budget is spent",
);
assert_eq!(FallbackTrigger::for_error(&budget), None);Trait Implementations§
Source§impl Clone for FallbackTrigger
impl Clone for FallbackTrigger
impl Copy for FallbackTrigger
Source§impl Debug for FallbackTrigger
impl Debug for FallbackTrigger
Source§impl Display for FallbackTrigger
impl Display for FallbackTrigger
impl Eq for FallbackTrigger
Source§impl Hash for FallbackTrigger
impl Hash for FallbackTrigger
Source§impl PartialEq for FallbackTrigger
impl PartialEq for FallbackTrigger
impl StructuralPartialEq for FallbackTrigger
Auto Trait Implementations§
impl Forget for FallbackTrigger
impl Freeze for FallbackTrigger
impl Move for FallbackTrigger
impl RefUnwindSafe for FallbackTrigger
impl Send for FallbackTrigger
impl Sync for FallbackTrigger
impl Unpin for FallbackTrigger
impl UnsafeUnpin for FallbackTrigger
impl UnwindSafe for FallbackTrigger
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<T> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
Source§fn with_current_context(self) -> WithContext<Self> ⓘ
fn with_current_context(self) -> WithContext<Self> ⓘ
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request