Module: AgentHarness::Api::ErrorClassifier

Defined in:
lib/agent_harness/api/chat_transport.rb

Constant Summary collapse

TRANSIENT =
{
  Faraday::TimeoutError => :timeout,
  Faraday::ConnectionFailed => :connection_failed,
  Faraday::SSLError => :connection_failed,
  RubyLLM::RateLimitError => :rate_limited,
  RubyLLM::ServerError => :server_error,
  RubyLLM::ServiceUnavailableError => :service_unavailable,
  RubyLLM::OverloadedError => :overloaded
}.freeze
NON_RETRYABLE =
{
  RubyLlmChatAdapter::MissingCredentialError => [:authentication, :invalid_credential],
  RubyLLM::UnauthorizedError => [:authentication, :invalid_credential],
  RubyLLM::ForbiddenError => [:authorization, :permission_denied],
  RubyLLM::PaymentRequiredError => [:billing, :billing_unavailable],
  RubyLLM::ContextLengthExceededError => [:context_length, :context_length_exceeded],
  RubyLLM::BadRequestError => [:invalid_request, :invalid_request],
  RubyLlmChatAdapter::UnsupportedOptionError => [:unsupported, :unsupported_capability],
  RubyLLM::UnsupportedServerToolError => [:unsupported, :unsupported_capability],
  RubyLLM::ToolCallParseError => [:invalid_response, :invalid_tool_arguments],
  JSON::ParserError => [:invalid_response, :invalid_tool_arguments],
  RubyLLM::ModelNotFoundError => [:configuration, :invalid_configuration],
  RubyLLM::ConfigurationError => [:configuration, :invalid_configuration],
  RubyLLM::CancelledError => [:cancelled, :cancelled]
}.freeze

Class Method Summary collapse

Class Method Details

.call(error) ⇒ Object



469
470
471
472
473
474
475
476
477
# File 'lib/agent_harness/api/chat_transport.rb', line 469

def self.call(error)
  transient = TRANSIENT.find { |klass, _| error.is_a?(klass) }
  return payload(error, :transient, transient.last, true) if transient

  permanent = NON_RETRYABLE.find { |klass, _| error.is_a?(klass) }
  return payload(error, *permanent.last, false) if permanent

  payload(error, :unknown, :unclassified_provider_error, false)
end