pub struct FallbackConfig {
pub developer: Vec<String>,
pub reviewer: Vec<String>,
pub commit: Vec<String>,
pub provider_fallback: HashMap<String, Vec<String>>,
pub max_retries: u32,
pub retry_delay_ms: u64,
pub backoff_multiplier: f64,
pub max_backoff_ms: u64,
pub max_cycles: u32,
}Expand description
Agent chain configuration for preferred agents and fallback switching.
The agent chain defines both:
- The preferred agent (first in the list) for each role
- The fallback agents (remaining in the list) to try if the preferred fails
This provides a unified way to configure which agents to use and in what order. Ralph automatically switches to the next agent in the chain when encountering errors like rate limits or auth failures.
§Provider-Level Fallback
In addition to agent-level fallback, you can configure provider-level fallback
within a single agent using the provider_fallback field. This is useful for
agents like opencode that support multiple providers/models via the -m flag.
Example:
[agent_chain]
provider_fallback.opencode = ["-m opencode/glm-4.7-free", "-m opencode/claude-sonnet-4"]§Exponential Backoff and Cycling
When all fallbacks are exhausted, Ralph uses exponential backoff and cycles back to the first agent in the chain:
- Base delay starts at
retry_delay_ms(default: 1000ms) - Each cycle multiplies by
backoff_multiplier(default: 2.0) - Capped at
max_backoff_ms(default: 60000ms = 1 minute) - Maximum cycles controlled by
max_cycles(default: 3)
Fields§
§developer: Vec<String>Ordered list of agents for developer role (first = preferred, rest = fallbacks).
reviewer: Vec<String>Ordered list of agents for reviewer role (first = preferred, rest = fallbacks).
commit: Vec<String>Ordered list of agents for commit role (first = preferred, rest = fallbacks).
provider_fallback: HashMap<String, Vec<String>>Provider-level fallback: maps agent name to list of model flags to try.
Example: opencode = ["-m opencode/glm-4.7-free", "-m opencode/claude-sonnet-4"]
max_retries: u32Maximum number of retries per agent before moving to next.
retry_delay_ms: u64Base delay between retries in milliseconds.
backoff_multiplier: f64Multiplier for exponential backoff (default: 2.0).
max_backoff_ms: u64Maximum backoff delay in milliseconds (default: 60000 = 1 minute).
max_cycles: u32Maximum number of cycles through all agents before giving up (default: 3).
Implementations§
Source§impl FallbackConfig
impl FallbackConfig
Sourcepub fn calculate_backoff(&self, cycle: u32) -> u64
pub fn calculate_backoff(&self, cycle: u32) -> u64
Calculate exponential backoff delay for a given cycle.
Uses the formula: min(base * multiplier^cycle, max_backoff)
Uses integer arithmetic to avoid floating-point casting issues.
Sourcepub fn get_fallbacks(&self, role: AgentRole) -> &[String]
pub fn get_fallbacks(&self, role: AgentRole) -> &[String]
Get fallback agents for a role.
Sourcepub fn has_fallbacks(&self, role: AgentRole) -> bool
pub fn has_fallbacks(&self, role: AgentRole) -> bool
Check if fallback is configured for a role.
Sourcepub fn get_provider_fallbacks(&self, agent_name: &str) -> &[String]
pub fn get_provider_fallbacks(&self, agent_name: &str) -> &[String]
Get provider-level fallback model flags for an agent.
Returns the list of model flags to try for the given agent name. Empty slice if no provider fallback is configured for this agent.
Sourcepub fn has_provider_fallbacks(&self, agent_name: &str) -> bool
pub fn has_provider_fallbacks(&self, agent_name: &str) -> bool
Check if provider-level fallback is configured for an agent.
Trait Implementations§
Source§impl Clone for FallbackConfig
impl Clone for FallbackConfig
Source§fn clone(&self) -> FallbackConfig
fn clone(&self) -> FallbackConfig
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for FallbackConfig
impl Debug for FallbackConfig
Source§impl Default for FallbackConfig
impl Default for FallbackConfig
Source§impl<'de> Deserialize<'de> for FallbackConfig
impl<'de> Deserialize<'de> for FallbackConfig
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Auto Trait Implementations§
impl Freeze for FallbackConfig
impl RefUnwindSafe for FallbackConfig
impl Send for FallbackConfig
impl Sync for FallbackConfig
impl Unpin for FallbackConfig
impl UnwindSafe for FallbackConfig
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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 more