Class: Legion::Extensions::Agentic::Social::TheoryOfMind::Helpers::AgentModel
- Inherits:
-
Object
- Object
- Legion::Extensions::Agentic::Social::TheoryOfMind::Helpers::AgentModel
- Defined in:
- lib/legion/extensions/agentic/social/theory_of_mind/helpers/agent_model.rb
Instance Attribute Summary collapse
-
#agent_id ⇒ Object
readonly
Returns the value of attribute agent_id.
-
#beliefs ⇒ Object
readonly
Returns the value of attribute beliefs.
-
#created_at ⇒ Object
readonly
Returns the value of attribute created_at.
-
#desires ⇒ Object
readonly
Returns the value of attribute desires.
-
#intentions ⇒ Object
readonly
Returns the value of attribute intentions.
-
#interaction_count ⇒ Object
readonly
Returns the value of attribute interaction_count.
-
#prediction_accuracy ⇒ Object
readonly
Returns the value of attribute prediction_accuracy.
-
#updated_at ⇒ Object
readonly
Returns the value of attribute updated_at.
Instance Method Summary collapse
- #belief_for(domain) ⇒ Object
- #decay_beliefs ⇒ Object
- #false_beliefs(known_truths) ⇒ Object
-
#initialize(agent_id) ⇒ AgentModel
constructor
A new instance of AgentModel.
- #most_likely_intention ⇒ Object
- #perspective ⇒ Object
- #strongest_desire ⇒ Object
- #to_h ⇒ Object
- #update_belief(domain:, content:, confidence:, source: :inference) ⇒ Object
- #update_desire(goal:, priority: :medium) ⇒ Object
- #update_intention(action:, confidence: :possible) ⇒ Object
- #update_prediction_accuracy(outcome) ⇒ Object
Constructor Details
#initialize(agent_id) ⇒ AgentModel
Returns a new instance of AgentModel.
13 14 15 16 17 18 19 20 21 22 |
# File 'lib/legion/extensions/agentic/social/theory_of_mind/helpers/agent_model.rb', line 13 def initialize(agent_id) @agent_id = agent_id @beliefs = {} @desires = [] @intentions = [] @prediction_accuracy = 0.5 @interaction_count = 0 @created_at = Time.now.utc @updated_at = Time.now.utc end |
Instance Attribute Details
#agent_id ⇒ Object (readonly)
Returns the value of attribute agent_id.
10 11 12 |
# File 'lib/legion/extensions/agentic/social/theory_of_mind/helpers/agent_model.rb', line 10 def agent_id @agent_id end |
#beliefs ⇒ Object (readonly)
Returns the value of attribute beliefs.
10 11 12 |
# File 'lib/legion/extensions/agentic/social/theory_of_mind/helpers/agent_model.rb', line 10 def beliefs @beliefs end |
#created_at ⇒ Object (readonly)
Returns the value of attribute created_at.
10 11 12 |
# File 'lib/legion/extensions/agentic/social/theory_of_mind/helpers/agent_model.rb', line 10 def created_at @created_at end |
#desires ⇒ Object (readonly)
Returns the value of attribute desires.
10 11 12 |
# File 'lib/legion/extensions/agentic/social/theory_of_mind/helpers/agent_model.rb', line 10 def desires @desires end |
#intentions ⇒ Object (readonly)
Returns the value of attribute intentions.
10 11 12 |
# File 'lib/legion/extensions/agentic/social/theory_of_mind/helpers/agent_model.rb', line 10 def intentions @intentions end |
#interaction_count ⇒ Object (readonly)
Returns the value of attribute interaction_count.
10 11 12 |
# File 'lib/legion/extensions/agentic/social/theory_of_mind/helpers/agent_model.rb', line 10 def interaction_count @interaction_count end |
#prediction_accuracy ⇒ Object (readonly)
Returns the value of attribute prediction_accuracy.
10 11 12 |
# File 'lib/legion/extensions/agentic/social/theory_of_mind/helpers/agent_model.rb', line 10 def prediction_accuracy @prediction_accuracy end |
#updated_at ⇒ Object (readonly)
Returns the value of attribute updated_at.
10 11 12 |
# File 'lib/legion/extensions/agentic/social/theory_of_mind/helpers/agent_model.rb', line 10 def updated_at @updated_at end |
Instance Method Details
#belief_for(domain) ⇒ Object
59 60 61 |
# File 'lib/legion/extensions/agentic/social/theory_of_mind/helpers/agent_model.rb', line 59 def belief_for(domain) @beliefs[domain] end |
#decay_beliefs ⇒ Object
98 99 100 101 102 103 |
# File 'lib/legion/extensions/agentic/social/theory_of_mind/helpers/agent_model.rb', line 98 def decay_beliefs @beliefs.each do |domain, belief| belief[:confidence] -= Constants::BELIEF_DECAY_RATE @beliefs.delete(domain) if belief[:confidence] < Constants::CONFIDENCE_THRESHOLD end end |
#false_beliefs(known_truths) ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/legion/extensions/agentic/social/theory_of_mind/helpers/agent_model.rb', line 71 def false_beliefs(known_truths) @beliefs.each_with_object({}) do |(domain, belief), result| truth = known_truths[domain] next unless truth next if truth == belief[:content] result[domain] = { agent_believes: belief[:content], actual_truth: truth, confidence: belief[:confidence] } end end |
#most_likely_intention ⇒ Object
67 68 69 |
# File 'lib/legion/extensions/agentic/social/theory_of_mind/helpers/agent_model.rb', line 67 def most_likely_intention @intentions.max_by { |i| Constants::INTENTION_CONFIDENCE_LEVELS[i[:confidence]] || 0 } end |
#perspective ⇒ Object
105 106 107 108 109 110 111 112 113 |
# File 'lib/legion/extensions/agentic/social/theory_of_mind/helpers/agent_model.rb', line 105 def perspective { knowledge: @beliefs.transform_values { |b| b[:content] }, goals: @desires.map { |d| d[:goal] }, emotional_state: infer_emotional_state, constraints: infer_constraints, recent_actions: @intentions.last(5).map { |i| i[:action] } } end |
#strongest_desire ⇒ Object
63 64 65 |
# File 'lib/legion/extensions/agentic/social/theory_of_mind/helpers/agent_model.rb', line 63 def strongest_desire @desires.max_by { |d| Constants::DESIRE_PRIORITIES[d[:priority]] || 0 } end |
#to_h ⇒ Object
115 116 117 118 119 120 121 122 123 124 125 126 |
# File 'lib/legion/extensions/agentic/social/theory_of_mind/helpers/agent_model.rb', line 115 def to_h { agent_id: @agent_id, belief_count: @beliefs.size, desire_count: @desires.size, intention_count: @intentions.size, prediction_accuracy: @prediction_accuracy.round(4), interaction_count: @interaction_count, strongest_desire: strongest_desire&.dig(:goal), likely_action: most_likely_intention&.dig(:action) } end |
#update_belief(domain:, content:, confidence:, source: :inference) ⇒ Object
24 25 26 27 28 29 30 31 32 33 |
# File 'lib/legion/extensions/agentic/social/theory_of_mind/helpers/agent_model.rb', line 24 def update_belief(domain:, content:, confidence:, source: :inference) @beliefs[domain] = { content: content, confidence: confidence.clamp(0.0, 1.0), source: source, updated_at: Time.now.utc } trim_beliefs touch end |
#update_desire(goal:, priority: :medium) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/legion/extensions/agentic/social/theory_of_mind/helpers/agent_model.rb', line 35 def update_desire(goal:, priority: :medium) existing = @desires.find { |d| d[:goal] == goal } if existing existing[:priority] = priority existing[:observed_at] = Time.now.utc else @desires << { goal: goal, priority: priority, observed_at: Time.now.utc } trim_desires end touch end |
#update_intention(action:, confidence: :possible) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/legion/extensions/agentic/social/theory_of_mind/helpers/agent_model.rb', line 47 def update_intention(action:, confidence: :possible) existing = @intentions.find { |i| i[:action] == action } if existing existing[:confidence] = confidence existing[:estimated_at] = Time.now.utc else @intentions << { action: action, confidence: confidence, estimated_at: Time.now.utc } trim_intentions end touch end |
#update_prediction_accuracy(outcome) ⇒ Object
85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/legion/extensions/agentic/social/theory_of_mind/helpers/agent_model.rb', line 85 def update_prediction_accuracy(outcome) score = case outcome when :correct then 1.0 when :partially_correct then 0.5 when :incorrect then 0.0 else return end alpha = Constants::PREDICTION_ALPHA @prediction_accuracy = (@prediction_accuracy * (1.0 - alpha)) + (score * alpha) @interaction_count += 1 touch end |