Class: PatientLLM::Agent::Failure
- Inherits:
-
Object
- Object
- PatientLLM::Agent::Failure
- Defined in:
- lib/patient_llm/agent/failure.rb
Overview
The failure delivered to an agent's failed hook. Wraps the error together with the rest of the invocation state so the hook has one object with everything it needs: the error itself, the HTTP exchange (when there was one), the context passed to ask/continue, and the serializable conversation state.
Instance Attribute Summary collapse
-
#context ⇒ PatientHttp::CallbackArgs
readonly
The context passed to ask/continue.
-
#error ⇒ PatientHttp::Error
readonly
The underlying error; exposes error_type, message, error_class, and request_id.
-
#http_request_id ⇒ String?
readonly
The request id of the HTTP exchange.
-
#http_response ⇒ PatientHttp::Response?
readonly
The HTTP response for HTTP errors; nil for non-HTTP errors (timeouts, connection failures).
-
#session ⇒ PromptBuilder::Session
readonly
The session at the time of the failure.
Instance Method Summary collapse
-
#[](key) ⇒ Object
A value from the context passed to ask/continue.
-
#error_class ⇒ String?
The class name of the original exception.
-
#error_type ⇒ Symbol?
The category of the error (e.g. :timeout, :client_error).
-
#initialize(error, session:, http_response: nil, http_request_id: nil, context: nil) ⇒ Failure
constructor
A new instance of Failure.
-
#message ⇒ String
The error message.
-
#state ⇒ Hash
The JSON-native session state at the time of the failure.
Constructor Details
#initialize(error, session:, http_response: nil, http_request_id: nil, context: nil) ⇒ Failure
Returns a new instance of Failure.
29 30 31 32 33 34 35 |
# File 'lib/patient_llm/agent/failure.rb', line 29 def initialize(error, session:, http_response: nil, http_request_id: nil, context: nil) @error = error @session = session @http_response = http_response @http_request_id = http_request_id @context = context || PatientHttp::CallbackArgs.new end |
Instance Attribute Details
#context ⇒ PatientHttp::CallbackArgs (readonly)
Returns the context passed to ask/continue.
27 28 29 |
# File 'lib/patient_llm/agent/failure.rb', line 27 def context @context end |
#error ⇒ PatientHttp::Error (readonly)
Returns the underlying error; exposes error_type, message, error_class, and request_id.
13 14 15 |
# File 'lib/patient_llm/agent/failure.rb', line 13 def error @error end |
#http_request_id ⇒ String? (readonly)
Returns the request id of the HTTP exchange. May be nil for non-HTTP errors.
24 25 26 |
# File 'lib/patient_llm/agent/failure.rb', line 24 def http_request_id @http_request_id end |
#http_response ⇒ PatientHttp::Response? (readonly)
Returns the HTTP response for HTTP errors; nil for non-HTTP errors (timeouts, connection failures).
20 21 22 |
# File 'lib/patient_llm/agent/failure.rb', line 20 def http_response @http_response end |
#session ⇒ PromptBuilder::Session (readonly)
Returns the session at the time of the failure.
16 17 18 |
# File 'lib/patient_llm/agent/failure.rb', line 16 def session @session end |
Instance Method Details
#[](key) ⇒ Object
A value from the context passed to ask/continue. Shorthand for
failure.context[key].
43 44 45 |
# File 'lib/patient_llm/agent/failure.rb', line 43 def [](key) context[key] end |
#error_class ⇒ String?
The class name of the original exception.
64 65 66 |
# File 'lib/patient_llm/agent/failure.rb', line 64 def error_class error.error_class end |
#error_type ⇒ Symbol?
The category of the error (e.g. :timeout, :client_error).
50 51 52 |
# File 'lib/patient_llm/agent/failure.rb', line 50 def error_type error.error_type end |
#message ⇒ String
The error message.
57 58 59 |
# File 'lib/patient_llm/agent/failure.rb', line 57 def error. end |
#state ⇒ Hash
The JSON-native session state at the time of the failure.
71 72 73 |
# File 'lib/patient_llm/agent/failure.rb', line 71 def state session.to_h end |