RetryPolicy

org.llm4s.reliability.RetryPolicy
See theRetryPolicy companion object
@Stable
sealed trait RetryPolicy

Retry policy for transient failures.

Defines how many times to retry and how long to wait between attempts.

Attributes

Companion
object
Graph
Supertypes
class Object
trait Matchable
class Any

Members list

Value members

Abstract methods

def delayFor(attemptNumber: Int, error: LLMError): FiniteDuration

Calculate delay before next retry attempt.

Calculate delay before next retry attempt.

Value parameters

attemptNumber

The attempt number (1-indexed)

error

The error that triggered the retry

Attributes

Returns

Delay duration before next attempt

def maxAttempts: Int

Maximum number of retry attempts

Maximum number of retry attempts

Attributes

Concrete methods

def isRetryable(error: LLMError): Boolean

Check if an error is retryable: whether the identical request is worth sending again, with nobody in the loop.

Check if an error is retryable: whether the identical request is worth sending again, with nobody in the loop.

This is the library's one rule for automatic retry, and LLMClientRetry and the agent graph's node retries use it too. It is derived from org.llm4s.error.LLMError.isRecoverable, never wider: an error is retried only if it is a org.llm4s.error.RecoverableError. isRecoverable says an error may succeed if tried again, perhaps after the caller does something first; this rule keeps the part where repeating the same request is enough. A recoverable error is therefore retried unless one of two documented exceptions applies:

So the retried errors are org.llm4s.error.RateLimitError, org.llm4s.error.TimeoutError, org.llm4s.error.NetworkError, org.llm4s.error.ExecutionError, org.llm4s.error.SystemError, an APIError or ServiceError with a retryable status, and an APIError without one. Every org.llm4s.error.NonRecoverableError is not, including org.llm4s.error.CancelledError.

Attributes