Module: Legion::Extensions::Agentic::Memory::SourceMonitoring::Runners::SourceMonitoring

Includes:
Helpers::Lex
Included in:
Client
Defined in:
lib/legion/extensions/agentic/memory/source_monitoring/runners/source_monitoring.rb

Instance Method Summary collapse

Instance Method Details

#attribute_source(content_id:) ⇒ Object



27
28
29
30
31
# File 'lib/legion/extensions/agentic/memory/source_monitoring/runners/source_monitoring.rb', line 27

def attribute_source(content_id:, **)
  records = tracker.attribute(content_id: content_id)
  log.debug("[source_monitoring] attribute: content=#{content_id} found=#{records.size}")
  { success: true, records: records.map(&:to_h), count: records.size }
end

#attribution_accuracyObject



69
70
71
# File 'lib/legion/extensions/agentic/memory/source_monitoring/runners/source_monitoring.rb', line 69

def attribution_accuracy(**)
  { success: true, accuracy: tracker.attribution_accuracy.round(4) }
end

#confused_sourcesObject



59
60
61
62
# File 'lib/legion/extensions/agentic/memory/source_monitoring/runners/source_monitoring.rb', line 59

def confused_sources(**)
  confused = tracker.confused_records
  { success: true, confused: confused, count: confused.size }
end

#correct_source(record_id:, new_source:) ⇒ Object



43
44
45
46
47
48
49
50
51
# File 'lib/legion/extensions/agentic/memory/source_monitoring/runners/source_monitoring.rb', line 43

def correct_source(record_id:, new_source:, **)
  log.debug("[source_monitoring] correct: #{record_id} -> #{new_source}")
  rec = tracker.correct_source(record_id: record_id.to_sym, new_source: new_source.to_sym)
  if rec
    { success: true, record: rec.to_h }
  else
    { success: false, reason: :not_found_or_invalid }
  end
end

#reality_check(content_id:) ⇒ Object



53
54
55
56
57
# File 'lib/legion/extensions/agentic/memory/source_monitoring/runners/source_monitoring.rb', line 53

def reality_check(content_id:, **)
  result = tracker.reality_check(content_id: content_id)
  log.debug("[source_monitoring] reality_check: #{content_id} => #{result[:status]}")
  { success: true, **result }
end

#record_source(content_id:, source:, domain: :general, confidence: nil, context: {}) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/legion/extensions/agentic/memory/source_monitoring/runners/source_monitoring.rb', line 13

def record_source(content_id:, source:, domain: :general, confidence: nil, context: {}, **)
  conf = confidence || Helpers::Constants::DEFAULT_CONFIDENCE
  log.debug("[source_monitoring] record: content=#{content_id} source=#{source}")
  rec = tracker.record_source(
    content_id: content_id, source: source.to_sym,
    domain: domain, confidence: conf, context: context
  )
  if rec
    { success: true, record: rec.to_h }
  else
    { success: false, reason: :invalid_or_full }
  end
end

#source_monitoring_statsObject



79
80
81
82
# File 'lib/legion/extensions/agentic/memory/source_monitoring/runners/source_monitoring.rb', line 79

def source_monitoring_stats(**)
  log.debug('[source_monitoring] stats')
  { success: true, stats: tracker.to_h }
end

#sources_by_type(source:) ⇒ Object



64
65
66
67
# File 'lib/legion/extensions/agentic/memory/source_monitoring/runners/source_monitoring.rb', line 64

def sources_by_type(source:, **)
  records = tracker.records_by_source(source: source.to_sym)
  { success: true, records: records, count: records.size }
end

#update_source_monitoringObject



73
74
75
76
77
# File 'lib/legion/extensions/agentic/memory/source_monitoring/runners/source_monitoring.rb', line 73

def update_source_monitoring(**)
  log.debug('[source_monitoring] tick')
  tracker.decay_all
  { success: true, records: tracker.records.size }
end

#verify_source(record_id:) ⇒ Object



33
34
35
36
37
38
39
40
41
# File 'lib/legion/extensions/agentic/memory/source_monitoring/runners/source_monitoring.rb', line 33

def verify_source(record_id:, **)
  log.debug("[source_monitoring] verify: #{record_id}")
  rec = tracker.verify_source(record_id: record_id.to_sym)
  if rec
    { success: true, record: rec.to_h }
  else
    { success: false, reason: :not_found }
  end
end