Skip to content

Resilience

Retry failed agent runs with exponential backoff:

import { withRetry } from 'agentfootprint/resilience';
const reliable = withRetry(agent, {
maxRetries: 3,
backoffMs: 1000,
});
await reliable.run('Hello');

Fall back to a cheaper/faster agent when the primary fails:

import { withFallback } from 'agentfootprint/resilience';
const resilient = withFallback(primaryAgent, cheapAgent);
await resilient.run('Hello');

Stop calling a failing provider after N consecutive failures:

import { withCircuitBreaker } from 'agentfootprint/resilience';
const guarded = withCircuitBreaker(agent, {
threshold: 5, // open after 5 failures
resetAfterMs: 30000, // probe after 30s
});

Cross-family failover: Claude, GPT-4o, local Ollama:

import { anthropic, openai, ollama } from 'agentfootprint';
import { fallbackProvider } from 'agentfootprint/resilience';
const provider = fallbackProvider([
anthropic('claude-sonnet-4-20250514'),
openai('gpt-4o'),
ollama('llama3'),
]);
const agent = Agent.create({ provider }).build();