Class: Legion::Extensions::Agentic::Social::JointAttention::Helpers::AttentionTarget

Inherits:
Object
  • Object
show all
Includes:
Constants
Defined in:
lib/legion/extensions/agentic/social/joint_attention/helpers/attention_target.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

Constructor Details

#initialize(name:, domain:, priority:, creator_agent_id:) ⇒ AttentionTarget

Returns a new instance of AttentionTarget.



14
15
16
17
18
19
20
21
22
23
# File 'lib/legion/extensions/agentic/social/joint_attention/helpers/attention_target.rb', line 14

def initialize(name:, domain:, priority:, creator_agent_id:)
  @id               = SecureRandom.uuid
  @name             = name
  @domain           = domain
  @priority         = priority.clamp(0.0, 1.0)
  @creator_agent_id = creator_agent_id
  @created_at       = Time.now.utc
  @attendees        = {}
  @focus_strength   = DEFAULT_FOCUS
end

Instance Attribute Details

#attendeesObject (readonly)

Returns the value of attribute attendees.



12
13
14
# File 'lib/legion/extensions/agentic/social/joint_attention/helpers/attention_target.rb', line 12

def attendees
  @attendees
end

#created_atObject (readonly)

Returns the value of attribute created_at.



12
13
14
# File 'lib/legion/extensions/agentic/social/joint_attention/helpers/attention_target.rb', line 12

def created_at
  @created_at
end

#creator_agent_idObject (readonly)

Returns the value of attribute creator_agent_id.



12
13
14
# File 'lib/legion/extensions/agentic/social/joint_attention/helpers/attention_target.rb', line 12

def creator_agent_id
  @creator_agent_id
end

#domainObject (readonly)

Returns the value of attribute domain.



12
13
14
# File 'lib/legion/extensions/agentic/social/joint_attention/helpers/attention_target.rb', line 12

def domain
  @domain
end

#focus_strengthObject (readonly)

Returns the value of attribute focus_strength.



12
13
14
# File 'lib/legion/extensions/agentic/social/joint_attention/helpers/attention_target.rb', line 12

def focus_strength
  @focus_strength
end

#idObject (readonly)

Returns the value of attribute id.



12
13
14
# File 'lib/legion/extensions/agentic/social/joint_attention/helpers/attention_target.rb', line 12

def id
  @id
end

#nameObject (readonly)

Returns the value of attribute name.



12
13
14
# File 'lib/legion/extensions/agentic/social/joint_attention/helpers/attention_target.rb', line 12

def name
  @name
end

#priorityObject (readonly)

Returns the value of attribute priority.



12
13
14
# File 'lib/legion/extensions/agentic/social/joint_attention/helpers/attention_target.rb', line 12

def priority
  @priority
end

Instance Method Details

#add_attendee(agent_id:, gaze: nil) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/legion/extensions/agentic/social/joint_attention/helpers/attention_target.rb', line 25

def add_attendee(agent_id:, gaze: nil)
  return :at_capacity if @attendees.size >= MAX_ATTENDEES_PER_TARGET
  return :already_attending if @attendees.key?(agent_id)

  @attendees[agent_id] = {
    focus:            DEFAULT_FOCUS,
    gaze:             gaze,
    joined_at:        Time.now.utc,
    mutual_awareness: false
  }
  :joined
end

#attendee_countObject



71
72
73
# File 'lib/legion/extensions/agentic/social/joint_attention/helpers/attention_target.rb', line 71

def attendee_count
  @attendees.size
end

#boost_focus(agent_id:, amount:) ⇒ Object



52
53
54
55
56
57
58
# File 'lib/legion/extensions/agentic/social/joint_attention/helpers/attention_target.rb', line 52

def boost_focus(agent_id:, amount:)
  return :not_found unless @attendees.key?(agent_id)

  current = @attendees[agent_id][:focus]
  @attendees[agent_id][:focus] = [current + amount, 1.0].min
  :boosted
end

#decayObject



84
85
86
87
88
89
90
91
92
93
# File 'lib/legion/extensions/agentic/social/joint_attention/helpers/attention_target.rb', line 84

def decay
  @attendees.each_value do |info|
    info[:focus] = [info[:focus] - FOCUS_DECAY, FOCUS_FLOOR].max
  end
  @focus_strength = if @attendees.empty?
                      [@focus_strength - FOCUS_DECAY, FOCUS_FLOOR].max
                    else
                      @attendees.values.sum { |v| v[:focus] } / @attendees.size
                    end
end

#establish_mutual_awareness(agent_a:, agent_b:) ⇒ Object



60
61
62
63
64
65
66
67
68
69
# File 'lib/legion/extensions/agentic/social/joint_attention/helpers/attention_target.rb', line 60

def establish_mutual_awareness(agent_a:, agent_b:)
  return :not_found unless @attendees.key?(agent_a) && @attendees.key?(agent_b)

  bonus = SHARED_AWARENESS_BONUS
  @attendees[agent_a][:mutual_awareness] = true
  @attendees[agent_b][:mutual_awareness] = true
  @attendees[agent_a][:focus] = [@attendees[agent_a][:focus] + bonus, 1.0].min
  @attendees[agent_b][:focus] = [@attendees[agent_b][:focus] + bonus, 1.0].min
  :established
end

#faded?Boolean

Returns:

  • (Boolean)


95
96
97
# File 'lib/legion/extensions/agentic/social/joint_attention/helpers/attention_target.rb', line 95

def faded?
  @focus_strength <= FOCUS_FLOOR && @attendees.empty?
end

#focus_labelObject



79
80
81
82
# File 'lib/legion/extensions/agentic/social/joint_attention/helpers/attention_target.rb', line 79

def focus_label
  FOCUS_LABELS.each { |range, lbl| return lbl if range.cover?(@focus_strength) }
  :fading
end

#prune_faded_attendeesObject



99
100
101
# File 'lib/legion/extensions/agentic/social/joint_attention/helpers/attention_target.rb', line 99

def prune_faded_attendees
  @attendees.reject! { |_, v| v[:focus] <= FOCUS_FLOOR }
end

#remove_attendee(agent_id:) ⇒ Object



38
39
40
41
42
43
# File 'lib/legion/extensions/agentic/social/joint_attention/helpers/attention_target.rb', line 38

def remove_attendee(agent_id:)
  return :not_found unless @attendees.key?(agent_id)

  @attendees.delete(agent_id)
  :removed
end

#shared_awareness?Boolean

Returns:

  • (Boolean)


75
76
77
# File 'lib/legion/extensions/agentic/social/joint_attention/helpers/attention_target.rb', line 75

def shared_awareness?
  @attendees.count { |_, v| v[:mutual_awareness] } >= 2
end

#to_hObject



103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# File 'lib/legion/extensions/agentic/social/joint_attention/helpers/attention_target.rb', line 103

def to_h
  {
    id:               @id,
    name:             @name,
    domain:           @domain,
    priority:         @priority,
    creator_agent_id: @creator_agent_id,
    created_at:       @created_at,
    focus_strength:   @focus_strength.round(4),
    focus_label:      focus_label,
    attendee_count:   attendee_count,
    shared_awareness: shared_awareness?,
    attendees:        @attendees.transform_values { |v| v.merge(focus: v[:focus].round(4)) }
  }
end

#update_gaze(agent_id:, gaze:) ⇒ Object



45
46
47
48
49
50
# File 'lib/legion/extensions/agentic/social/joint_attention/helpers/attention_target.rb', line 45

def update_gaze(agent_id:, gaze:)
  return :not_found unless @attendees.key?(agent_id)

  @attendees[agent_id][:gaze] = gaze
  :updated
end