Class: PatientLLM::Agent::Failure

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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

#contextPatientHttp::CallbackArgs (readonly)

Returns the context passed to ask/continue.

Returns:

  • (PatientHttp::CallbackArgs)

    the context passed to ask/continue



27
28
29
# File 'lib/patient_llm/agent/failure.rb', line 27

def context
  @context
end

#errorPatientHttp::Error (readonly)

Returns the underlying error; exposes error_type, message, error_class, and request_id.

Returns:

  • (PatientHttp::Error)

    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_idString? (readonly)

Returns the request id of the HTTP exchange. May be nil for non-HTTP errors.

Returns:

  • (String, nil)

    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_responsePatientHttp::Response? (readonly)

Returns the HTTP response for HTTP errors; nil for non-HTTP errors (timeouts, connection failures).

Returns:

  • (PatientHttp::Response, nil)

    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

#sessionPromptBuilder::Session (readonly)

Returns the session at the time of the failure.

Returns:

  • (PromptBuilder::Session)

    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].

Parameters:

  • key (String, Symbol)

    the context key

Returns:

  • (Object)

    the context value

Raises:

  • (KeyError)

    if the key is not in the context



43
44
45
# File 'lib/patient_llm/agent/failure.rb', line 43

def [](key)
  context[key]
end

#error_classString?

The class name of the original exception.

Returns:

  • (String, nil)


64
65
66
# File 'lib/patient_llm/agent/failure.rb', line 64

def error_class
  error.error_class
end

#error_typeSymbol?

The category of the error (e.g. :timeout, :client_error).

Returns:

  • (Symbol, nil)


50
51
52
# File 'lib/patient_llm/agent/failure.rb', line 50

def error_type
  error.error_type
end

#messageString

The error message.

Returns:

  • (String)


57
58
59
# File 'lib/patient_llm/agent/failure.rb', line 57

def message
  error.message
end

#stateHash

The JSON-native session state at the time of the failure.

Returns:

  • (Hash)


71
72
73
# File 'lib/patient_llm/agent/failure.rb', line 71

def state
  session.to_h
end