Skip to main content

FallbackConfig

Struct FallbackConfig 

Source
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:

  1. The preferred agent (first in the list) for each role
  2. 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: u32

Maximum number of retries per agent before moving to next.

§retry_delay_ms: u64

Base delay between retries in milliseconds.

§backoff_multiplier: f64

Multiplier for exponential backoff (default: 2.0).

§max_backoff_ms: u64

Maximum backoff delay in milliseconds (default: 60000 = 1 minute).

§max_cycles: u32

Maximum number of cycles through all agents before giving up (default: 3).

Implementations§

Source§

impl FallbackConfig

Source

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.

Source

pub fn get_fallbacks(&self, role: AgentRole) -> &[String]

Get fallback agents for a role.

Source

pub fn has_fallbacks(&self, role: AgentRole) -> bool

Check if fallback is configured for a role.

Source

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.

Source

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

Source§

fn clone(&self) -> FallbackConfig

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for FallbackConfig

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for FallbackConfig

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for FallbackConfig

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,