Class: Llmemory::ForgetLog

Inherits:
Object
  • Object
show all
Defined in:
lib/llmemory/forget_log.rb

Overview

Append-only audit trail of forgotten memory entries. CoALA notes that modifying and deleting memory (“unlearning”) are understudied; when an agent removes knowledge it should remain accountable for what was removed, when and why. ForgetLog records that trail, unified per user across memory types.

Backed by the same pluggable short-term stores as the rest of the session layer, under a per-user pseudo-session key.

Constant Summary collapse

SESSION_KEY =
"__forget_log__"

Instance Method Summary collapse

Constructor Details

#initialize(store: nil) ⇒ ForgetLog

Returns a new instance of ForgetLog.



17
18
19
# File 'lib/llmemory/forget_log.rb', line 17

def initialize(store: nil)
  @store = store || ShortTerm::Stores.build
end

Instance Method Details

#entries(user_id) ⇒ Object



36
37
38
39
40
41
# File 'lib/llmemory/forget_log.rb', line 36

def entries(user_id)
  state = @store.load(user_id, SESSION_KEY)
  return [] unless state.is_a?(Hash)
  list = state[:entries] || state["entries"]
  list.is_a?(Array) ? list.map { |e| symbolize(e) } : []
end

#record(user_id, memory_type:, ids:, reason: nil) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/llmemory/forget_log.rb', line 21

def record(user_id, memory_type:, ids:, reason: nil)
  ids = Array(ids).map(&:to_s)
  entry = {
    memory_type: memory_type.to_s,
    ids: ids,
    count: ids.size,
    reason: reason,
    at: Time.now.iso8601
  }
  log = entries(user_id)
  log << entry
  @store.save(user_id, SESSION_KEY, { "entries" => log })
  entry
end