1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
//! Routing configuration for fallback chains and smart routing.
//!
//! Allows workflows to define provider fallback strategies:
//!
//! ```yaml
//! routing:
//! fallback: [anthropic, openai, groq]
//! strategy: cost # or: latency, availability
//! ```
use serde::{Deserialize, Serialize};
/// Routing configuration for provider fallback and smart routing.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct RoutingConfig {
/// Fallback provider chain (try in order).
#[serde(default)]
pub fallback: Vec<String>,
/// Routing strategy.
#[serde(default)]
pub strategy: Option<RoutingStrategy>,
}
/// Strategy for selecting a provider from the fallback chain.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "lowercase")]
pub enum RoutingStrategy {
/// Use the cheapest available provider.
Cost,
/// Use the fastest available provider.
Latency,
/// Use the first available provider (default).
Availability,
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn routing_config_serde_roundtrip() {
let config = RoutingConfig {
fallback: vec!["anthropic".into(), "openai".into()],
strategy: Some(RoutingStrategy::Cost),
};
let json = serde_json::to_string(&config).unwrap();
let parsed: RoutingConfig = serde_json::from_str(&json).unwrap();
assert_eq!(config, parsed);
}
#[test]
fn routing_config_default() {
let config = RoutingConfig::default();
assert!(config.fallback.is_empty());
assert_eq!(config.strategy, None);
}
}