Class: SwarmSDK::V3::Loop::Result
- Inherits:
-
Object
- Object
- SwarmSDK::V3::Loop::Result
- Defined in:
- lib/swarm_sdk/v3/loop/result.rb
Overview
Aggregate result of a completed loop execution
Contains all iterations and whether the loop converged. Frozen on creation — both the Result and its iterations array are immutable after construction.
Instance Attribute Summary collapse
-
#converged ⇒ Boolean
(also: #converged?)
readonly
Whether the loop converged below the threshold.
-
#iterations ⇒ Array<Iteration>
readonly
All iterations (frozen).
Instance Method Summary collapse
-
#final_response ⇒ RubyLLM::Message?
The last iteration’s LLM response.
-
#initialize(iterations:, converged:) ⇒ Result
constructor
Create a new Result.
-
#iteration_count ⇒ Integer
Number of iterations executed.
-
#total_tokens ⇒ Hash{Symbol => Integer}
Aggregate token usage across all iterations.
Constructor Details
#initialize(iterations:, converged:) ⇒ Result
Create a new Result
34 35 36 37 38 |
# File 'lib/swarm_sdk/v3/loop/result.rb', line 34 def initialize(iterations:, converged:) @iterations = iterations.freeze @converged = converged freeze end |
Instance Attribute Details
#converged ⇒ Boolean (readonly) Also known as: converged?
Returns Whether the loop converged below the threshold.
27 28 29 |
# File 'lib/swarm_sdk/v3/loop/result.rb', line 27 def converged @converged end |
#iterations ⇒ Array<Iteration> (readonly)
Returns All iterations (frozen).
24 25 26 |
# File 'lib/swarm_sdk/v3/loop/result.rb', line 24 def iterations @iterations end |
Instance Method Details
#final_response ⇒ RubyLLM::Message?
The last iteration’s LLM response
46 47 48 |
# File 'lib/swarm_sdk/v3/loop/result.rb', line 46 def final_response @iterations.last&.response end |
#iteration_count ⇒ Integer
Number of iterations executed
56 57 58 |
# File 'lib/swarm_sdk/v3/loop/result.rb', line 56 def iteration_count @iterations.size end |
#total_tokens ⇒ Hash{Symbol => Integer}
Aggregate token usage across all iterations
66 67 68 69 70 |
# File 'lib/swarm_sdk/v3/loop/result.rb', line 66 def total_tokens input = @iterations.sum { |i| i.tokens[:input] } output = @iterations.sum { |i| i.tokens[:output] } { input: input, output: output } end |