Class: Agentic::RetryConfig

Inherits:
Object
  • Object
show all
Defined in:
lib/agentic/retry_config.rb

Overview

Configuration object for the RetryHandler

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(max_retries: 3, retryable_errors: [Errors::LlmTimeoutError, Errors::LlmRateLimitError, Errors::LlmServerError, Errors::LlmNetworkError], backoff_strategy: :exponential, backoff_options: {}, before_retry: nil, after_retry: nil) ⇒ RetryConfig

Initializes a new retry configuration

Parameters:

  • max_retries (Integer) (defaults to: 3)

    The maximum number of retry attempts

  • retryable_errors (Array<Class, String>) (defaults to: [Errors::LlmTimeoutError, Errors::LlmRateLimitError, Errors::LlmServerError, Errors::LlmNetworkError])

    List of retryable error types/names

  • backoff_strategy (Symbol) (defaults to: :exponential)

    The backoff strategy (:constant, :linear, :exponential)

  • backoff_options (Hash) (defaults to: {})

    Options for the backoff strategy

  • before_retry (Proc, nil) (defaults to: nil)

    Optional block to run before each retry

  • after_retry (Proc, nil) (defaults to: nil)

    Optional block to run after each retry



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/agentic/retry_config.rb', line 31

def initialize(
  max_retries: 3,
  retryable_errors: [Errors::LlmTimeoutError, Errors::LlmRateLimitError, Errors::LlmServerError, Errors::LlmNetworkError],
  backoff_strategy: :exponential,
  backoff_options: {},
  before_retry: nil,
  after_retry: nil
)
  @max_retries = max_retries
  @retryable_errors = retryable_errors
  @backoff_strategy = backoff_strategy
  @backoff_options = {
    base_delay: 1.0,
    jitter_factor: 0.25
  }.merge(backoff_options)
  @before_retry = before_retry
  @after_retry = after_retry
end

Instance Attribute Details

#after_retryProc?

Returns Optional block to run after each retry.

Returns:

  • (Proc, nil)

    Optional block to run after each retry



22
23
24
# File 'lib/agentic/retry_config.rb', line 22

def after_retry
  @after_retry
end

#backoff_optionsHash

Returns Options for the backoff strategy.

Returns:

  • (Hash)

    Options for the backoff strategy



16
17
18
# File 'lib/agentic/retry_config.rb', line 16

def backoff_options
  @backoff_options
end

#backoff_strategySymbol

Returns The backoff strategy to use.

Returns:

  • (Symbol)

    The backoff strategy to use



13
14
15
# File 'lib/agentic/retry_config.rb', line 13

def backoff_strategy
  @backoff_strategy
end

#before_retryProc?

Returns Optional block to run before each retry.

Returns:

  • (Proc, nil)

    Optional block to run before each retry



19
20
21
# File 'lib/agentic/retry_config.rb', line 19

def before_retry
  @before_retry
end

#max_retriesInteger

Returns The maximum number of retry attempts.

Returns:

  • (Integer)

    The maximum number of retry attempts



7
8
9
# File 'lib/agentic/retry_config.rb', line 7

def max_retries
  @max_retries
end

#retryable_errorsArray<Class, String>

Returns List of retryable error types/names.

Returns:

  • (Array<Class, String>)

    List of retryable error types/names



10
11
12
# File 'lib/agentic/retry_config.rb', line 10

def retryable_errors
  @retryable_errors
end

Instance Method Details

#to_handlerRetryHandler

Creates a RetryHandler from this configuration

Returns:



52
53
54
55
56
57
58
59
60
61
# File 'lib/agentic/retry_config.rb', line 52

def to_handler
  RetryHandler.new(
    max_retries: @max_retries,
    retryable_errors: @retryable_errors,
    backoff_strategy: @backoff_strategy,
    backoff_options: @backoff_options,
    before_retry: @before_retry,
    after_retry: @after_retry
  )
end