Overview
OneClaw provides two wrapper types for building resilient multi-provider systems:FallbackChain- Try providers in order until one succeedsReliableProvider- Wrap any provider with automatic retry logic
FallbackChain
Try multiple providers in order until one succeeds.Concept
AFallbackChain wraps multiple providers and attempts each in sequence:
- Check if provider is available (
is_available()) - Skip unavailable providers
- Try to call the provider
- On error, log and try next provider
- Return first successful response
- If all fail, return error
Construction
Provider Strategy
OneClaw’s recommended fallback strategy:Methods
new(providers: Vec<Box<dyn Provider>>) -> Self
Create a new fallback chain from an ordered list of providers.
len() -> usize
Number of providers in the chain.
is_empty() -> bool
Whether the chain has no providers.
provider_info() -> String
Return a string showing the provider sequence: "anthropic → openai → ollama".
Provider Trait Implementation
FallbackChain implements Provider, so it can be used anywhere a Provider is expected:
Behavior
Availability Check
Chat Method
Use Cases
Multi-Cloud Redundancy
Cloud + Local Hybrid
Cost Optimization
ReliableProvider
Wrap any provider with automatic retry logic.Concept
AReliableProvider wraps a single provider and retries failed requests automatically:
- Try to call the inner provider
- On error, log warning and retry
- Repeat up to
max_retriestimes - Return first successful response
- If all attempts fail, return last error
Construction
Retry Logic
Total attempts = 1 (initial) +max_retries
Example with max_retries = 2:
max_retries = 2 (all fail):
Methods
new(inner: P, max_retries: u32) -> Self
Create a new reliable provider wrapping inner with max_retries retry attempts.
Provider Trait Implementation
Use Cases
Transient Network Errors
Rate Limit Handling
API Flakiness
Combining FallbackChain + ReliableProvider
Build ultra-resilient systems by combining both:Resilience Levels
| Configuration | Resilience | Max Attempts |
|---|---|---|
| Single provider | None | 1 |
ReliableProvider(provider, 2) | Low | 3 |
FallbackChain([p1, p2, p3]) | Medium | 3 |
FallbackChain([Reliable(p1), Reliable(p2), Reliable(p3)]) | High | 9+ |
Chain Builder (Config-Driven)
OneClaw provides a config-driven chain builder:chain_builder.rs source for implementation details.
Logging and Observability
BothFallbackChain and ReliableProvider emit structured logs via tracing:
Recommended Logging Setup
Best Practices
1. Order Providers by Preference
Place highest-quality/fastest providers first:2. Always Include Local Fallback
Ensure system works offline:3. Limit Retries
Avoid excessive retries (increases latency):4. Monitor Fallback Usage
Log when fallback activates to detect primary provider issues:5. Test Failure Scenarios
Graceful Degradation Example
Complete production-ready setup:- ✅ High quality (Claude primary)
- ✅ Cost efficiency (DeepSeek secondary)
- ✅ Offline capability (Ollama tertiary)
- ✅ Automatic retries (2 per provider)
- ✅ Graceful degradation (9+ total attempts)
- ✅ Zero downtime (always has fallback)