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 ofretries max:fallback to:instead offallback_modelscircuit_breaker after:instead ofcircuit_breaker errors:timeoutinstead oftotal_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.
394 395 396 397 398 399 400 401 402 |
# File 'lib/ruby_llm/agents/dsl/reliability.rb', line 394 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.
390 391 392 |
# File 'lib/ruby_llm/agents/dsl/reliability.rb', line 390 def circuit_breaker_config @circuit_breaker_config end |
#fallback_models_list ⇒ Object (readonly)
Returns the value of attribute fallback_models_list.
390 391 392 |
# File 'lib/ruby_llm/agents/dsl/reliability.rb', line 390 def fallback_models_list @fallback_models_list end |
#fallback_providers_list ⇒ Object (readonly)
Returns the value of attribute fallback_providers_list.
390 391 392 |
# File 'lib/ruby_llm/agents/dsl/reliability.rb', line 390 def fallback_providers_list @fallback_providers_list end |
#non_fallback_errors_list ⇒ Object (readonly)
Returns the value of attribute non_fallback_errors_list.
390 391 392 |
# File 'lib/ruby_llm/agents/dsl/reliability.rb', line 390 def non_fallback_errors_list @non_fallback_errors_list end |
#retries_config ⇒ Object (readonly)
Returns the value of attribute retries_config.
390 391 392 |
# File 'lib/ruby_llm/agents/dsl/reliability.rb', line 390 def retries_config @retries_config end |
#retryable_patterns_list ⇒ Object (readonly)
Returns the value of attribute retryable_patterns_list.
390 391 392 |
# File 'lib/ruby_llm/agents/dsl/reliability.rb', line 390 def retryable_patterns_list @retryable_patterns_list end |
#total_timeout_value ⇒ Object (readonly)
Returns the value of attribute total_timeout_value.
390 391 392 |
# File 'lib/ruby_llm/agents/dsl/reliability.rb', line 390 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
482 483 484 485 486 487 488 489 490 491 |
# File 'lib/ruby_llm/agents/dsl/reliability.rb', line 482 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
433 434 435 |
# File 'lib/ruby_llm/agents/dsl/reliability.rb', line 433 def fallback(to:) @fallback_models_list = Array(to) end |
#fallback_models(*models) ⇒ Object
Also support fallback_models for compatibility
438 439 440 |
# File 'lib/ruby_llm/agents/dsl/reliability.rb', line 438 def fallback_models(*models) @fallback_models_list = models.flatten end |
#fallback_provider(provider, **options) ⇒ Object
Configure a fallback provider (for audio agents)
447 448 449 |
# File 'lib/ruby_llm/agents/dsl/reliability.rb', line 447 def fallback_provider(provider, **) @fallback_providers_list << {provider: provider, **} end |
#non_fallback_errors(*error_classes) ⇒ Object
Configure errors that should never trigger fallback
499 500 501 |
# File 'lib/ruby_llm/agents/dsl/reliability.rb', line 499 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
415 416 417 418 419 420 421 422 423 |
# File 'lib/ruby_llm/agents/dsl/reliability.rb', line 415 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
494 495 496 |
# File 'lib/ruby_llm/agents/dsl/reliability.rb', line 494 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
459 460 461 462 463 464 465 466 |
# File 'lib/ruby_llm/agents/dsl/reliability.rb', line 459 def timeout(duration) # Handle ActiveSupport::Duration @total_timeout_value = if duration == false false else duration.respond_to?(:to_i) ? duration.to_i : duration end end |