Class: Legion::Extensions::Agentic::Memory::Echo::Helpers::EchoEngine

Inherits:
Object
  • Object
show all
Includes:
Constants
Defined in:
lib/legion/extensions/agentic/memory/echo/helpers/echo_engine.rb

Constant Summary

Constants included from Constants

Constants::CHAMBER_LABELS, Constants::DEFAULT_INTENSITY, Constants::ECHO_DECAY, Constants::ECHO_TYPES, Constants::EFFECT_LABELS, Constants::INTENSITY_LABELS, Constants::INTERFERENCE_THRESHOLD, Constants::MAX_ECHOES, Constants::MAX_INTERACTIONS, Constants::PRIMING_THRESHOLD, Constants::REINFORCEMENT, Constants::SILENT_THRESHOLD

Instance Method Summary collapse

Methods included from Constants

label_for

Constructor Details

#initializeEchoEngine

Returns a new instance of EchoEngine.



12
13
14
# File 'lib/legion/extensions/agentic/memory/echo/helpers/echo_engine.rb', line 12

def initialize
  @echoes = {}
end

Instance Method Details

#active_echoesObject



37
# File 'lib/legion/extensions/agentic/memory/echo/helpers/echo_engine.rb', line 37

def active_echoes = @echoes.values.select(&:active?)

#average_intensityObject



77
78
79
80
81
# File 'lib/legion/extensions/agentic/memory/echo/helpers/echo_engine.rb', line 77

def average_intensity
  return 0.0 if @echoes.empty?

  (@echoes.values.sum(&:intensity) / @echoes.size).round(10)
end

#chamber_labelObject



61
# File 'lib/legion/extensions/agentic/memory/echo/helpers/echo_engine.rb', line 61

def chamber_label = Constants.label_for(CHAMBER_LABELS, echo_chamber_score)

#create_echo(content:, echo_type: :thought, domain: :general, intensity: DEFAULT_INTENSITY) ⇒ Object



16
17
18
19
20
21
# File 'lib/legion/extensions/agentic/memory/echo/helpers/echo_engine.rb', line 16

def create_echo(content:, echo_type: :thought, domain: :general, intensity: DEFAULT_INTENSITY)
  prune_silent
  echo = Echo.new(content: content, echo_type: echo_type, domain: domain, intensity: intensity)
  @echoes[echo.id] = echo
  echo
end

#decay_all!Object



31
32
33
34
35
# File 'lib/legion/extensions/agentic/memory/echo/helpers/echo_engine.rb', line 31

def decay_all!
  @echoes.each_value(&:decay!)
  prune_silent
  { echoes_decayed: @echoes.size, pruned: count_silent }
end

#echo_chamber_scoreObject



52
53
54
55
56
57
58
59
# File 'lib/legion/extensions/agentic/memory/echo/helpers/echo_engine.rb', line 52

def echo_chamber_score
  return 0.0 if @echoes.empty?

  domains = @echoes.values.map(&:domain).uniq
  return 1.0 if domains.size <= 1

  domain_concentration(domains)
end

#echo_reportObject



83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/legion/extensions/agentic/memory/echo/helpers/echo_engine.rb', line 83

def echo_report
  {
    total_echoes:       @echoes.size,
    active_count:       active_echoes.size,
    priming_count:      priming_echoes.size,
    interfering_count:  interfering_echoes.size,
    average_intensity:  average_intensity,
    echo_chamber_score: echo_chamber_score,
    chamber_label:      chamber_label,
    interference_level: interference_level,
    strongest:          strongest_echoes(limit: 3).map(&:to_h)
  }
end

#echoes_by_domain(domain:) ⇒ Object



45
46
47
# File 'lib/legion/extensions/agentic/memory/echo/helpers/echo_engine.rb', line 45

def echoes_by_domain(domain:)
  @echoes.values.select { |e| e.domain == domain.to_sym }
end

#echoes_by_type(echo_type:) ⇒ Object



41
42
43
# File 'lib/legion/extensions/agentic/memory/echo/helpers/echo_engine.rb', line 41

def echoes_by_type(echo_type:)
  @echoes.values.select { |e| e.echo_type == echo_type.to_sym }
end

#faintest_echoes(limit: 5) ⇒ Object



50
# File 'lib/legion/extensions/agentic/memory/echo/helpers/echo_engine.rb', line 50

def faintest_echoes(limit: 5) = @echoes.values.select(&:active?).sort_by(&:intensity).first(limit)

#interference_levelObject



70
71
72
73
74
75
# File 'lib/legion/extensions/agentic/memory/echo/helpers/echo_engine.rb', line 70

def interference_level
  interfering = interfering_echoes
  return 0.0 if interfering.empty?

  (interfering.sum(&:intensity) / @echoes.size).clamp(0.0, 1.0).round(10)
end

#interfering_echoesObject



39
# File 'lib/legion/extensions/agentic/memory/echo/helpers/echo_engine.rb', line 39

def interfering_echoes = @echoes.values.select(&:interfering?)

#priming_echoesObject



38
# File 'lib/legion/extensions/agentic/memory/echo/helpers/echo_engine.rb', line 38

def priming_echoes = @echoes.values.select(&:priming?)

#priming_effect_for(domain:) ⇒ Object



63
64
65
66
67
68
# File 'lib/legion/extensions/agentic/memory/echo/helpers/echo_engine.rb', line 63

def priming_effect_for(domain:)
  matching = echoes_by_domain(domain: domain).select(&:priming?)
  return 0.0 if matching.empty?

  matching.sum(&:intensity).clamp(0.0, 1.0).round(10)
end

#reinforce_echo(echo_id:, amount: REINFORCEMENT) ⇒ Object



23
24
25
26
27
28
29
# File 'lib/legion/extensions/agentic/memory/echo/helpers/echo_engine.rb', line 23

def reinforce_echo(echo_id:, amount: REINFORCEMENT)
  echo = @echoes[echo_id]
  return nil unless echo

  echo.reinforce!(amount)
  echo
end

#strongest_echoes(limit: 5) ⇒ Object



49
# File 'lib/legion/extensions/agentic/memory/echo/helpers/echo_engine.rb', line 49

def strongest_echoes(limit: 5) = @echoes.values.sort_by { |e| -e.intensity }.first(limit)

#to_hObject



97
98
99
100
101
102
103
104
# File 'lib/legion/extensions/agentic/memory/echo/helpers/echo_engine.rb', line 97

def to_h
  {
    total_echoes:      @echoes.size,
    active:            active_echoes.size,
    average_intensity: average_intensity,
    chamber_score:     echo_chamber_score
  }
end