Expand description
§Module: Orchestrator
§Responsibility
Provides a composable LLM pipeline with circuit breaking, retry, deduplication,
and backpressure. Mirrors the public API of tokio-prompt-orchestrator.
§Guarantees
- Thread-safe: all types wrap state in
Arc<Mutex<_>>or atomics - Circuit breaker opens after
thresholdconsecutive failures - RetryPolicy delays grow exponentially and are capped at
MAX_RETRY_DELAY - Deduplicator is deterministic and non-blocking
- BackpressureGuard never exceeds declared hard capacity
- Non-panicking: all operations return
Result
§NOT Responsible For
- Cross-node circuit breakers (single-process only, unless a distributed backend is provided)
- Persistent deduplication (in-memory, bounded TTL)
- Distributed backpressure
§Composing the Primitives
The four primitives are designed to be layered. A typical production setup:
request
│
▼
BackpressureGuard ← shed if too many in-flight requests
│
▼
Deduplicator ← return cached result for duplicate keys
│
▼
CircuitBreaker ← fast-fail if the downstream is unhealthy
│
▼
RetryPolicy ← retry transient failures with exponential backoff
│
▼
Pipeline ← transform request/response through named stagesStructs§
- Backpressure
Guard - Tracks in-flight work count and enforces a capacity limit.
- Circuit
Breaker - Circuit breaker guarding a fallible operation.
- Deduplicator
- Deduplicates requests by key within a TTL window.
- InMemory
Circuit Breaker Backend - In-process circuit breaker backend backed by a
Mutex<HashMap>. - Pipeline
- A composable pipeline that passes a string through a sequence of named stages.
- Pipeline
Result - Result of executing a pipeline, including per-stage timing.
- Retry
Policy - Configurable retry policy with exponential backoff or constant interval.
- Stage
- A single named stage in the pipeline.
Enums§
- Circuit
State - Tracks failure rates and opens when the threshold is exceeded.
- Deduplication
Result - Result of a deduplication check.
- Retry
Kind - Retry mode: exponential backoff or constant interval.
Constants§
- MAX_
RETRY_ DELAY - Maximum delay between retries — caps exponential growth.
Traits§
- Async
Circuit Breaker Backend - Async counterpart of
CircuitBreakerBackendfor distributed backends. - Circuit
Breaker Backend - Backend for circuit breaker state storage.