Class: RubyLLM::Agents::TrackReport
- Inherits:
-
Object
- Object
- RubyLLM::Agents::TrackReport
- Defined in:
- lib/ruby_llm/agents/track_report.rb
Overview
Aggregated read-only report returned by RubyLLM::Agents.track.
Provides totals and breakdowns across all agent calls made inside the tracked block.
Instance Attribute Summary collapse
- #completed_at ⇒ Object readonly
- #error ⇒ Object readonly
- #request_id ⇒ Object readonly
- #results ⇒ Object readonly
- #started_at ⇒ Object readonly
- #value ⇒ Object readonly
Instance Method Summary collapse
- #all_successful? ⇒ Boolean
- #any_errors? ⇒ Boolean
- #call_count ⇒ Object
- #cost_breakdown ⇒ Object
- #duration_ms ⇒ Object
- #errors ⇒ Object
- #failed? ⇒ Boolean
-
#initialize(value:, error:, results:, request_id:, started_at:, completed_at:) ⇒ TrackReport
constructor
A new instance of TrackReport.
- #input_cost ⇒ Object
- #input_tokens ⇒ Object
- #models_used ⇒ Object
- #output_cost ⇒ Object
- #output_tokens ⇒ Object
- #successful ⇒ Object
- #successful? ⇒ Boolean
- #to_h ⇒ Object
- #total_cost ⇒ Object
- #total_tokens ⇒ Object
Constructor Details
#initialize(value:, error:, results:, request_id:, started_at:, completed_at:) ⇒ TrackReport
Returns a new instance of TrackReport.
23 24 25 26 27 28 29 30 |
# File 'lib/ruby_llm/agents/track_report.rb', line 23 def initialize(value:, error:, results:, request_id:, started_at:, completed_at:) @value = value @error = error @results = results.freeze @request_id = request_id @started_at = started_at @completed_at = completed_at end |
Instance Attribute Details
#completed_at ⇒ Object (readonly)
21 22 23 |
# File 'lib/ruby_llm/agents/track_report.rb', line 21 def completed_at @completed_at end |
#error ⇒ Object (readonly)
20 21 22 |
# File 'lib/ruby_llm/agents/track_report.rb', line 20 def error @error end |
#request_id ⇒ Object (readonly)
20 21 22 |
# File 'lib/ruby_llm/agents/track_report.rb', line 20 def request_id @request_id end |
#results ⇒ Object (readonly)
20 21 22 |
# File 'lib/ruby_llm/agents/track_report.rb', line 20 def results @results end |
#started_at ⇒ Object (readonly)
21 22 23 |
# File 'lib/ruby_llm/agents/track_report.rb', line 21 def started_at @started_at end |
#value ⇒ Object (readonly)
20 21 22 |
# File 'lib/ruby_llm/agents/track_report.rb', line 20 def value @value end |
Instance Method Details
#all_successful? ⇒ Boolean
73 74 75 |
# File 'lib/ruby_llm/agents/track_report.rb', line 73 def all_successful? @results.all?(&:success?) end |
#any_errors? ⇒ Boolean
77 78 79 |
# File 'lib/ruby_llm/agents/track_report.rb', line 77 def any_errors? @results.any?(&:error?) end |
#call_count ⇒ Object
40 41 42 |
# File 'lib/ruby_llm/agents/track_report.rb', line 40 def call_count @results.size end |
#cost_breakdown ⇒ Object
93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/ruby_llm/agents/track_report.rb', line 93 def cost_breakdown @results.map do |r| { agent: r.respond_to?(:agent_class_name) ? r.agent_class_name : nil, model: r.chosen_model_id, cost: r.total_cost || 0, tokens: r.total_tokens, duration_ms: r.duration_ms } end end |
#duration_ms ⇒ Object
68 69 70 71 |
# File 'lib/ruby_llm/agents/track_report.rb', line 68 def duration_ms return nil unless @started_at && @completed_at ((@completed_at - @started_at) * 1000).to_i end |
#errors ⇒ Object
81 82 83 |
# File 'lib/ruby_llm/agents/track_report.rb', line 81 def errors @results.select(&:error?) end |
#failed? ⇒ Boolean
36 37 38 |
# File 'lib/ruby_llm/agents/track_report.rb', line 36 def failed? !successful? end |
#input_cost ⇒ Object
48 49 50 |
# File 'lib/ruby_llm/agents/track_report.rb', line 48 def input_cost @results.sum { |r| r.input_cost || 0 } end |
#input_tokens ⇒ Object
60 61 62 |
# File 'lib/ruby_llm/agents/track_report.rb', line 60 def input_tokens @results.sum { |r| r.input_tokens || 0 } end |
#models_used ⇒ Object
89 90 91 |
# File 'lib/ruby_llm/agents/track_report.rb', line 89 def models_used @results.filter_map(&:chosen_model_id).uniq end |
#output_cost ⇒ Object
52 53 54 |
# File 'lib/ruby_llm/agents/track_report.rb', line 52 def output_cost @results.sum { |r| r.output_cost || 0 } end |
#output_tokens ⇒ Object
64 65 66 |
# File 'lib/ruby_llm/agents/track_report.rb', line 64 def output_tokens @results.sum { |r| r.output_tokens || 0 } end |
#successful ⇒ Object
85 86 87 |
# File 'lib/ruby_llm/agents/track_report.rb', line 85 def successful @results.select(&:success?) end |
#successful? ⇒ Boolean
32 33 34 |
# File 'lib/ruby_llm/agents/track_report.rb', line 32 def successful? @error.nil? end |
#to_h ⇒ Object
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/ruby_llm/agents/track_report.rb', line 105 def to_h { successful: successful?, value: value, error: error&., request_id: request_id, call_count: call_count, total_cost: total_cost, input_cost: input_cost, output_cost: output_cost, total_tokens: total_tokens, input_tokens: input_tokens, output_tokens: output_tokens, duration_ms: duration_ms, started_at: started_at, completed_at: completed_at, models_used: models_used, cost_breakdown: cost_breakdown } end |
#total_cost ⇒ Object
44 45 46 |
# File 'lib/ruby_llm/agents/track_report.rb', line 44 def total_cost @results.sum { |r| r.total_cost || 0 } end |
#total_tokens ⇒ Object
56 57 58 |
# File 'lib/ruby_llm/agents/track_report.rb', line 56 def total_tokens @results.sum { |r| r.total_tokens } end |