Class: Legion::Extensions::Agentic::Executive::WorkingMemory::Helpers::BufferItem
- Inherits:
-
Object
- Object
- Legion::Extensions::Agentic::Executive::WorkingMemory::Helpers::BufferItem
- Defined in:
- lib/legion/extensions/agentic/executive/working_memory/helpers/buffer_item.rb
Instance Attribute Summary collapse
-
#activation ⇒ Object
Returns the value of attribute activation.
-
#age_ticks ⇒ Object
Returns the value of attribute age_ticks.
-
#buffer_type ⇒ Object
readonly
Returns the value of attribute buffer_type.
-
#content ⇒ Object
readonly
Returns the value of attribute content.
-
#created_at ⇒ Object
readonly
Returns the value of attribute created_at.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#priority ⇒ Object
readonly
Returns the value of attribute priority.
-
#rehearsal_count ⇒ Object
Returns the value of attribute rehearsal_count.
-
#tags ⇒ Object
readonly
Returns the value of attribute tags.
Instance Method Summary collapse
- #consolidation_ready? ⇒ Boolean
- #decay ⇒ Object
- #expired? ⇒ Boolean
-
#initialize(content:, buffer_type: :episodic, priority: :normal, tags: []) ⇒ BufferItem
constructor
A new instance of BufferItem.
- #interferes_with?(other) ⇒ Boolean
- #rehearse ⇒ Object
- #to_h ⇒ Object
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 = @activation = Constants::PRIORITY_LEVELS[priority] || 0.5 @rehearsal_count = 0 @age_ticks = 0 @created_at = Time.now.utc end |
Instance Attribute Details
#activation ⇒ Object
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_ticks ⇒ Object
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_type ⇒ Object (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 |
#content ⇒ Object (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_at ⇒ Object (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 |
#id ⇒ Object (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 |
#priority ⇒ Object (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_count ⇒ Object
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 |
#tags ⇒ Object (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 end |
Instance Method Details
#consolidation_ready? ⇒ 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 |
#decay ⇒ Object
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
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
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..include?(t) } && (@activation - other.activation).abs < Constants::INTERFERENCE_THRESHOLD end |
#rehearse ⇒ Object
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_h ⇒ Object
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 |