Class: Legion::Extensions::Agentic::Memory::Trace::Quota

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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

#evictionObject (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_bytesObject (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_tracesObject (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

Returns:

  • (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