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

Inherits:
Object
  • Object
show all
Includes:
Constants
Defined in:
lib/legion/extensions/agentic/memory/echo/helpers/echo.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 Attribute Summary collapse

Instance Method Summary collapse

Methods included from Constants

label_for

Constructor Details

#initialize(content:, echo_type: :thought, domain: :general, intensity: DEFAULT_INTENSITY) ⇒ Echo

Returns a new instance of Echo.



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

def initialize(content:, echo_type: :thought, domain: :general, intensity: DEFAULT_INTENSITY)
  @id                 = SecureRandom.uuid
  @content            = content
  @echo_type          = validate_type(echo_type)
  @domain             = domain.to_sym
  @intensity          = intensity.to_f.clamp(0.0, 1.0).round(10)
  @original_intensity = @intensity
  @decay_count        = 0
  @created_at         = Time.now.utc
end

Instance Attribute Details

#contentObject (readonly)

Returns the value of attribute content.



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

def created_at
  @created_at
end

#decay_countObject (readonly)

Returns the value of attribute decay_count.



14
15
16
# File 'lib/legion/extensions/agentic/memory/echo/helpers/echo.rb', line 14

def decay_count
  @decay_count
end

#domainObject (readonly)

Returns the value of attribute domain.



14
15
16
# File 'lib/legion/extensions/agentic/memory/echo/helpers/echo.rb', line 14

def domain
  @domain
end

#echo_typeObject (readonly)

Returns the value of attribute echo_type.



14
15
16
# File 'lib/legion/extensions/agentic/memory/echo/helpers/echo.rb', line 14

def echo_type
  @echo_type
end

#idObject (readonly)

Returns the value of attribute id.



14
15
16
# File 'lib/legion/extensions/agentic/memory/echo/helpers/echo.rb', line 14

def id
  @id
end

#intensityObject (readonly)

Returns the value of attribute intensity.



14
15
16
# File 'lib/legion/extensions/agentic/memory/echo/helpers/echo.rb', line 14

def intensity
  @intensity
end

#original_intensityObject (readonly)

Returns the value of attribute original_intensity.



14
15
16
# File 'lib/legion/extensions/agentic/memory/echo/helpers/echo.rb', line 14

def original_intensity
  @original_intensity
end

Instance Method Details

#active?Boolean

Returns:

  • (Boolean)


43
44
45
# File 'lib/legion/extensions/agentic/memory/echo/helpers/echo.rb', line 43

def active?
  @intensity > SILENT_THRESHOLD
end

#decay!Object



28
29
30
31
32
# File 'lib/legion/extensions/agentic/memory/echo/helpers/echo.rb', line 28

def decay!
  @decay_count += 1
  @intensity = (@intensity - ECHO_DECAY).clamp(0.0, 1.0).round(10)
  self
end

#effect_labelObject



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

def effect_label = Constants.label_for(EFFECT_LABELS, @intensity)

#intensity_labelObject



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

def intensity_label = Constants.label_for(INTENSITY_LABELS, @intensity)

#interfering?Boolean

Returns:

  • (Boolean)


51
52
53
# File 'lib/legion/extensions/agentic/memory/echo/helpers/echo.rb', line 51

def interfering?
  @intensity >= INTERFERENCE_THRESHOLD
end

#persistenceObject



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

def persistence
  return 0.0 if @original_intensity.zero?

  (@intensity / @original_intensity).clamp(0.0, 1.0).round(10)
end

#priming?Boolean

Returns:

  • (Boolean)


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

def priming?
  @intensity >= PRIMING_THRESHOLD
end

#reinforce!(amount = REINFORCEMENT) ⇒ Object



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

def reinforce!(amount = REINFORCEMENT)
  @intensity = (@intensity + amount).clamp(0.0, 1.0).round(10)
  self
end

#silent?Boolean

Returns:

  • (Boolean)


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

def silent?
  @intensity <= SILENT_THRESHOLD
end

#to_hObject



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/legion/extensions/agentic/memory/echo/helpers/echo.rb', line 64

def to_h
  {
    id:                 @id,
    content:            @content,
    echo_type:          @echo_type,
    domain:             @domain,
    intensity:          @intensity,
    original_intensity: @original_intensity,
    intensity_label:    intensity_label,
    effect_label:       effect_label,
    priming:            priming?,
    interfering:        interfering?,
    silent:             silent?,
    persistence:        persistence,
    decay_count:        @decay_count,
    created_at:         @created_at
  }
end