Module: Legion::Extensions::Agentic::Social::Mentalizing::Runners::Mentalizing

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

Instance Method Summary collapse

Instance Method Details

#attribute_belief(agent_id:, subject:, content:, confidence: nil, depth: 0, about_agent_id: nil) ⇒ Object



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

def attribute_belief(agent_id:, subject:, content:, confidence: nil, depth: 0, about_agent_id: nil, **)
  depth = [depth.to_i, Helpers::Constants::MAX_RECURSION_DEPTH].min
  conf  = confidence || Helpers::Constants::DEFAULT_CONFIDENCE
  belief = mental_model.attribute_belief(
    agent_id:       agent_id,
    subject:        subject,
    content:        content,
    confidence:     conf.to_f,
    depth:          depth,
    about_agent_id: about_agent_id
  )
  log.debug "[mentalizing] attribute agent=#{agent_id} subject=#{subject} depth=#{depth} conf=#{belief.confidence.round(2)}"
  { attributed: true, belief: belief.to_h }
end

#beliefs_about_agent(about_agent_id:) ⇒ Object



52
53
54
55
56
# File 'lib/legion/extensions/agentic/social/mentalizing/runners/mentalizing.rb', line 52

def beliefs_about_agent(about_agent_id:, **)
  beliefs = mental_model.beliefs_about(about_agent_id: about_agent_id)
  log.debug "[mentalizing] beliefs_about about=#{about_agent_id} count=#{beliefs.size}"
  { about_agent_id: about_agent_id, beliefs: beliefs.map(&:to_h), count: beliefs.size }
end

#beliefs_for_agent(agent_id:) ⇒ Object



46
47
48
49
50
# File 'lib/legion/extensions/agentic/social/mentalizing/runners/mentalizing.rb', line 46

def beliefs_for_agent(agent_id:, **)
  beliefs = mental_model.beliefs_for(agent_id: agent_id)
  log.debug "[mentalizing] beliefs_for agent=#{agent_id} count=#{beliefs.size}"
  { agent_id: agent_id, beliefs: beliefs.map(&:to_h), count: beliefs.size }
end

#check_alignment(agent_a:, agent_b:, subject:) ⇒ Object



34
35
36
37
38
# File 'lib/legion/extensions/agentic/social/mentalizing/runners/mentalizing.rb', line 34

def check_alignment(agent_a:, agent_b:, subject:, **)
  score = mental_model.alignment(agent_a: agent_a, agent_b: agent_b, subject: subject)
  log.debug "[mentalizing] alignment agent_a=#{agent_a} agent_b=#{agent_b} subject=#{subject} score=#{score.round(2)}"
  { agent_a: agent_a, agent_b: agent_b, subject: subject, alignment: score.round(4) }
end

#detect_false_belief(agent_id:, subject:, reality:) ⇒ Object



40
41
42
43
44
# File 'lib/legion/extensions/agentic/social/mentalizing/runners/mentalizing.rb', line 40

def detect_false_belief(agent_id:, subject:, reality:, **)
  result = mental_model.detect_false_belief(agent_id: agent_id, subject: subject, reality: reality)
  log.info "[mentalizing] false_belief_check agent=#{agent_id} subject=#{subject} false=#{result[:false_belief]}"
  result
end

#mentalizing_statsObject



75
76
77
78
79
80
# File 'lib/legion/extensions/agentic/social/mentalizing/runners/mentalizing.rb', line 75

def mentalizing_stats(**)
  {
    agents:  mental_model.agent_count,
    beliefs: mental_model.belief_count
  }
end

#project_belief(subject:, own_belief:, other_agent_id:) ⇒ Object



28
29
30
31
32
# File 'lib/legion/extensions/agentic/social/mentalizing/runners/mentalizing.rb', line 28

def project_belief(subject:, own_belief:, other_agent_id:, **)
  belief = mental_model.project_self(subject: subject, own_belief: own_belief.to_f, other_agent_id: other_agent_id)
  log.debug "[mentalizing] project subject=#{subject} other=#{other_agent_id} discounted_conf=#{belief.confidence.round(2)}"
  { projected: true, belief: belief.to_h }
end

#recursive_belief_lookup(agent_id:, about_agent_id:, subject:) ⇒ Object



58
59
60
61
62
63
64
65
66
67
# File 'lib/legion/extensions/agentic/social/mentalizing/runners/mentalizing.rb', line 58

def recursive_belief_lookup(agent_id:, about_agent_id:, subject:, **)
  belief = mental_model.recursive_belief(agent_id: agent_id, about_agent_id: about_agent_id, subject: subject)
  if belief
    log.debug "[mentalizing] recursive agent=#{agent_id} about=#{about_agent_id} subject=#{subject} found=true"
    { found: true, belief: belief.to_h }
  else
    log.debug "[mentalizing] recursive agent=#{agent_id} about=#{about_agent_id} subject=#{subject} found=false"
    { found: false, agent_id: agent_id, about_agent_id: about_agent_id, subject: subject }
  end
end

#update_mentalizingObject



69
70
71
72
73
# File 'lib/legion/extensions/agentic/social/mentalizing/runners/mentalizing.rb', line 69

def update_mentalizing(**)
  mental_model.decay_all
  log.debug "[mentalizing] decay cycle agents=#{mental_model.agent_count} beliefs=#{mental_model.belief_count}"
  { decayed: true, agents: mental_model.agent_count, beliefs: mental_model.belief_count }
end