Class: Legion::Extensions::Agentic::Social::Mentalizing::Helpers::BeliefAttribution

Inherits:
Object
  • Object
show all
Defined in:
lib/legion/extensions/agentic/social/mentalizing/helpers/belief_attribution.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(agent_id:, subject:, content:, confidence:, depth: 0, about_agent_id: nil) ⇒ BeliefAttribution

Returns a new instance of BeliefAttribution.



13
14
15
16
17
18
19
20
21
22
# File 'lib/legion/extensions/agentic/social/mentalizing/helpers/belief_attribution.rb', line 13

def initialize(agent_id:, subject:, content:, confidence:, depth: 0, about_agent_id: nil)
  @id             = SecureRandom.uuid
  @agent_id       = agent_id
  @subject        = subject
  @content        = content
  @confidence     = confidence.clamp(0.0, 1.0)
  @depth          = depth
  @about_agent_id = about_agent_id
  @created_at     = Time.now.utc
end

Instance Attribute Details

#about_agent_idObject (readonly)

Returns the value of attribute about_agent_id.



10
11
12
# File 'lib/legion/extensions/agentic/social/mentalizing/helpers/belief_attribution.rb', line 10

def about_agent_id
  @about_agent_id
end

#agent_idObject (readonly)

Returns the value of attribute agent_id.



10
11
12
# File 'lib/legion/extensions/agentic/social/mentalizing/helpers/belief_attribution.rb', line 10

def agent_id
  @agent_id
end

#confidenceObject

Returns the value of attribute confidence.



11
12
13
# File 'lib/legion/extensions/agentic/social/mentalizing/helpers/belief_attribution.rb', line 11

def confidence
  @confidence
end

#contentObject (readonly)

Returns the value of attribute content.



10
11
12
# File 'lib/legion/extensions/agentic/social/mentalizing/helpers/belief_attribution.rb', line 10

def content
  @content
end

#created_atObject (readonly)

Returns the value of attribute created_at.



10
11
12
# File 'lib/legion/extensions/agentic/social/mentalizing/helpers/belief_attribution.rb', line 10

def created_at
  @created_at
end

#depthObject (readonly)

Returns the value of attribute depth.



10
11
12
# File 'lib/legion/extensions/agentic/social/mentalizing/helpers/belief_attribution.rb', line 10

def depth
  @depth
end

#idObject (readonly)

Returns the value of attribute id.



10
11
12
# File 'lib/legion/extensions/agentic/social/mentalizing/helpers/belief_attribution.rb', line 10

def id
  @id
end

#subjectObject (readonly)

Returns the value of attribute subject.



10
11
12
# File 'lib/legion/extensions/agentic/social/mentalizing/helpers/belief_attribution.rb', line 10

def subject
  @subject
end

Instance Method Details

#decayObject



24
25
26
# File 'lib/legion/extensions/agentic/social/mentalizing/helpers/belief_attribution.rb', line 24

def decay
  @confidence = [@confidence - Constants::BELIEF_DECAY, Constants::BELIEF_FLOOR].max
end

#labelObject



32
33
34
35
36
37
# File 'lib/legion/extensions/agentic/social/mentalizing/helpers/belief_attribution.rb', line 32

def label
  Constants::CONFIDENCE_LABELS.each do |range, lbl|
    return lbl if range.cover?(@confidence)
  end
  :unknown
end

#reinforce(amount: Constants::CONFIDENCE_ALPHA) ⇒ Object



28
29
30
# File 'lib/legion/extensions/agentic/social/mentalizing/helpers/belief_attribution.rb', line 28

def reinforce(amount: Constants::CONFIDENCE_ALPHA)
  @confidence = [@confidence + amount, 1.0].min
end

#to_hObject



39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/legion/extensions/agentic/social/mentalizing/helpers/belief_attribution.rb', line 39

def to_h
  {
    id:             @id,
    agent_id:       @agent_id,
    subject:        @subject,
    content:        @content,
    confidence:     @confidence,
    depth:          @depth,
    about_agent_id: @about_agent_id,
    label:          label,
    created_at:     @created_at
  }
end