Class: Legion::Extensions::Agentic::Memory::Offloading::Helpers::OffloadedItem

Inherits:
Object
  • Object
show all
Includes:
Constants
Defined in:
lib/legion/extensions/agentic/memory/offloading/helpers/offloaded_item.rb

Constant Summary

Constants included from Constants

Constants::DEFAULT_STORE_TRUST, Constants::IMPORTANCE_LABELS, Constants::ITEM_TYPES, Constants::MAX_ITEMS, Constants::MAX_STORES, Constants::OFFLOAD_LABELS, Constants::RETRIEVAL_SUCCESS_THRESHOLD, Constants::STORE_TYPES, Constants::TRUST_BOOST, Constants::TRUST_DECAY, Constants::TRUST_LABELS

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(content:, item_type:, importance:, store_id:) ⇒ OffloadedItem

Returns a new instance of OffloadedItem.



18
19
20
21
22
23
24
25
26
27
# File 'lib/legion/extensions/agentic/memory/offloading/helpers/offloaded_item.rb', line 18

def initialize(content:, item_type:, importance:, store_id:)
  @id               = ::SecureRandom.uuid
  @content          = content
  @item_type        = item_type
  @importance       = importance.clamp(0.0, 1.0)
  @store_id         = store_id
  @offloaded_at     = Time.now.utc
  @retrieved_count  = 0
  @last_retrieved_at = nil
end

Instance Attribute Details

#contentObject (readonly)

Returns the value of attribute content.



15
16
17
# File 'lib/legion/extensions/agentic/memory/offloading/helpers/offloaded_item.rb', line 15

def content
  @content
end

#idObject (readonly)

Returns the value of attribute id.



15
16
17
# File 'lib/legion/extensions/agentic/memory/offloading/helpers/offloaded_item.rb', line 15

def id
  @id
end

#importanceObject (readonly)

Returns the value of attribute importance.



15
16
17
# File 'lib/legion/extensions/agentic/memory/offloading/helpers/offloaded_item.rb', line 15

def importance
  @importance
end

#item_typeObject (readonly)

Returns the value of attribute item_type.



15
16
17
# File 'lib/legion/extensions/agentic/memory/offloading/helpers/offloaded_item.rb', line 15

def item_type
  @item_type
end

#last_retrieved_atObject (readonly)

Returns the value of attribute last_retrieved_at.



15
16
17
# File 'lib/legion/extensions/agentic/memory/offloading/helpers/offloaded_item.rb', line 15

def last_retrieved_at
  @last_retrieved_at
end

#offloaded_atObject (readonly)

Returns the value of attribute offloaded_at.



15
16
17
# File 'lib/legion/extensions/agentic/memory/offloading/helpers/offloaded_item.rb', line 15

def offloaded_at
  @offloaded_at
end

#retrieved_countObject (readonly)

Returns the value of attribute retrieved_count.



15
16
17
# File 'lib/legion/extensions/agentic/memory/offloading/helpers/offloaded_item.rb', line 15

def retrieved_count
  @retrieved_count
end

#store_idObject (readonly)

Returns the value of attribute store_id.



15
16
17
# File 'lib/legion/extensions/agentic/memory/offloading/helpers/offloaded_item.rb', line 15

def store_id
  @store_id
end

Instance Method Details

#importance_labelObject



42
43
44
# File 'lib/legion/extensions/agentic/memory/offloading/helpers/offloaded_item.rb', line 42

def importance_label
  IMPORTANCE_LABELS.find { |range, _| range.cover?(@importance) }&.last || :trivial
end

#retrieve!Object



29
30
31
32
33
# File 'lib/legion/extensions/agentic/memory/offloading/helpers/offloaded_item.rb', line 29

def retrieve!
  @retrieved_count  += 1
  @last_retrieved_at = Time.now.utc
  self
end

#stale?(threshold_seconds: 3600) ⇒ Boolean

Returns:

  • (Boolean)


35
36
37
38
39
40
# File 'lib/legion/extensions/agentic/memory/offloading/helpers/offloaded_item.rb', line 35

def stale?(threshold_seconds: 3600)
  return false if @last_retrieved_at.nil? && @retrieved_count.zero?

  reference = @last_retrieved_at || @offloaded_at
  (Time.now.utc - reference) > threshold_seconds
end

#to_hObject



46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/legion/extensions/agentic/memory/offloading/helpers/offloaded_item.rb', line 46

def to_h
  {
    id:                @id,
    content:           @content,
    item_type:         @item_type,
    importance:        @importance.round(10),
    importance_label:  importance_label,
    store_id:          @store_id,
    offloaded_at:      @offloaded_at,
    retrieved_count:   @retrieved_count,
    last_retrieved_at: @last_retrieved_at
  }
end