Class: SwarmSDK::V3::Loop::Iteration
- Inherits:
-
Object
- Object
- SwarmSDK::V3::Loop::Iteration
- Defined in:
- lib/swarm_sdk/v3/loop/iteration.rb
Overview
Immutable record of a single loop iteration
Captures the prompt sent, the LLM response received, token usage, and the embedding-similarity delta from the previous iteration. Frozen on creation to prevent accidental mutation.
Instance Attribute Summary collapse
-
#delta_score ⇒ Float?
readonly
Cosine similarity to previous iteration (nil for iteration 1).
-
#number ⇒ Integer
readonly
1-indexed iteration number.
-
#prompt ⇒ String
readonly
Prompt used for this iteration (kickoff or iterate).
-
#response ⇒ RubyLLM::Message
readonly
LLM response from ask().
-
#tokens ⇒ Hash{Symbol => Integer}
readonly
Token usage { input:, output: }.
Instance Method Summary collapse
-
#initialize(number:, response:, prompt:, tokens:, delta_score:) ⇒ Iteration
constructor
Create a new Iteration record.
Constructor Details
#initialize(number:, response:, prompt:, tokens:, delta_score:) ⇒ Iteration
Create a new Iteration record
52 53 54 55 56 57 58 59 |
# File 'lib/swarm_sdk/v3/loop/iteration.rb', line 52 def initialize(number:, response:, prompt:, tokens:, delta_score:) @number = number @response = response @prompt = prompt @tokens = tokens.freeze @delta_score = delta_score freeze end |
Instance Attribute Details
#delta_score ⇒ Float? (readonly)
Returns Cosine similarity to previous iteration (nil for iteration 1).
43 44 45 |
# File 'lib/swarm_sdk/v3/loop/iteration.rb', line 43 def delta_score @delta_score end |
#number ⇒ Integer (readonly)
Returns 1-indexed iteration number.
31 32 33 |
# File 'lib/swarm_sdk/v3/loop/iteration.rb', line 31 def number @number end |
#prompt ⇒ String (readonly)
Returns Prompt used for this iteration (kickoff or iterate).
37 38 39 |
# File 'lib/swarm_sdk/v3/loop/iteration.rb', line 37 def prompt @prompt end |
#response ⇒ RubyLLM::Message (readonly)
Returns LLM response from ask().
34 35 36 |
# File 'lib/swarm_sdk/v3/loop/iteration.rb', line 34 def response @response end |
#tokens ⇒ Hash{Symbol => Integer} (readonly)
Returns Token usage { input:, output: }.
40 41 42 |
# File 'lib/swarm_sdk/v3/loop/iteration.rb', line 40 def tokens @tokens end |