Class: Legion::Extensions::Agentic::Memory::Palimpsest::Helpers::BeliefLayer

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

Constant Summary

Constants included from Constants

Constants::CONFIDENCE_LABELS, Constants::DEFAULT_CONFIDENCE, Constants::DRIFT_LABELS, Constants::EROSION_RATE, Constants::GHOST_DECAY, Constants::GHOST_LABELS, Constants::GHOST_THRESHOLD, Constants::LAYER_DOMAINS, Constants::MAX_LAYERS_PER_TOPIC, Constants::MAX_PALIMPSESTS

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Constants

label_for

Constructor Details

#initialize(content:, confidence: DEFAULT_CONFIDENCE, domain: :unknown, version: 1, author: :system) ⇒ BeliefLayer

Returns a new instance of BeliefLayer.



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

def initialize(content:, confidence: DEFAULT_CONFIDENCE, domain: :unknown,
               version: 1, author: :system)
  @id            = ::SecureRandom.uuid
  @content       = content
  @confidence    = confidence.to_f.clamp(0.0, 1.0)
  @domain        = domain
  @version       = version
  @author        = author
  @timestamp     = ::Time.now.utc
  @superseded_by = nil
end

Instance Attribute Details

#authorObject (readonly)

Returns the value of attribute author.



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

def author
  @author
end

#confidenceObject (readonly)

Returns the value of attribute confidence.



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

def confidence
  @confidence
end

#contentObject (readonly)

Returns the value of attribute content.



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

def content
  @content
end

#domainObject (readonly)

Returns the value of attribute domain.



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

def domain
  @domain
end

#idObject (readonly)

Returns the value of attribute id.



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

def id
  @id
end

#superseded_byObject (readonly)

Returns the value of attribute superseded_by.



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

def superseded_by
  @superseded_by
end

#timestampObject (readonly)

Returns the value of attribute timestamp.



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

def timestamp
  @timestamp
end

#versionObject (readonly)

Returns the value of attribute version.



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

def version
  @version
end

Instance Method Details

#confidence_labelObject



50
51
52
# File 'lib/legion/extensions/agentic/memory/palimpsest/helpers/belief_layer.rb', line 50

def confidence_label
  Constants.label_for(CONFIDENCE_LABELS, @confidence)
end

#dissipated?Boolean

Returns:

  • (Boolean)


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

def dissipated?
  superseded? && @confidence <= GHOST_THRESHOLD
end

#erode!(rate: EROSION_RATE) ⇒ Object



46
47
48
# File 'lib/legion/extensions/agentic/memory/palimpsest/helpers/belief_layer.rb', line 46

def erode!(rate: EROSION_RATE)
  @confidence = (@confidence - rate).clamp(0.0, 1.0).round(10)
end

#ghost?Boolean

Returns:

  • (Boolean)


38
39
40
# File 'lib/legion/extensions/agentic/memory/palimpsest/helpers/belief_layer.rb', line 38

def ghost?
  superseded? && @confidence > GHOST_THRESHOLD
end

#ghost_labelObject



54
55
56
57
58
# File 'lib/legion/extensions/agentic/memory/palimpsest/helpers/belief_layer.rb', line 54

def ghost_label
  return :not_ghost unless superseded?

  Constants.label_for(GHOST_LABELS, @confidence)
end

#supersede!(next_layer_id) ⇒ Object



30
31
32
# File 'lib/legion/extensions/agentic/memory/palimpsest/helpers/belief_layer.rb', line 30

def supersede!(next_layer_id)
  @superseded_by = next_layer_id
end

#superseded?Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/legion/extensions/agentic/memory/palimpsest/helpers/belief_layer.rb', line 34

def superseded?
  !@superseded_by.nil?
end

#to_hObject



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/legion/extensions/agentic/memory/palimpsest/helpers/belief_layer.rb', line 60

def to_h
  {
    id:            @id,
    content:       @content,
    confidence:    @confidence.round(4),
    domain:        @domain,
    version:       @version,
    author:        @author,
    timestamp:     @timestamp.iso8601,
    superseded_by: @superseded_by,
    superseded:    superseded?,
    ghost:         ghost?,
    label:         confidence_label
  }
end