Class: AgentHarness::Api::AttemptReport

Inherits:
Object
  • Object
show all
Defined in:
lib/agent_harness/api/attempt_report.rb

Overview

Serializable accounting facts for one physical provider request.

Constant Summary collapse

STATUSES =
i[succeeded failed cancelled partial].freeze
USAGE_KEYS =
i[input_tokens output_tokens cache_read_tokens cache_write_tokens thinking_tokens total_tokens].freeze
COST_KEYS =
i[input output cache_read cache_write thinking total].freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attempt_id:, request_id:, number:, provider:, model:, status:, started_at:, finished_at:, usage: nil, cost: nil, provider_reported: false, error: nil) ⇒ AttemptReport

Returns a new instance of AttemptReport.



27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/agent_harness/api/attempt_report.rb', line 27

def initialize(attempt_id:, request_id:, number:, provider:, model:, status:, started_at:, finished_at:,
  usage: nil, cost: nil, provider_reported: false, error: nil)
  @attributes = {
    attempt_id: attempt_id.to_s, request_id: request_id.to_s, number: number,
    provider: provider.to_sym, model: model&.to_s, status: status.to_sym,
    started_at: timestamp(started_at), finished_at: timestamp(finished_at),
    usage: normalize_usage(usage), cost: normalize_cost(cost),
    provider_reported: provider_reported == true, error: error
  }
  validate!
  deep_freeze(@attributes)
end

Instance Attribute Details

#attributes ⇒ Object (readonly)

Returns the value of attribute attributes.



13
14
15
# File 'lib/agent_harness/api/attempt_report.rb', line 13

def attributes
  @attributes
end

Class Method Details

.from_h(attributes) ⇒ Object



15
16
17
# File 'lib/agent_harness/api/attempt_report.rb', line 15

def self.from_h(attributes)
  new(**symbolize(attributes))
end

Instance Method Details

#to_h ⇒ Object



40
41
42
# File 'lib/agent_harness/api/attempt_report.rb', line 40

def to_h
  deep_dup(attributes)
end