Module: Legion::Extensions::Agentic::Attention::Salience::Helpers::SignalIntegrator

Defined in:
lib/legion/extensions/agentic/attention/salience/helpers/signal_integrator.rb

Constant Summary collapse

EMPATHY_CLIMATE_SCORES =
{
  adversarial: 1.0,
  tense:       0.5,
  neutral:     0.1,
  harmonious:  0.0
}.freeze

Class Method Summary collapse

Class Method Details

.clamp(value, min = 0.0, max = 1.0) ⇒ Object



88
89
90
# File 'lib/legion/extensions/agentic/attention/salience/helpers/signal_integrator.rb', line 88

def clamp(value, min = 0.0, max = 1.0)
  value.clamp(min, max)
end

.extract_attention(data) ⇒ Object



51
52
53
54
55
# File 'lib/legion/extensions/agentic/attention/salience/helpers/signal_integrator.rb', line 51

def extract_attention(data)
  spotlight_count = (data[:spotlight_count] || 0).to_f
  total           = [(data[:total] || 0).to_f, 1.0].max
  clamp(spotlight_count / total)
end

.extract_curiosity(data) ⇒ Object



57
58
59
60
# File 'lib/legion/extensions/agentic/attention/salience/helpers/signal_integrator.rb', line 57

def extract_curiosity(data)
  top_salience = (data[:top_salience] || 0.0).to_f
  clamp(top_salience)
end

.extract_emotion(data) ⇒ Object



40
41
42
43
44
# File 'lib/legion/extensions/agentic/attention/salience/helpers/signal_integrator.rb', line 40

def extract_emotion(data)
  arousal      = (data[:arousal] || 0.0).to_f
  gut_strength = (data[:gut_strength] || 0.0).to_f
  clamp([arousal, gut_strength].max)
end

.extract_empathy(data) ⇒ Object



79
80
81
# File 'lib/legion/extensions/agentic/attention/salience/helpers/signal_integrator.rb', line 79

def extract_empathy(data)
  EMPATHY_CLIMATE_SCORES.fetch(data[:climate], 0.0)
end

.extract_homeostasis(data) ⇒ Object



62
63
64
65
# File 'lib/legion/extensions/agentic/attention/salience/helpers/signal_integrator.rb', line 62

def extract_homeostasis(data)
  worst_deviation = (data[:worst_deviation] || 0.0).to_f
  clamp(worst_deviation)
end

.extract_mood(data) ⇒ Object



46
47
48
49
# File 'lib/legion/extensions/agentic/attention/salience/helpers/signal_integrator.rb', line 46

def extract_mood(data)
  stability = (data[:stability] || 1.0).to_f
  clamp(1.0 - stability)
end

.extract_raw(source, data) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/legion/extensions/agentic/attention/salience/helpers/signal_integrator.rb', line 26

def extract_raw(source, data)
  case source
  when :emotion     then extract_emotion(data)
  when :mood        then extract_mood(data)
  when :attention   then extract_attention(data)
  when :curiosity   then extract_curiosity(data)
  when :homeostasis then extract_homeostasis(data)
  when :trust       then extract_trust(data)
  when :empathy     then extract_empathy(data)
  when :volition    then extract_volition(data)
  else 0.0
  end
end

.extract_trust(data) ⇒ Object



67
68
69
70
# File 'lib/legion/extensions/agentic/attention/salience/helpers/signal_integrator.rb', line 67

def extract_trust(data)
  violation_count = (data[:violation_count] || 0).to_f
  clamp(violation_count * 0.3)
end

.extract_volition(data) ⇒ Object



83
84
85
86
# File 'lib/legion/extensions/agentic/attention/salience/helpers/signal_integrator.rb', line 83

def extract_volition(data)
  intention_salience = (data[:intention_salience] || 0.0).to_f
  clamp(intention_salience)
end

.integrate(tick_results: {}) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/legion/extensions/agentic/attention/salience/helpers/signal_integrator.rb', line 12

def integrate(tick_results: {})
  Constants::SALIENCE_SOURCES.each_with_object({}) do |source, result|
    data   = tick_results.fetch(source, {}) || {}
    raw    = extract_raw(source, data)
    weight = Constants::SOURCE_WEIGHTS.fetch(source, 0.0)

    result[source] = {
      raw_salience: raw,
      weighted:     (raw * weight).round(6),
      signal_data:  data
    }
  end
end