Class: Legion::Extensions::Agentic::Memory::Trace::Quota
- Inherits:
-
Object
- Object
- Legion::Extensions::Agentic::Memory::Trace::Quota
- Defined in:
- lib/legion/extensions/agentic/memory/trace/quota.rb
Constant Summary collapse
- DEFAULTS =
{ max_traces: 10_000, max_bytes: 52_428_800, # 50MB eviction: :lru }.freeze
Instance Attribute Summary collapse
-
#eviction ⇒ Object
readonly
Returns the value of attribute eviction.
-
#max_bytes ⇒ Object
readonly
Returns the value of attribute max_bytes.
-
#max_traces ⇒ Object
readonly
Returns the value of attribute max_traces.
Instance Method Summary collapse
- #enforce!(store) ⇒ Object
-
#initialize(**opts) ⇒ Quota
constructor
A new instance of Quota.
- #within_limits?(store) ⇒ Boolean
Constructor Details
#initialize(**opts) ⇒ Quota
Returns a new instance of Quota.
17 18 19 20 21 22 |
# File 'lib/legion/extensions/agentic/memory/trace/quota.rb', line 17 def initialize(**opts) config = DEFAULTS.merge(opts) @max_traces = config[:max_traces] @max_bytes = config[:max_bytes] @eviction = config[:eviction].to_sym end |
Instance Attribute Details
#eviction ⇒ Object (readonly)
Returns the value of attribute eviction.
15 16 17 |
# File 'lib/legion/extensions/agentic/memory/trace/quota.rb', line 15 def eviction @eviction end |
#max_bytes ⇒ Object (readonly)
Returns the value of attribute max_bytes.
15 16 17 |
# File 'lib/legion/extensions/agentic/memory/trace/quota.rb', line 15 def max_bytes @max_bytes end |
#max_traces ⇒ Object (readonly)
Returns the value of attribute max_traces.
15 16 17 |
# File 'lib/legion/extensions/agentic/memory/trace/quota.rb', line 15 def max_traces @max_traces end |
Instance Method Details
#enforce!(store) ⇒ Object
24 25 26 27 28 29 30 31 32 |
# File 'lib/legion/extensions/agentic/memory/trace/quota.rb', line 24 def enforce!(store) evict_count = store.count - max_traces evict!(store, evict_count) if evict_count.positive? return unless store.respond_to?(:total_bytes) overage = store.total_bytes - max_bytes evict!(store, estimate_eviction_count(overage)) if overage.positive? end |
#within_limits?(store) ⇒ Boolean
34 35 36 37 38 |
# File 'lib/legion/extensions/agentic/memory/trace/quota.rb', line 34 def within_limits?(store) return store.count <= max_traces unless store.respond_to?(:total_bytes) store.count <= max_traces && store.total_bytes <= max_bytes end |