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
| Name | Type | Description |
|---|---|---|
config | FailoverConfig | Failover configuration |
profiles | Vec<AuthProfile> | Registered profiles |
current_index | usize | Current profile index |
callbacks | Vec<FailoverCallback> | Failover callbacks |
Methods
new
fn new(config: FailoverConfig) -> SelfCreate a new failover manager.
Parameters:
| Name | Type |
|---|---|
config | FailoverConfig |
default_config
fn default_config() -> SelfCreate with default config.
add_profile
fn add_profile(&mut self, profile: AuthProfile) -> ()Add an auth profile.
Parameters:
| Name | Type |
|---|---|
profile | AuthProfile |
remove_profile
fn remove_profile(&mut self, name: &str) -> boolRemove a profile by name.
Parameters:
| Name | Type |
|---|---|
name | &str |
get_profile
fn get_profile(&self, name: &str) -> Option<&AuthProfile>Get a profile by name.
Parameters:
| Name | Type |
|---|---|
name | &str |
get_profile_mut
fn get_profile_mut(&mut self, name: &str) -> Option<&mut AuthProfile>Get a mutable profile by name.
Parameters:
| Name | Type |
|---|---|
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:
| Name | Type |
|---|---|
profile_name | &str |
error | &str |
is_rate_limit | bool |
mark_success
fn mark_success(&mut self, profile_name: &str) -> ()Mark a profile as successful.
Parameters:
| Name | Type |
|---|---|
profile_name | &str |
on_failover
fn on_failover(&mut self, callback: FailoverCallback) -> ()Register a callback for failover events.
Parameters:
| Name | Type |
|---|---|
callback | FailoverCallback |
get_retry_delay
fn get_retry_delay(&self, attempt: u32) -> DurationCalculate retry delay for an attempt.
Parameters:
| Name | Type |
|---|---|
attempt | u32 |
status
fn status(&self) -> FailoverStatusGet failover manager status.
reset_all
fn reset_all(&mut self) -> ()Reset all profiles to available status.
len
fn len(&self) -> usizeGet the number of profiles.
is_empty
fn is_empty(&self) -> boolCheck if empty.
Source
View on GitHubpraisonai/src/failover/mod.rs at line 292