LlmCore.Memory.Hindsight.Retry (llm_core v0.3.0)

Copy Markdown View Source

Retry logic with exponential backoff for Hindsight operations.

Features:

  • Configurable max retries and backoff timing
  • Jitter to prevent thundering herd
  • Retry classification (retry transient, fail fast on client errors)

Retry Classification

  • Retry: connection_refused, timeout, 5xx errors
  • No retry: 4xx errors, invalid response

Summary

Functions

Gets the delay for a specific retry attempt with jitter.

Determines if an error should be retried.

Wraps an operation with retry logic.

Types

retry_result()

@type retry_result() :: {:ok, term()} | {:error, term()}

Functions

get_delay(attempt, backoff_ms)

@spec get_delay(non_neg_integer(), [pos_integer()]) :: pos_integer()

Gets the delay for a specific retry attempt with jitter.

should_retry?(reason)

@spec should_retry?(term()) :: boolean()

Determines if an error should be retried.

with_retry(operation, opts \\ [])

@spec with_retry(
  (-> {:ok, term()} | {:error, term()}),
  keyword()
) :: retry_result()

Wraps an operation with retry logic.

Options

  • :max_retries - maximum retry attempts (default from config)
  • :backoff_ms - list of backoff delays in ms (default from config)

Example

Retry.with_retry(fn -> do_request() end, max_retries: 3)