Class: Legion::Extensions::Agentic::Integration::Synthesis::Helpers::SynthesisStream

Inherits:
Object
  • Object
show all
Includes:
Constants
Defined in:
lib/legion/extensions/agentic/integration/synthesis/helpers/synthesis_stream.rb

Constant Summary

Constants included from Constants

Constants::COHERENCE_LABELS, Constants::COHERENCE_THRESHOLD, Constants::CONFIDENCE_LABELS, Constants::DEFAULT_WEIGHT, Constants::FRESHNESS_DECAY, Constants::MAX_STREAMS, Constants::MAX_SYNTHESES, Constants::MIN_STREAMS_FOR_SYNTHESIS, Constants::NOVELTY_THRESHOLD, Constants::STREAM_TYPES

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(stream_type:, content:, weight: DEFAULT_WEIGHT, confidence: DEFAULT_WEIGHT) ⇒ SynthesisStream

Returns a new instance of SynthesisStream.



16
17
18
19
20
21
22
23
24
# File 'lib/legion/extensions/agentic/integration/synthesis/helpers/synthesis_stream.rb', line 16

def initialize(stream_type:, content:, weight: DEFAULT_WEIGHT, confidence: DEFAULT_WEIGHT)
  @id          = SecureRandom.uuid
  @stream_type = stream_type
  @content     = content
  @weight      = weight.clamp(0.0, 1.0)
  @confidence  = confidence.clamp(0.0, 1.0)
  @freshness   = 1.0
  @created_at  = Time.now.utc
end

Instance Attribute Details

#confidenceObject (readonly)

Returns the value of attribute confidence.



14
15
16
# File 'lib/legion/extensions/agentic/integration/synthesis/helpers/synthesis_stream.rb', line 14

def confidence
  @confidence
end

#contentObject (readonly)

Returns the value of attribute content.



14
15
16
# File 'lib/legion/extensions/agentic/integration/synthesis/helpers/synthesis_stream.rb', line 14

def content
  @content
end

#created_atObject (readonly)

Returns the value of attribute created_at.



14
15
16
# File 'lib/legion/extensions/agentic/integration/synthesis/helpers/synthesis_stream.rb', line 14

def created_at
  @created_at
end

#freshnessObject (readonly)

Returns the value of attribute freshness.



14
15
16
# File 'lib/legion/extensions/agentic/integration/synthesis/helpers/synthesis_stream.rb', line 14

def freshness
  @freshness
end

#idObject (readonly)

Returns the value of attribute id.



14
15
16
# File 'lib/legion/extensions/agentic/integration/synthesis/helpers/synthesis_stream.rb', line 14

def id
  @id
end

#stream_typeObject (readonly)

Returns the value of attribute stream_type.



14
15
16
# File 'lib/legion/extensions/agentic/integration/synthesis/helpers/synthesis_stream.rb', line 14

def stream_type
  @stream_type
end

#weightObject (readonly)

Returns the value of attribute weight.



14
15
16
# File 'lib/legion/extensions/agentic/integration/synthesis/helpers/synthesis_stream.rb', line 14

def weight
  @weight
end

Instance Method Details

#coherence_labelObject



38
39
40
# File 'lib/legion/extensions/agentic/integration/synthesis/helpers/synthesis_stream.rb', line 38

def coherence_label
  COHERENCE_LABELS.find { |range, _| range.cover?(@weight) }&.last || :chaotic
end

#confidence_labelObject



42
43
44
# File 'lib/legion/extensions/agentic/integration/synthesis/helpers/synthesis_stream.rb', line 42

def confidence_label
  CONFIDENCE_LABELS.find { |range, _| range.cover?(@confidence) }&.last || :guessing
end

#decay_freshness!Object



26
27
28
# File 'lib/legion/extensions/agentic/integration/synthesis/helpers/synthesis_stream.rb', line 26

def decay_freshness!
  @freshness = (@freshness - FRESHNESS_DECAY).clamp(0.0, 1.0)
end

#effective_weightObject



34
35
36
# File 'lib/legion/extensions/agentic/integration/synthesis/helpers/synthesis_stream.rb', line 34

def effective_weight
  (@weight * @freshness * @confidence).round(10)
end

#stale?Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/legion/extensions/agentic/integration/synthesis/helpers/synthesis_stream.rb', line 30

def stale?
  @freshness < 0.1
end

#to_hObject



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/legion/extensions/agentic/integration/synthesis/helpers/synthesis_stream.rb', line 46

def to_h
  {
    id:               @id,
    stream_type:      @stream_type,
    content:          @content,
    weight:           @weight,
    confidence:       @confidence,
    freshness:        @freshness,
    effective_weight: effective_weight,
    stale:            stale?,
    coherence_label:  coherence_label,
    confidence_label: confidence_label,
    created_at:       @created_at
  }
end