Class: RubyLLM::Agents::DSL::Reliability::OnFailureBuilder
- Inherits:
-
Object
- Object
- RubyLLM::Agents::DSL::Reliability::OnFailureBuilder
- Defined in:
- lib/ruby_llm/agents/dsl/reliability.rb
Overview
Builder class for on_failure block with simplified syntax
Uses more intuitive method names:
-
‘retry times:` instead of `retries max:`
-
‘fallback to:` instead of `fallback_models`
-
‘circuit_breaker after:` instead of `circuit_breaker errors:`
-
‘timeout` instead of `total_timeout`
Reliability DSL collapse
-
#circuit_breaker_config ⇒ Object
readonly
Returns the value of attribute circuit_breaker_config.
-
#fallback_models_list ⇒ Object
readonly
Returns the value of attribute fallback_models_list.
-
#fallback_providers_list ⇒ Object
readonly
Returns the value of attribute fallback_providers_list.
-
#non_fallback_errors_list ⇒ Object
readonly
Returns the value of attribute non_fallback_errors_list.
-
#retries_config ⇒ Object
readonly
Returns the value of attribute retries_config.
-
#retryable_patterns_list ⇒ Object
readonly
Returns the value of attribute retryable_patterns_list.
-
#total_timeout_value ⇒ Object
readonly
Returns the value of attribute total_timeout_value.
Reliability DSL collapse
-
#circuit_breaker(after: nil, errors: nil, within: 60, cooldown: 300) ⇒ Object
Configure circuit breaker.
-
#fallback(to:) ⇒ Object
Configure fallback models.
-
#fallback_models(*models) ⇒ Object
Also support fallback_models for compatibility.
-
#fallback_provider(provider, **options) ⇒ Object
Configure a fallback provider (for audio agents).
-
#initialize ⇒ OnFailureBuilder
constructor
A new instance of OnFailureBuilder.
-
#non_fallback_errors(*error_classes) ⇒ Object
Configure errors that should never trigger fallback.
-
#retries(times: 0, backoff: :exponential, base: 0.4, max_delay: 3.0, on: []) ⇒ Object
Configure retry behavior.
-
#retryable_patterns(*patterns) ⇒ Object
Configure additional retryable patterns.
-
#timeout(duration) ⇒ Object
(also: #total_timeout)
Configure timeout for all retry/fallback attempts.
Constructor Details
#initialize ⇒ OnFailureBuilder
Returns a new instance of OnFailureBuilder.
372 373 374 375 376 377 378 379 380 |
# File 'lib/ruby_llm/agents/dsl/reliability.rb', line 372 def initialize @retries_config = nil @fallback_models_list = [] @total_timeout_value = nil @circuit_breaker_config = nil @retryable_patterns_list = nil @fallback_providers_list = [] @non_fallback_errors_list = nil end |
Instance Attribute Details
#circuit_breaker_config ⇒ Object (readonly)
Returns the value of attribute circuit_breaker_config.
368 369 370 |
# File 'lib/ruby_llm/agents/dsl/reliability.rb', line 368 def circuit_breaker_config @circuit_breaker_config end |
#fallback_models_list ⇒ Object (readonly)
Returns the value of attribute fallback_models_list.
368 369 370 |
# File 'lib/ruby_llm/agents/dsl/reliability.rb', line 368 def fallback_models_list @fallback_models_list end |
#fallback_providers_list ⇒ Object (readonly)
Returns the value of attribute fallback_providers_list.
368 369 370 |
# File 'lib/ruby_llm/agents/dsl/reliability.rb', line 368 def fallback_providers_list @fallback_providers_list end |
#non_fallback_errors_list ⇒ Object (readonly)
Returns the value of attribute non_fallback_errors_list.
368 369 370 |
# File 'lib/ruby_llm/agents/dsl/reliability.rb', line 368 def non_fallback_errors_list @non_fallback_errors_list end |
#retries_config ⇒ Object (readonly)
Returns the value of attribute retries_config.
368 369 370 |
# File 'lib/ruby_llm/agents/dsl/reliability.rb', line 368 def retries_config @retries_config end |
#retryable_patterns_list ⇒ Object (readonly)
Returns the value of attribute retryable_patterns_list.
368 369 370 |
# File 'lib/ruby_llm/agents/dsl/reliability.rb', line 368 def retryable_patterns_list @retryable_patterns_list end |
#total_timeout_value ⇒ Object (readonly)
Returns the value of attribute total_timeout_value.
368 369 370 |
# File 'lib/ruby_llm/agents/dsl/reliability.rb', line 368 def total_timeout_value @total_timeout_value end |
Instance Method Details
#circuit_breaker(after: nil, errors: nil, within: 60, cooldown: 300) ⇒ Object
Configure circuit breaker
456 457 458 459 460 461 462 463 464 465 |
# File 'lib/ruby_llm/agents/dsl/reliability.rb', line 456 def circuit_breaker(after: nil, errors: nil, within: 60, cooldown: 300) error_threshold = after || errors || 10 cooldown_seconds = cooldown.respond_to?(:to_i) ? cooldown.to_i : cooldown @circuit_breaker_config = { errors: error_threshold, within: within, cooldown: cooldown_seconds } end |
#fallback(to:) ⇒ Object
Configure fallback models
411 412 413 |
# File 'lib/ruby_llm/agents/dsl/reliability.rb', line 411 def fallback(to:) @fallback_models_list = Array(to) end |
#fallback_models(*models) ⇒ Object
Also support fallback_models for compatibility
416 417 418 |
# File 'lib/ruby_llm/agents/dsl/reliability.rb', line 416 def fallback_models(*models) @fallback_models_list = models.flatten end |
#fallback_provider(provider, **options) ⇒ Object
Configure a fallback provider (for audio agents)
425 426 427 |
# File 'lib/ruby_llm/agents/dsl/reliability.rb', line 425 def fallback_provider(provider, **) @fallback_providers_list << {provider: provider, **} end |
#non_fallback_errors(*error_classes) ⇒ Object
Configure errors that should never trigger fallback
473 474 475 |
# File 'lib/ruby_llm/agents/dsl/reliability.rb', line 473 def non_fallback_errors(*error_classes) @non_fallback_errors_list = error_classes.flatten end |
#retries(times: 0, backoff: :exponential, base: 0.4, max_delay: 3.0, on: []) ⇒ Object
Configure retry behavior
393 394 395 396 397 398 399 400 401 |
# File 'lib/ruby_llm/agents/dsl/reliability.rb', line 393 def retries(times: 0, backoff: :exponential, base: 0.4, max_delay: 3.0, on: []) @retries_config = { max: times, backoff: backoff, base: base, max_delay: max_delay, on: on } end |
#retryable_patterns(*patterns) ⇒ Object
Configure additional retryable patterns
468 469 470 |
# File 'lib/ruby_llm/agents/dsl/reliability.rb', line 468 def retryable_patterns(*patterns) @retryable_patterns_list = patterns.flatten end |
#timeout(duration) ⇒ Object Also known as: total_timeout
Configure timeout for all retry/fallback attempts
437 438 439 440 |
# File 'lib/ruby_llm/agents/dsl/reliability.rb', line 437 def timeout(duration) # Handle ActiveSupport::Duration @total_timeout_value = duration.respond_to?(:to_i) ? duration.to_i : duration end |