Resilience
Agentix includes configurable retry logic and circuit breakers to handle transient LLM failures and multi-worker deployments.
Retry configuration
from agentix import AgentixAgentOptions
options = AgentixAgentOptions(
retry_max_attempts=3, # default: 3
retry_base_delay=1.0, # initial delay in seconds (doubles each attempt)
retry_max_delay=30.0, # max delay cap
)
Circuit breaker
The circuit breaker prevents cascading failures by stopping LLM calls once a threshold of consecutive failures is reached.
options = AgentixAgentOptions(
circuit_breaker_failure_threshold=5, # default: 5; 0 = disabled
circuit_breaker_cooldown=60.0, # seconds before a probe is allowed
)
When the circuit is open, AgentixResilienceError is raised.
Circuit breaker backends
By default each AgentixClient instance uses an in-memory circuit breaker (no shared state). For multi-worker deployments, use a shared Redis backend:
from agentix import AgentixClient, AgentixAgentOptions
from agentix.resilience import (
InMemoryCircuitBreakerBackend,
RedisCircuitBreakerBackend,
AsyncRedisCircuitBreakerBackend,
)
# In-memory (default, per-instance)
client = AgentixClient(
options=options,
circuit_breaker_backend=InMemoryCircuitBreakerBackend(),
)
# Redis (sync) — shared across workers
client = AgentixClient(
options=options,
circuit_breaker_backend=RedisCircuitBreakerBackend(url="redis://localhost:6379/0"),
)
# Redis (async) — uses redis.asyncio
client = AgentixClient(
options=options,
circuit_breaker_backend=AsyncRedisCircuitBreakerBackend(url="redis://localhost:6379/0"),
)
Multi-tenant circuit breakers
The circuit breaker key is f"{tenant_id}:{options.provider}". Use tenant_id to scope state across tenants so one tenant's failures cannot trip another's circuit:
client = AgentixClient(
options=options,
tenant_id="customer-abc",
circuit_breaker_backend=shared_redis_backend,
)
Fallback model
Configure a fallback model for when the primary model fails after all retries:
options = AgentixAgentOptions(
provider="anthropic",
model="claude-opus-4-20250514",
fallback_model="claude-sonnet-4-20250514",
)
Token budget
Set a hard stop when total token usage exceeds a budget:
options = AgentixAgentOptions(
max_tokens_budget=100000, # hard stop at 100k total tokens
)