Skip to main content

FailoverManager

Defined in the failover module.
Rust AI Agent SDK Manages failover between multiple LLM auth profiles. Provides automatic failover when rate limits or errors occur, with configurable retry behavior and cooldown periods.

Fields

NameTypeDescription
configFailoverConfigFailover configuration
profilesVec<AuthProfile>Registered profiles
current_indexusizeCurrent profile index
callbacksVec<FailoverCallback>Failover callbacks

Methods

new

fn new(config: FailoverConfig) -> Self
Create a new failover manager. Parameters:
NameType
configFailoverConfig

default_config

fn default_config() -> Self
Create with default config.

add_profile

fn add_profile(&mut self, profile: AuthProfile) -> ()
Add an auth profile. Parameters:
NameType
profileAuthProfile

remove_profile

fn remove_profile(&mut self, name: &str) -> bool
Remove a profile by name. Parameters:
NameType
name&str

get_profile

fn get_profile(&self, name: &str) -> Option<&AuthProfile>
Get a profile by name. Parameters:
NameType
name&str

get_profile_mut

fn get_profile_mut(&mut self, name: &str) -> Option<&mut AuthProfile>
Get a mutable profile by name. Parameters:
NameType
name&str

list_profiles

fn list_profiles(&self) -> &[AuthProfile]
List all profiles.

get_next_profile

fn get_next_profile(&mut self) -> Option<&AuthProfile>
Get the next available profile. Returns profiles in priority order, skipping those that are rate limited or in cooldown.

mark_failure

fn mark_failure(&mut self, profile_name: &str, error: &str, is_rate_limit: bool) -> ()
Mark a profile as failed. Parameters:
NameType
profile_name&str
error&str
is_rate_limitbool

mark_success

fn mark_success(&mut self, profile_name: &str) -> ()
Mark a profile as successful. Parameters:
NameType
profile_name&str

on_failover

fn on_failover(&mut self, callback: FailoverCallback) -> ()
Register a callback for failover events. Parameters:
NameType
callbackFailoverCallback

get_retry_delay

fn get_retry_delay(&self, attempt: u32) -> Duration
Calculate retry delay for an attempt. Parameters:
NameType
attemptu32

status

fn status(&self) -> FailoverStatus
Get failover manager status.

reset_all

fn reset_all(&mut self) -> ()
Reset all profiles to available status.

len

fn len(&self) -> usize
Get the number of profiles.

is_empty

fn is_empty(&self) -> bool
Check if empty.

Source

View on GitHub

praisonai/src/failover/mod.rs at line 292