Class: Legion::Extensions::Agentic::Attention::Regulation::Helpers::AttentionController
- Inherits:
-
Object
- Object
- Legion::Extensions::Agentic::Attention::Regulation::Helpers::AttentionController
show all
- Includes:
- Constants
- Defined in:
- lib/legion/extensions/agentic/attention/regulation/helpers/attention_controller.rb
Constant Summary
Constants included
from Constants
Constants::ATTENTION_MODES, Constants::CAPTURE_THRESHOLD, Constants::DEFAULT_RESOURCE, Constants::DEFAULT_ZOOM, Constants::MAX_HISTORY, Constants::MAX_TARGETS, Constants::RESOURCE_CEILING, Constants::RESOURCE_DRAIN, Constants::RESOURCE_FLOOR, Constants::RESOURCE_LABELS, Constants::RESOURCE_RECOVERY, Constants::TARGET_STATES, Constants::ZOOM_CEILING, Constants::ZOOM_FLOOR
Instance Method Summary
collapse
Constructor Details
Returns a new instance of AttentionController.
12
13
14
15
16
17
18
19
20
|
# File 'lib/legion/extensions/agentic/attention/regulation/helpers/attention_controller.rb', line 12
def initialize
@targets = {}
@current_target_id = nil
@zoom = DEFAULT_ZOOM
@resource = DEFAULT_RESOURCE
@mode = :diffuse
@counter = 0
@history = []
end
|
Instance Method Details
#add_target(name:, domain: :general, salience: 0.5) ⇒ Object
22
23
24
25
26
27
28
29
30
|
# File 'lib/legion/extensions/agentic/attention/regulation/helpers/attention_controller.rb', line 22
def add_target(name:, domain: :general, salience: 0.5)
return nil if @targets.size >= MAX_TARGETS
id = :"target_#{@counter}"
@counter += 1
target = AttentionTarget.new(id: id, name: name, domain: domain, salience: salience)
@targets[id] = target
target
end
|
#attended_targets ⇒ Object
99
100
101
|
# File 'lib/legion/extensions/agentic/attention/regulation/helpers/attention_controller.rb', line 99
def attended_targets
@targets.values.select { |t| t.state == :attended }
end
|
#check_capture ⇒ Object
75
76
77
78
79
80
81
82
83
84
85
86
87
|
# File 'lib/legion/extensions/agentic/attention/regulation/helpers/attention_controller.rb', line 75
def check_capture
return nil unless @resource > 0.3
candidate = @targets.values
.select { |t| t.state != :attended && t.salient_enough_to_capture? }
.max_by(&:salience)
return nil unless candidate
focus_on(target_id: candidate.id)
@mode = :captured
record_history(:captured, candidate.id)
candidate
end
|
#current_target ⇒ Object
89
90
91
92
93
|
# File 'lib/legion/extensions/agentic/attention/regulation/helpers/attention_controller.rb', line 89
def current_target
return nil unless @current_target_id
@targets[@current_target_id]
end
|
#defocus ⇒ Object
44
45
46
47
48
49
50
|
# File 'lib/legion/extensions/agentic/attention/regulation/helpers/attention_controller.rb', line 44
def defocus
defocus_current_target
@current_target_id = nil
@mode = :diffuse
record_history(:defocus, nil)
true
end
|
#focus_on(target_id:) ⇒ Object
32
33
34
35
36
37
38
39
40
41
42
|
# File 'lib/legion/extensions/agentic/attention/regulation/helpers/attention_controller.rb', line 32
def focus_on(target_id:)
target = @targets[target_id]
return nil unless target
defocus_current_target
@current_target_id = target_id
@mode = :focused
target.attend!
record_history(:focus, target_id)
target
end
|
#most_salient ⇒ Object
95
96
97
|
# File 'lib/legion/extensions/agentic/attention/regulation/helpers/attention_controller.rb', line 95
def most_salient
@targets.values.max_by(&:salience)
end
|
#peripheral_targets ⇒ Object
103
104
105
|
# File 'lib/legion/extensions/agentic/attention/regulation/helpers/attention_controller.rb', line 103
def peripheral_targets
@targets.values.select { |t| t.state == :peripheral }
end
|
#resource_label ⇒ Object
118
119
120
121
|
# File 'lib/legion/extensions/agentic/attention/regulation/helpers/attention_controller.rb', line 118
def resource_label
RESOURCE_LABELS.each { |range, lbl| return lbl if range.cover?(@resource) }
:depleted
end
|
#rest ⇒ Object
58
59
60
61
62
63
|
# File 'lib/legion/extensions/agentic/attention/regulation/helpers/attention_controller.rb', line 58
def rest
@mode = :resting
@current_target_id = nil
record_history(:rest, nil)
true
end
|
#scan ⇒ Object
52
53
54
55
56
|
# File 'lib/legion/extensions/agentic/attention/regulation/helpers/attention_controller.rb', line 52
def scan
@mode = :scanning
record_history(:scan, nil)
check_capture
end
|
#to_h ⇒ Object
123
124
125
126
127
128
129
130
131
132
133
134
135
|
# File 'lib/legion/extensions/agentic/attention/regulation/helpers/attention_controller.rb', line 123
def to_h
{
mode: @mode,
zoom: @zoom.round(4),
resource: @resource.round(4),
resource_label: resource_label,
current_target_id: @current_target_id,
target_count: @targets.size,
attended_count: attended_targets.size,
peripheral_count: peripheral_targets.size,
history_count: @history.size
}
end
|
#zoom_in(amount: 0.1) ⇒ Object
65
66
67
68
|
# File 'lib/legion/extensions/agentic/attention/regulation/helpers/attention_controller.rb', line 65
def zoom_in(amount: 0.1)
@zoom = (@zoom + amount.to_f).clamp(ZOOM_FLOOR, ZOOM_CEILING)
@zoom
end
|
#zoom_out(amount: 0.1) ⇒ Object
70
71
72
73
|
# File 'lib/legion/extensions/agentic/attention/regulation/helpers/attention_controller.rb', line 70
def zoom_out(amount: 0.1)
@zoom = (@zoom - amount.to_f).clamp(ZOOM_FLOOR, ZOOM_CEILING)
@zoom
end
|