Class: Legion::Extensions::Agentic::Attention::Blink::Helpers::Stimulus

Inherits:
Object
  • Object
show all
Includes:
Constants
Defined in:
lib/legion/extensions/agentic/attention/blink/helpers/stimulus.rb

Constant Summary

Constants included from Constants

Constants::DEFAULT_BLINK_DURATION, Constants::LAG1_SPARING_THRESHOLD, Constants::MAX_BLINKS, Constants::MAX_BLINK_DURATION, Constants::MAX_STIMULI, Constants::MIN_BLINK_DURATION, Constants::PROCESSING_LABELS, Constants::RECOVERY_LABELS, Constants::RECOVERY_RATE, Constants::SALIENCE_THRESHOLD, Constants::STIMULUS_TYPES

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(stimulus_type:, content:, salience: 0.5, arrival_time: nil) ⇒ Stimulus

Returns a new instance of Stimulus.



17
18
19
20
21
22
23
24
25
26
# File 'lib/legion/extensions/agentic/attention/blink/helpers/stimulus.rb', line 17

def initialize(stimulus_type:, content:, salience: 0.5, arrival_time: nil)
  @id                 = SecureRandom.uuid
  @stimulus_type      = stimulus_type.to_sym
  @content            = content
  @salience           = salience.to_f.clamp(0.0, 1.0)
  @processed          = false
  @processing_quality = 0.0
  @arrival_time       = arrival_time || Time.now.utc.to_f
  @created_at         = Time.now.utc
end

Instance Attribute Details

#arrival_timeObject (readonly)

Returns the value of attribute arrival_time.



14
15
16
# File 'lib/legion/extensions/agentic/attention/blink/helpers/stimulus.rb', line 14

def arrival_time
  @arrival_time
end

#contentObject (readonly)

Returns the value of attribute content.



14
15
16
# File 'lib/legion/extensions/agentic/attention/blink/helpers/stimulus.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/attention/blink/helpers/stimulus.rb', line 14

def created_at
  @created_at
end

#idObject (readonly)

Returns the value of attribute id.



14
15
16
# File 'lib/legion/extensions/agentic/attention/blink/helpers/stimulus.rb', line 14

def id
  @id
end

#processedObject (readonly)

Returns the value of attribute processed.



14
15
16
# File 'lib/legion/extensions/agentic/attention/blink/helpers/stimulus.rb', line 14

def processed
  @processed
end

#processing_qualityObject (readonly)

Returns the value of attribute processing_quality.



14
15
16
# File 'lib/legion/extensions/agentic/attention/blink/helpers/stimulus.rb', line 14

def processing_quality
  @processing_quality
end

#salienceObject (readonly)

Returns the value of attribute salience.



14
15
16
# File 'lib/legion/extensions/agentic/attention/blink/helpers/stimulus.rb', line 14

def salience
  @salience
end

#stimulus_typeObject (readonly)

Returns the value of attribute stimulus_type.



14
15
16
# File 'lib/legion/extensions/agentic/attention/blink/helpers/stimulus.rb', line 14

def stimulus_type
  @stimulus_type
end

Instance Method Details

#missed?Boolean

Returns:

  • (Boolean)


43
44
45
# File 'lib/legion/extensions/agentic/attention/blink/helpers/stimulus.rb', line 43

def missed?
  @processed && @processing_quality < 0.2
end

#process!(quality:) ⇒ Object



28
29
30
31
32
# File 'lib/legion/extensions/agentic/attention/blink/helpers/stimulus.rb', line 28

def process!(quality:)
  @processed = true
  @processing_quality = quality.to_f.clamp(0.0, 1.0)
  self
end

#processing_labelObject



38
39
40
41
# File 'lib/legion/extensions/agentic/attention/blink/helpers/stimulus.rb', line 38

def processing_label
  match = PROCESSING_LABELS.find { |range, _| range.cover?(@processing_quality) }
  match ? match.last : :blinked
end

#salient?Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/legion/extensions/agentic/attention/blink/helpers/stimulus.rb', line 34

def salient?
  @salience >= SALIENCE_THRESHOLD
end

#to_hObject



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/legion/extensions/agentic/attention/blink/helpers/stimulus.rb', line 47

def to_h
  {
    id:                 @id,
    stimulus_type:      @stimulus_type,
    content:            @content,
    salience:           @salience,
    processed:          @processed,
    processing_quality: @processing_quality,
    processing_label:   processing_label,
    salient:            salient?,
    missed:             missed?,
    arrival_time:       @arrival_time,
    created_at:         @created_at
  }
end