Retry & Error Handling Kit

Configurable retry strategies with exponential backoff, circuit breakers, and error classification.

Configuration

3
60%

Integration Code

import { withRetry, CircuitBreaker } from 'agent-tools-kit/execution'

const result = await withRetry(
  () => callExternalApi(),
  {
    strategy: 'exponential',
    maxAttempts: 3,
    initialDelay: 500,
    maxDelay: 30000,
    retryOn: ['ETIMEDOUT', 'ECONNREFUSED', 429, 500, 502, 503],
    circuitBreaker: true ? new CircuitBreaker({
      threshold: 5,      // open after 5 consecutive failures
      resetTimeout: 30000, // try again after 30s
    }) : undefined,
    onRetry: (attempt, error) => {
      logger.warn('Retrying', { attempt, error: error.message })
    },
  }
)