Skip to main content

brainwires_call_policy/
lib.rs

1#![deny(missing_docs)]
2//! Provider-layer resilience middleware for the Brainwires Agent Framework.
3//!
4//! Wraps any `brainwires_core::Provider` with composable decorators:
5//!
6//! - [`RetryProvider`] — exponential backoff with jitter on transient failures.
7//! - [`BudgetProvider`] — atomic token/USD/round caps with pre-flight rejection.
8//! - [`CircuitBreakerProvider`] — half-open state machine, optional fallback.
9//!
10//! Decorators wrap `Arc<dyn Provider>` and return `Arc<dyn Provider>`, so they
11//! compose freely. Typical stacking (outermost first):
12//!
13//! ```text
14//! CircuitBreaker → Retry → Budget → base Provider
15//! ```
16
17mod budget;
18mod cache;
19mod circuit;
20mod classify;
21mod error;
22mod retry;
23
24#[cfg(test)]
25mod tests_util;
26
27pub use budget::{BudgetConfig, BudgetGuard, BudgetProvider};
28#[cfg(feature = "cache")]
29pub use cache::SqliteCache;
30pub use cache::{
31    CacheBackend, CacheKey, CachedProvider, CachedResponse, MemoryCache, cache_key_for,
32};
33pub use circuit::{CircuitBreakerConfig, CircuitBreakerProvider, CircuitState};
34pub use classify::{ErrorClass, classify_error};
35pub use error::ResilienceError;
36pub use retry::{RetryPolicy, RetryProvider};