Class: Legion::Extensions::Agentic::Social::JointAttention::Helpers::JointFocusManager
- Inherits:
-
Object
- Object
- Legion::Extensions::Agentic::Social::JointAttention::Helpers::JointFocusManager
show all
- Includes:
- Constants
- Defined in:
- lib/legion/extensions/agentic/social/joint_attention/helpers/joint_focus_manager.rb
Constant Summary
Constants included
from Constants
Constants::DEFAULT_FOCUS, Constants::FOCUS_ALPHA, Constants::FOCUS_DECAY, Constants::FOCUS_FLOOR, Constants::FOCUS_LABELS, Constants::MAX_ATTENDEES_PER_TARGET, Constants::MAX_HISTORY, Constants::MAX_SIMULTANEOUS_TARGETS, Constants::MAX_TARGETS, Constants::REFERRAL_BOOST, Constants::SHARED_AWARENESS_BONUS
Instance Attribute Summary collapse
Instance Method Summary
collapse
-
#attendees_for_target(target_id:) ⇒ Object
-
#create_target(name:, domain:, priority:, creator:) ⇒ Object
-
#decay_all ⇒ Object
-
#direct_attention(from_agent:, to_agent:, target_id:) ⇒ Object
-
#establish_shared(target_id:, agent_a:, agent_b:) ⇒ Object
-
#initialize ⇒ JointFocusManager
constructor
A new instance of JointFocusManager.
-
#join_target(target_id:, agent_id:, gaze: nil) ⇒ Object
-
#leave_target(target_id:, agent_id:) ⇒ Object
-
#shared_targets(agent_a:, agent_b:) ⇒ Object
-
#target_count ⇒ Object
-
#targets_for_agent(agent_id:) ⇒ Object
-
#to_h ⇒ Object
-
#update_gaze(target_id:, agent_id:, gaze:) ⇒ Object
Constructor Details
Returns a new instance of JointFocusManager.
14
15
16
17
18
|
# File 'lib/legion/extensions/agentic/social/joint_attention/helpers/joint_focus_manager.rb', line 14
def initialize
@targets = {}
@agent_focus = {}
@history = []
end
|
Instance Attribute Details
#history ⇒ Object
Returns the value of attribute history.
12
13
14
|
# File 'lib/legion/extensions/agentic/social/joint_attention/helpers/joint_focus_manager.rb', line 12
def history
@history
end
|
#targets ⇒ Object
Returns the value of attribute targets.
12
13
14
|
# File 'lib/legion/extensions/agentic/social/joint_attention/helpers/joint_focus_manager.rb', line 12
def targets
@targets
end
|
Instance Method Details
#attendees_for_target(target_id:) ⇒ Object
97
98
99
100
101
102
|
# File 'lib/legion/extensions/agentic/social/joint_attention/helpers/joint_focus_manager.rb', line 97
def attendees_for_target(target_id:)
target = @targets[target_id]
return [] unless target
target.attendees.keys
end
|
#create_target(name:, domain:, priority:, creator:) ⇒ Object
20
21
22
23
24
25
26
27
28
29
30
31
32
|
# File 'lib/legion/extensions/agentic/social/joint_attention/helpers/joint_focus_manager.rb', line 20
def create_target(name:, domain:, priority:, creator:)
prune_targets if @targets.size >= MAX_TARGETS
target = AttentionTarget.new(
name: name,
domain: domain,
priority: priority,
creator_agent_id: creator
)
@targets[target.id] = target
record_history(event: :target_created, target_id: target.id, agent_id: creator)
join_target(target_id: target.id, agent_id: creator)
target
end
|
#decay_all ⇒ Object
110
111
112
113
114
115
|
# File 'lib/legion/extensions/agentic/social/joint_attention/helpers/joint_focus_manager.rb', line 110
def decay_all
@targets.each_value(&:decay)
@targets.each_value(&:prune_faded_attendees)
sync_agent_focus
@targets.reject! { |_, t| t.faded? }
end
|
#direct_attention(from_agent:, to_agent:, target_id:) ⇒ Object
62
63
64
65
66
67
68
69
70
71
72
73
74
|
# File 'lib/legion/extensions/agentic/social/joint_attention/helpers/joint_focus_manager.rb', line 62
def direct_attention(from_agent:, to_agent:, target_id:)
target = @targets[target_id]
return :target_not_found unless target
return :referrer_not_attending unless target.attendees.key?(from_agent)
join_result = join_target(target_id: target_id, agent_id: to_agent)
return join_result if join_result == :capacity_exceeded
target.boost_focus(agent_id: to_agent, amount: REFERRAL_BOOST) if target.attendees.key?(to_agent)
record_history(event: :attention_directed, target_id: target_id, from_agent: from_agent, to_agent: to_agent)
:directed
end
|
#establish_shared(target_id:, agent_a:, agent_b:) ⇒ Object
76
77
78
79
80
81
82
83
|
# File 'lib/legion/extensions/agentic/social/joint_attention/helpers/joint_focus_manager.rb', line 76
def establish_shared(target_id:, agent_a:, agent_b:)
target = @targets[target_id]
return :target_not_found unless target
result = target.establish_mutual_awareness(agent_a: agent_a, agent_b: agent_b)
record_history(event: :shared_awareness, target_id: target_id, agent_a: agent_a, agent_b: agent_b) if result == :established
result
end
|
#join_target(target_id:, agent_id:, gaze: nil) ⇒ Object
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
# File 'lib/legion/extensions/agentic/social/joint_attention/helpers/joint_focus_manager.rb', line 34
def join_target(target_id:, agent_id:, gaze: nil)
target = @targets[target_id]
return :target_not_found unless target
current = agent_target_ids(agent_id)
return :capacity_exceeded if current.size >= MAX_SIMULTANEOUS_TARGETS && !current.include?(target_id)
result = target.add_attendee(agent_id: agent_id, gaze: gaze)
if result == :joined
@agent_focus[agent_id] ||= []
@agent_focus[agent_id] << target_id unless @agent_focus[agent_id].include?(target_id)
record_history(event: :agent_joined, target_id: target_id, agent_id: agent_id)
end
result
end
|
#leave_target(target_id:, agent_id:) ⇒ Object
50
51
52
53
54
55
56
57
58
59
60
|
# File 'lib/legion/extensions/agentic/social/joint_attention/helpers/joint_focus_manager.rb', line 50
def leave_target(target_id:, agent_id:)
target = @targets[target_id]
return :target_not_found unless target
result = target.remove_attendee(agent_id: agent_id)
if result == :removed
@agent_focus[agent_id]&.delete(target_id)
record_history(event: :agent_left, target_id: target_id, agent_id: agent_id)
end
result
end
|
#shared_targets(agent_a:, agent_b:) ⇒ Object
104
105
106
107
108
|
# File 'lib/legion/extensions/agentic/social/joint_attention/helpers/joint_focus_manager.rb', line 104
def shared_targets(agent_a:, agent_b:)
ids_a = agent_target_ids(agent_a)
ids_b = agent_target_ids(agent_b)
(ids_a & ids_b).filter_map { |tid| @targets[tid] }
end
|
#target_count ⇒ Object
117
118
119
|
# File 'lib/legion/extensions/agentic/social/joint_attention/helpers/joint_focus_manager.rb', line 117
def target_count
@targets.size
end
|
#targets_for_agent(agent_id:) ⇒ Object
92
93
94
95
|
# File 'lib/legion/extensions/agentic/social/joint_attention/helpers/joint_focus_manager.rb', line 92
def targets_for_agent(agent_id:)
ids = agent_target_ids(agent_id)
ids.filter_map { |tid| @targets[tid] }
end
|
#to_h ⇒ Object
121
122
123
124
125
126
127
128
|
# File 'lib/legion/extensions/agentic/social/joint_attention/helpers/joint_focus_manager.rb', line 121
def to_h
{
target_count: target_count,
agent_count: @agent_focus.count { |_, ids| ids.any? },
history_size: @history.size,
targets: @targets.transform_values(&:to_h)
}
end
|
#update_gaze(target_id:, agent_id:, gaze:) ⇒ Object
85
86
87
88
89
90
|
# File 'lib/legion/extensions/agentic/social/joint_attention/helpers/joint_focus_manager.rb', line 85
def update_gaze(target_id:, agent_id:, gaze:)
target = @targets[target_id]
return :target_not_found unless target
target.update_gaze(agent_id: agent_id, gaze: gaze)
end
|