Failover Manager • Rust AI Agent SDK

FailoverManager: Manages failover between multiple LLM auth profiles. Provides automatic failover when rate limits or errors occur, with configurable retry behavior…

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

rust
fn new(config: FailoverConfig) -> Self

Create a new failover manager.

Parameters:

NameType
configFailoverConfig

default_config

rust
fn default_config() -> Self

Create with default config.

add_profile

rust
fn add_profile(&mut self, profile: AuthProfile) -> ()

Add an auth profile.

Parameters:

NameType
profileAuthProfile

remove_profile

rust
fn remove_profile(&mut self, name: &str) -> bool

Remove a profile by name.

Parameters:

NameType
name&str

get_profile

rust
fn get_profile(&self, name: &str) -> Option<&AuthProfile>

Get a profile by name.

Parameters:

NameType
name&str

get_profile_mut

rust
fn get_profile_mut(&mut self, name: &str) -> Option<&mut AuthProfile>

Get a mutable profile by name.

Parameters:

NameType
name&str

list_profiles

rust
fn list_profiles(&self) -> &[AuthProfile]

List all profiles.

get_next_profile

rust
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

rust
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

rust
fn mark_success(&mut self, profile_name: &str) -> ()

Mark a profile as successful.

Parameters:

NameType
profile_name&str

on_failover

rust
fn on_failover(&mut self, callback: FailoverCallback) -> ()

Register a callback for failover events.

Parameters:

NameType
callbackFailoverCallback

get_retry_delay

rust
fn get_retry_delay(&self, attempt: u32) -> Duration

Calculate retry delay for an attempt.

Parameters:

NameType
attemptu32

status

rust
fn status(&self) -> FailoverStatus

Get failover manager status.

reset_all

rust
fn reset_all(&mut self) -> ()

Reset all profiles to available status.

len

rust
fn len(&self) -> usize

Get the number of profiles.

is_empty

rust
fn is_empty(&self) -> bool

Check if empty.

Source

View on GitHub

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


Related Documentation