Class: AgentHarness::Response

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

Examples:

response = provider.send_message(prompt: "Hello")
if response.success?
  puts response.output
else
  puts "Error: #{response.error}"
end

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(output:, exit_code:, duration:, provider:, model: nil, tokens: nil, metadata: {}, error: nil) ⇒ Response

Create a new Response

Parameters:

  • output (String)

    the output from the provider

  • exit_code (Integer)

    the exit code (0 for success)

  • duration (Float)

    execution duration in seconds

  • provider (Symbol, String)

    the provider name

  • model (String, nil) (defaults to: nil)

    the model used

  • tokens (Hash, nil) (defaults to: nil)

    token usage information

  • metadata (Hash) (defaults to: {})

    additional metadata

  • error (String, nil) (defaults to: nil)

    error message if failed



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

#durationObject (readonly)

Returns the value of attribute duration.



16
17
18
# File 'lib/agent_harness/response.rb', line 16

def duration
  @duration
end

#errorObject (readonly)

Returns the value of attribute error.



17
18
19
# File 'lib/agent_harness/response.rb', line 17

def error
  @error
end

#exit_codeObject (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

#metadataObject (readonly)

Returns the value of attribute metadata.



17
18
19
# File 'lib/agent_harness/response.rb', line 17

def 
  @metadata
end

#modelObject (readonly)

Returns the value of attribute model.



16
17
18
# File 'lib/agent_harness/response.rb', line 16

def model
  @model
end

#outputObject (readonly)

Returns the value of attribute output.



16
17
18
# File 'lib/agent_harness/response.rb', line 16

def output
  @output
end

#providerObject (readonly)

Returns the value of attribute provider.



16
17
18
# File 'lib/agent_harness/response.rb', line 16

def provider
  @provider
end

#tokensObject (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

Returns:

  • (Boolean)

    true if not successful



51
52
53
# File 'lib/agent_harness/response.rb', line 51

def failed?
  !success?
end

#input_tokensInteger?

Get input tokens used

Returns:

  • (Integer, nil)

    input tokens or nil if not tracked



65
66
67
# File 'lib/agent_harness/response.rb', line 65

def input_tokens
  @tokens&.[](:input)
end

#inspectString

String representation for debugging

Returns:

  • (String)

    debug string



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_tokensInteger?

Get output tokens used

Returns:

  • (Integer, nil)

    output tokens or nil if not tracked



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

Returns:

  • (Boolean)

    true if exit_code is 0 and no error



44
45
46
# File 'lib/agent_harness/response.rb', line 44

def success?
  @exit_code == 0 && @error.nil?
end

#to_hHash

Convert to hash representation

Returns:

  • (Hash)

    hash representation of the response



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_tokensInteger?

Get total tokens used

Returns:

  • (Integer, nil)

    total tokens or nil if not tracked



58
59
60
# File 'lib/agent_harness/response.rb', line 58

def total_tokens
  @tokens&.[](:total)
end