Module: Legion::Extensions::Agentic::Attention::Focus::Helpers::Focus

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

Class Method Summary collapse

Class Method Details

.attention_tier(score) ⇒ Object



48
49
50
51
52
53
54
# File 'lib/legion/extensions/agentic/attention/focus/helpers/focus.rb', line 48

def attention_tier(score)
  if score >= 0.7    then :spotlight
  elsif score >= 0.4 then :peripheral
  elsif score >= Constants::BACKGROUND_THRESHOLD then :background
  else :filtered
  end
end

.deduplicate(signals) ⇒ Object



56
57
58
59
60
61
62
63
64
65
# File 'lib/legion/extensions/agentic/attention/focus/helpers/focus.rb', line 56

def deduplicate(signals)
  seen = {}
  signals.each_with_object([]) do |signal, unique|
    key = signal_identity(signal)
    unless seen[key]
      seen[key] = true
      unique << signal
    end
  end
end

.extract_domain(signal) ⇒ Object



36
37
38
39
40
# File 'lib/legion/extensions/agentic/attention/focus/helpers/focus.rb', line 36

def extract_domain(signal)
  return :general unless signal.is_a?(Hash)

  signal[:domain] || signal[:source_type] || :general
end

.extract_novelty(signal) ⇒ Object



30
31
32
33
34
# File 'lib/legion/extensions/agentic/attention/focus/helpers/focus.rb', line 30

def extract_novelty(signal)
  return 0.5 unless signal.is_a?(Hash)

  signal[:novelty] || 0.5
end

.extract_salience(signal) ⇒ Object



24
25
26
27
28
# File 'lib/legion/extensions/agentic/attention/focus/helpers/focus.rb', line 24

def extract_salience(signal)
  return 0.0 unless signal.is_a?(Hash)

  signal[:salience] || signal[:attention_score] || 0.0
end

.score_signal(signal, habituation_level: 0.0, goal_relevance: 0.0) ⇒ Object



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

def score_signal(signal, habituation_level: 0.0, goal_relevance: 0.0)
  intrinsic = extract_salience(signal)
  novelty = extract_novelty(signal)

  weighted = (intrinsic * Constants::INTRINSIC_WEIGHT) +
             (goal_relevance * Constants::GOAL_RELEVANCE_WEIGHT) +
             (novelty * Constants::NOVELTY_WEIGHT) +
             ((1.0 - habituation_level) * Constants::HABITUATION_WEIGHT)

  weighted.clamp(0.0, 1.0)
end

.signal_identity(signal) ⇒ Object



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

def signal_identity(signal)
  return signal.object_id unless signal.is_a?(Hash)

  [signal[:source_type], signal[:domain], signal[:value]].hash
end

.tag_signal(signal, attention_score:, attention_tier:) ⇒ Object



42
43
44
45
46
# File 'lib/legion/extensions/agentic/attention/focus/helpers/focus.rb', line 42

def tag_signal(signal, attention_score:, attention_tier:)
  return signal unless signal.is_a?(Hash)

  signal.merge(attention_score: attention_score, attention_tier: attention_tier)
end