Class: Legion::Extensions::Agentic::Executive::WorkingMemory::Helpers::BufferItem

Inherits:
Object
  • Object
show all
Defined in:
lib/legion/extensions/agentic/executive/working_memory/helpers/buffer_item.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(content:, buffer_type: :episodic, priority: :normal, tags: []) ⇒ BufferItem

Returns a new instance of BufferItem.



15
16
17
18
19
20
21
22
23
24
25
# File 'lib/legion/extensions/agentic/executive/working_memory/helpers/buffer_item.rb', line 15

def initialize(content:, buffer_type: :episodic, priority: :normal, tags: [])
  @id              = SecureRandom.uuid
  @content         = content
  @buffer_type     = buffer_type
  @priority        = priority
  @tags            = tags
  @activation      = Constants::PRIORITY_LEVELS[priority] || 0.5
  @rehearsal_count = 0
  @age_ticks       = 0
  @created_at      = Time.now.utc
end

Instance Attribute Details

#activationObject

Returns the value of attribute activation.



13
14
15
# File 'lib/legion/extensions/agentic/executive/working_memory/helpers/buffer_item.rb', line 13

def activation
  @activation
end

#age_ticksObject

Returns the value of attribute age_ticks.



13
14
15
# File 'lib/legion/extensions/agentic/executive/working_memory/helpers/buffer_item.rb', line 13

def age_ticks
  @age_ticks
end

#buffer_typeObject (readonly)

Returns the value of attribute buffer_type.



12
13
14
# File 'lib/legion/extensions/agentic/executive/working_memory/helpers/buffer_item.rb', line 12

def buffer_type
  @buffer_type
end

#contentObject (readonly)

Returns the value of attribute content.



12
13
14
# File 'lib/legion/extensions/agentic/executive/working_memory/helpers/buffer_item.rb', line 12

def content
  @content
end

#created_atObject (readonly)

Returns the value of attribute created_at.



12
13
14
# File 'lib/legion/extensions/agentic/executive/working_memory/helpers/buffer_item.rb', line 12

def created_at
  @created_at
end

#idObject (readonly)

Returns the value of attribute id.



12
13
14
# File 'lib/legion/extensions/agentic/executive/working_memory/helpers/buffer_item.rb', line 12

def id
  @id
end

#priorityObject (readonly)

Returns the value of attribute priority.



12
13
14
# File 'lib/legion/extensions/agentic/executive/working_memory/helpers/buffer_item.rb', line 12

def priority
  @priority
end

#rehearsal_countObject

Returns the value of attribute rehearsal_count.



13
14
15
# File 'lib/legion/extensions/agentic/executive/working_memory/helpers/buffer_item.rb', line 13

def rehearsal_count
  @rehearsal_count
end

#tagsObject (readonly)

Returns the value of attribute tags.



12
13
14
# File 'lib/legion/extensions/agentic/executive/working_memory/helpers/buffer_item.rb', line 12

def tags
  @tags
end

Instance Method Details

#consolidation_ready?Boolean

Returns:

  • (Boolean)


42
43
44
# File 'lib/legion/extensions/agentic/executive/working_memory/helpers/buffer_item.rb', line 42

def consolidation_ready?
  @activation >= Constants::CONSOLIDATION_THRESHOLD
end

#decayObject



33
34
35
36
# File 'lib/legion/extensions/agentic/executive/working_memory/helpers/buffer_item.rb', line 33

def decay
  @age_ticks += 1
  @activation = [@activation - Constants::DECAY_RATE, 0.0].max
end

#expired?Boolean

Returns:

  • (Boolean)


38
39
40
# File 'lib/legion/extensions/agentic/executive/working_memory/helpers/buffer_item.rb', line 38

def expired?
  @age_ticks >= Constants::MAX_AGE_TICKS || @activation <= 0.0
end

#interferes_with?(other) ⇒ Boolean

Returns:

  • (Boolean)


46
47
48
49
50
51
# File 'lib/legion/extensions/agentic/executive/working_memory/helpers/buffer_item.rb', line 46

def interferes_with?(other)
  return false unless other.is_a?(BufferItem)
  return false if @buffer_type != other.buffer_type

  @tags.any? { |t| other.tags.include?(t) } && (@activation - other.activation).abs < Constants::INTERFERENCE_THRESHOLD
end

#rehearseObject



27
28
29
30
31
# File 'lib/legion/extensions/agentic/executive/working_memory/helpers/buffer_item.rb', line 27

def rehearse
  @rehearsal_count += 1
  @activation = [@activation + Constants::REHEARSAL_BOOST, 1.0].min
  @age_ticks = 0
end

#to_hObject



53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/legion/extensions/agentic/executive/working_memory/helpers/buffer_item.rb', line 53

def to_h
  {
    id:                  @id,
    content:             @content,
    buffer_type:         @buffer_type,
    priority:            @priority,
    activation:          @activation.round(4),
    rehearsal_count:     @rehearsal_count,
    age_ticks:           @age_ticks,
    expired:             expired?,
    consolidation_ready: consolidation_ready?
  }
end