Class: Agentic::RetryConfig
- Inherits:
-
Object
- Object
- Agentic::RetryConfig
- Defined in:
- lib/agentic/retry_config.rb
Overview
Configuration object for the RetryHandler
Instance Attribute Summary collapse
-
#after_retry ⇒ Proc?
Optional block to run after each retry.
-
#backoff_options ⇒ Hash
Options for the backoff strategy.
-
#backoff_strategy ⇒ Symbol
The backoff strategy to use.
-
#before_retry ⇒ Proc?
Optional block to run before each retry.
-
#max_retries ⇒ Integer
The maximum number of retry attempts.
-
#retryable_errors ⇒ Array<Class, String>
List of retryable error types/names.
Instance Method Summary collapse
-
#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
constructor
Initializes a new retry configuration.
-
#to_handler ⇒ RetryHandler
Creates a RetryHandler from this configuration.
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
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() @before_retry = before_retry @after_retry = after_retry end |
Instance Attribute Details
#after_retry ⇒ Proc?
Returns 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_options ⇒ Hash
Returns Options for the backoff strategy.
16 17 18 |
# File 'lib/agentic/retry_config.rb', line 16 def @backoff_options end |
#backoff_strategy ⇒ Symbol
Returns The backoff strategy to use.
13 14 15 |
# File 'lib/agentic/retry_config.rb', line 13 def backoff_strategy @backoff_strategy end |
#before_retry ⇒ Proc?
Returns 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_retries ⇒ Integer
Returns The maximum number of retry attempts.
7 8 9 |
# File 'lib/agentic/retry_config.rb', line 7 def max_retries @max_retries end |
#retryable_errors ⇒ Array<Class, String>
Returns 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_handler ⇒ RetryHandler
Creates a RetryHandler from this configuration
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 |