Class: Legion::Extensions::Agentic::Executive::WorkingMemory::Helpers::Buffer
- Inherits:
-
Object
- Object
- Legion::Extensions::Agentic::Executive::WorkingMemory::Helpers::Buffer
- Defined in:
- lib/legion/extensions/agentic/executive/working_memory/helpers/buffer.rb
Instance Attribute Summary collapse
-
#items ⇒ Object
readonly
Returns the value of attribute items.
Instance Method Summary collapse
- #available_slots ⇒ Object
- #capacity ⇒ Object
- #clear ⇒ Object
- #consolidation_candidates ⇒ Object
- #current_load ⇒ Object
- #full? ⇒ Boolean
-
#initialize ⇒ Buffer
constructor
A new instance of Buffer.
- #load_level ⇒ Object
- #rehearse(id) ⇒ Object
- #remove(id) ⇒ Object
- #retrieve(id) ⇒ Object
- #retrieve_by_tag(tag) ⇒ Object
- #retrieve_by_type(buffer_type) ⇒ Object
- #size ⇒ Object
- #store(content:, buffer_type: :episodic, priority: :normal, tags: []) ⇒ Object
- #tick_decay ⇒ Object
- #to_h ⇒ Object
Constructor Details
#initialize ⇒ Buffer
Returns a new instance of Buffer.
12 13 14 |
# File 'lib/legion/extensions/agentic/executive/working_memory/helpers/buffer.rb', line 12 def initialize @items = [] end |
Instance Attribute Details
#items ⇒ Object (readonly)
Returns the value of attribute items.
10 11 12 |
# File 'lib/legion/extensions/agentic/executive/working_memory/helpers/buffer.rb', line 10 def items @items end |
Instance Method Details
#available_slots ⇒ Object
74 75 76 |
# File 'lib/legion/extensions/agentic/executive/working_memory/helpers/buffer.rb', line 74 def available_slots [capacity - @items.size, 0].max end |
#capacity ⇒ Object
70 71 72 |
# File 'lib/legion/extensions/agentic/executive/working_memory/helpers/buffer.rb', line 70 def capacity Constants::CAPACITY + chunk_bonus end |
#clear ⇒ Object
82 83 84 |
# File 'lib/legion/extensions/agentic/executive/working_memory/helpers/buffer.rb', line 82 def clear @items.clear end |
#consolidation_candidates ⇒ Object
52 53 54 |
# File 'lib/legion/extensions/agentic/executive/working_memory/helpers/buffer.rb', line 52 def consolidation_candidates @items.select(&:consolidation_ready?) end |
#current_load ⇒ Object
56 57 58 59 60 |
# File 'lib/legion/extensions/agentic/executive/working_memory/helpers/buffer.rb', line 56 def current_load return 0.0 if capacity.zero? (@items.size.to_f / capacity).clamp(0.0, 1.0) end |
#full? ⇒ Boolean
78 79 80 |
# File 'lib/legion/extensions/agentic/executive/working_memory/helpers/buffer.rb', line 78 def full? @items.size >= capacity end |
#load_level ⇒ Object
62 63 64 65 66 67 68 |
# File 'lib/legion/extensions/agentic/executive/working_memory/helpers/buffer.rb', line 62 def load_level load = current_load Constants::LOAD_LEVELS.each do |level, threshold| return level if load >= threshold end :idle end |
#rehearse(id) ⇒ Object
35 36 37 38 39 40 41 |
# File 'lib/legion/extensions/agentic/executive/working_memory/helpers/buffer.rb', line 35 def rehearse(id) item = retrieve(id) return nil unless item item.rehearse item end |
#remove(id) ⇒ Object
43 44 45 |
# File 'lib/legion/extensions/agentic/executive/working_memory/helpers/buffer.rb', line 43 def remove(id) @items.reject! { |i| i.id == id } end |
#retrieve(id) ⇒ Object
23 24 25 |
# File 'lib/legion/extensions/agentic/executive/working_memory/helpers/buffer.rb', line 23 def retrieve(id) @items.find { |i| i.id == id } end |
#retrieve_by_tag(tag) ⇒ Object
27 28 29 |
# File 'lib/legion/extensions/agentic/executive/working_memory/helpers/buffer.rb', line 27 def retrieve_by_tag(tag) @items.select { |i| i..include?(tag) } end |
#retrieve_by_type(buffer_type) ⇒ Object
31 32 33 |
# File 'lib/legion/extensions/agentic/executive/working_memory/helpers/buffer.rb', line 31 def retrieve_by_type(buffer_type) @items.select { |i| i.buffer_type == buffer_type } end |
#size ⇒ Object
86 87 88 |
# File 'lib/legion/extensions/agentic/executive/working_memory/helpers/buffer.rb', line 86 def size @items.size end |
#store(content:, buffer_type: :episodic, priority: :normal, tags: []) ⇒ Object
16 17 18 19 20 21 |
# File 'lib/legion/extensions/agentic/executive/working_memory/helpers/buffer.rb', line 16 def store(content:, buffer_type: :episodic, priority: :normal, tags: []) item = BufferItem.new(content: content, buffer_type: buffer_type, priority: priority, tags: ) @items << item evict_if_over_capacity item end |
#tick_decay ⇒ Object
47 48 49 50 |
# File 'lib/legion/extensions/agentic/executive/working_memory/helpers/buffer.rb', line 47 def tick_decay @items.each(&:decay) @items.reject!(&:expired?) end |
#to_h ⇒ Object
90 91 92 93 94 95 96 97 98 99 |
# File 'lib/legion/extensions/agentic/executive/working_memory/helpers/buffer.rb', line 90 def to_h { size: @items.size, capacity: capacity, load: current_load.round(4), load_level: load_level, by_type: items_by_type, available: available_slots } end |