Skip to main content

Crate rullama_call_policy

Crate rullama_call_policy 

Source
Expand description

Provider-layer resilience middleware for the rullama.

Wraps any rullama_core::Provider with composable decorators:

Decorators wrap Arc<dyn Provider> and return Arc<dyn Provider>, so they compose freely. Typical stacking (outermost first):

CircuitBreaker → Retry → Budget → base Provider

Structs§

BudgetConfig
Caps to enforce on a single BudgetGuard.
BudgetGuard
Shared atomic budget counters.
BudgetProvider
A Provider decorator that enforces a BudgetGuard around every call.
CacheKey
Key used to address a cached response.
CachedProvider
A Provider decorator that deduplicates identical chat() calls.
CachedResponse
Wire representation of a cached response, suitable for JSON storage.
CircuitBreakerConfig
Circuit-breaker configuration.
CircuitBreakerProvider
Circuit-breaker decorator around any Provider.
FailoverProvider
Decorator that walks through a list of providers, returning the first success.
HeuristicTokenizer
Cheap fallback: chars / 4. Matches the original approx_input_tokens behaviour; safe to use when no provider-specific tokenizer is wired up.
KeyedBudgetGuard
Per-caller budget tracking. Each unique K (e.g. user_id, tenant_id) gets its own private BudgetGuard with the same per-key caps.
MemoryCache
In-memory cache — the default backend. Cheap to Arc-clone.
RetryPolicy
Configuration for retry behavior.
RetryProvider
A Provider decorator that retries transient failures with exponential backoff and optional jitter.

Enums§

CircuitState
Circuit-breaker state for a single provider/model key.
ErrorClass
Coarse error classification used by retry and circuit-breaker logic.
ResilienceError
Errors surfaced by resilience decorators.

Traits§

CacheBackend
Pluggable storage backend behind CachedProvider.
Tokenizer
Counts tokens in a Message slice the way a particular provider would see them. Implementations are pure (no I/O) and cheap enough to call per pre-flight check.

Functions§

cache_key_for
Compute a stable cache key from the inputs to a chat() call.
classify_error
Classify an anyhow::Error by string inspection.