Class: AgentHarness::Response
- Inherits:
-
Object
- Object
- AgentHarness::Response
- Defined in:
- lib/agent_harness/response.rb
Overview
Response object returned from provider send_message calls
Contains the output, status, and metadata from a provider interaction.
Instance Attribute Summary collapse
-
#duration ⇒ Object
readonly
Returns the value of attribute duration.
-
#error ⇒ Object
readonly
Returns the value of attribute error.
-
#exit_code ⇒ Object
readonly
Returns the value of attribute exit_code.
-
#metadata ⇒ Object
readonly
Returns the value of attribute metadata.
-
#model ⇒ Object
readonly
Returns the value of attribute model.
-
#output ⇒ Object
readonly
Returns the value of attribute output.
-
#provider ⇒ Object
readonly
Returns the value of attribute provider.
-
#tokens ⇒ Object
readonly
Returns the value of attribute tokens.
Instance Method Summary collapse
-
#failed? ⇒ Boolean
Check if the response indicates failure.
-
#initialize(output:, exit_code:, duration:, provider:, model: nil, tokens: nil, metadata: {}, error: nil) ⇒ Response
constructor
Create a new Response.
-
#input_tokens ⇒ Integer?
Get input tokens used.
-
#inspect ⇒ String
String representation for debugging.
-
#output_tokens ⇒ Integer?
Get output tokens used.
-
#success? ⇒ Boolean
Check if the response indicates success.
-
#to_h ⇒ Hash
Convert to hash representation.
-
#total_tokens ⇒ Integer?
Get total tokens used.
Constructor Details
#initialize(output:, exit_code:, duration:, provider:, model: nil, tokens: nil, metadata: {}, error: nil) ⇒ Response
Create a new Response
29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/agent_harness/response.rb', line 29 def initialize(output:, exit_code:, duration:, provider:, model: nil, tokens: nil, metadata: {}, error: nil) @output = output @exit_code = exit_code @duration = duration @provider = provider.to_sym @model = model @tokens = tokens @metadata = @error = error end |
Instance Attribute Details
#duration ⇒ Object (readonly)
Returns the value of attribute duration.
16 17 18 |
# File 'lib/agent_harness/response.rb', line 16 def duration @duration end |
#error ⇒ Object (readonly)
Returns the value of attribute error.
17 18 19 |
# File 'lib/agent_harness/response.rb', line 17 def error @error end |
#exit_code ⇒ Object (readonly)
Returns the value of attribute exit_code.
16 17 18 |
# File 'lib/agent_harness/response.rb', line 16 def exit_code @exit_code end |
#metadata ⇒ Object (readonly)
Returns the value of attribute metadata.
17 18 19 |
# File 'lib/agent_harness/response.rb', line 17 def @metadata end |
#model ⇒ Object (readonly)
Returns the value of attribute model.
16 17 18 |
# File 'lib/agent_harness/response.rb', line 16 def model @model end |
#output ⇒ Object (readonly)
Returns the value of attribute output.
16 17 18 |
# File 'lib/agent_harness/response.rb', line 16 def output @output end |
#provider ⇒ Object (readonly)
Returns the value of attribute provider.
16 17 18 |
# File 'lib/agent_harness/response.rb', line 16 def provider @provider end |
#tokens ⇒ Object (readonly)
Returns the value of attribute tokens.
17 18 19 |
# File 'lib/agent_harness/response.rb', line 17 def tokens @tokens end |
Instance Method Details
#failed? ⇒ Boolean
Check if the response indicates failure
51 52 53 |
# File 'lib/agent_harness/response.rb', line 51 def failed? !success? end |
#input_tokens ⇒ Integer?
Get input tokens used
65 66 67 |
# File 'lib/agent_harness/response.rb', line 65 def input_tokens @tokens&.[](:input) end |
#inspect ⇒ String
String representation for debugging
96 97 98 |
# File 'lib/agent_harness/response.rb', line 96 def inspect "#<AgentHarness::Response provider=#{@provider} success=#{success?} duration=#{@duration.round(2)}s>" end |
#output_tokens ⇒ Integer?
Get output tokens used
72 73 74 |
# File 'lib/agent_harness/response.rb', line 72 def output_tokens @tokens&.[](:output) end |
#success? ⇒ Boolean
Check if the response indicates success
44 45 46 |
# File 'lib/agent_harness/response.rb', line 44 def success? @exit_code == 0 && @error.nil? end |
#to_h ⇒ Hash
Convert to hash representation
79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/agent_harness/response.rb', line 79 def to_h { output: @output, exit_code: @exit_code, duration: @duration, provider: @provider, model: @model, tokens: @tokens, metadata: @metadata, error: @error, success: success? } end |
#total_tokens ⇒ Integer?
Get total tokens used
58 59 60 |
# File 'lib/agent_harness/response.rb', line 58 def total_tokens @tokens&.[](:total) end |