Class: Legion::Extensions::Agentic::Executive::ExecutiveFunction::Helpers::ExecutiveController
- Inherits:
-
Object
- Object
- Legion::Extensions::Agentic::Executive::ExecutiveFunction::Helpers::ExecutiveController
- Defined in:
- lib/legion/extensions/agentic/executive/executive_function/helpers/executive_controller.rb
Constant Summary collapse
- EF_COMPONENTS =
%i[inhibition shifting updating].freeze
- COMMON_EF_WEIGHT =
0.4- SWITCH_COST =
0.15- INHIBITION_COST =
0.1- UPDATE_COST =
0.08- FATIGUE_RATE =
0.01- CAPACITY_ALPHA =
0.12- MAX_TASK_HISTORY =
200- MAX_INHIBITIONS =
100
Instance Attribute Summary collapse
-
#current_task_set ⇒ Object
readonly
Returns the value of attribute current_task_set.
-
#inhibition_log ⇒ Object
readonly
Returns the value of attribute inhibition_log.
-
#task_history ⇒ Object
readonly
Returns the value of attribute task_history.
-
#update_log ⇒ Object
readonly
Returns the value of attribute update_log.
Instance Method Summary collapse
- #can_inhibit? ⇒ Boolean
- #can_shift? ⇒ Boolean
- #can_update? ⇒ Boolean
- #common_ef_level ⇒ Object
- #component(name) ⇒ Object
- #inhibit(target:, reason:) ⇒ Object
-
#initialize ⇒ ExecutiveController
constructor
A new instance of ExecutiveController.
- #shift_task(from:, to:) ⇒ Object
- #tick ⇒ Object
- #to_h ⇒ Object
- #update_wm(slot:, old_value:, new_value:) ⇒ Object
Constructor Details
#initialize ⇒ ExecutiveController
Returns a new instance of ExecutiveController.
22 23 24 25 26 27 28 |
# File 'lib/legion/extensions/agentic/executive/executive_function/helpers/executive_controller.rb', line 22 def initialize @components = EF_COMPONENTS.to_h { |n| [n, EfComponent.new(name: n)] } @current_task_set = nil @task_history = [] @inhibition_log = [] @update_log = [] end |
Instance Attribute Details
#current_task_set ⇒ Object (readonly)
Returns the value of attribute current_task_set.
20 21 22 |
# File 'lib/legion/extensions/agentic/executive/executive_function/helpers/executive_controller.rb', line 20 def current_task_set @current_task_set end |
#inhibition_log ⇒ Object (readonly)
Returns the value of attribute inhibition_log.
20 21 22 |
# File 'lib/legion/extensions/agentic/executive/executive_function/helpers/executive_controller.rb', line 20 def inhibition_log @inhibition_log end |
#task_history ⇒ Object (readonly)
Returns the value of attribute task_history.
20 21 22 |
# File 'lib/legion/extensions/agentic/executive/executive_function/helpers/executive_controller.rb', line 20 def task_history @task_history end |
#update_log ⇒ Object (readonly)
Returns the value of attribute update_log.
20 21 22 |
# File 'lib/legion/extensions/agentic/executive/executive_function/helpers/executive_controller.rb', line 20 def update_log @update_log end |
Instance Method Details
#can_inhibit? ⇒ Boolean
79 80 81 |
# File 'lib/legion/extensions/agentic/executive/executive_function/helpers/executive_controller.rb', line 79 def can_inhibit? !@components[:inhibition].fatigued? end |
#can_shift? ⇒ Boolean
83 84 85 |
# File 'lib/legion/extensions/agentic/executive/executive_function/helpers/executive_controller.rb', line 83 def can_shift? !@components[:shifting].fatigued? end |
#can_update? ⇒ Boolean
87 88 89 |
# File 'lib/legion/extensions/agentic/executive/executive_function/helpers/executive_controller.rb', line 87 def can_update? !@components[:updating].fatigued? end |
#common_ef_level ⇒ Object
73 74 75 76 77 |
# File 'lib/legion/extensions/agentic/executive/executive_function/helpers/executive_controller.rb', line 73 def common_ef_level values = @components.values.map(&:effective_capacity) avg = values.sum / values.size.to_f (avg * (1.0 - COMMON_EF_WEIGHT)) + (avg * COMMON_EF_WEIGHT) end |
#component(name) ⇒ Object
95 96 97 |
# File 'lib/legion/extensions/agentic/executive/executive_function/helpers/executive_controller.rb', line 95 def component(name) @components[name.to_sym] end |
#inhibit(target:, reason:) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/legion/extensions/agentic/executive/executive_function/helpers/executive_controller.rb', line 30 def inhibit(target:, reason:) comp = @components[:inhibition] return { success: false, reason: :insufficient_capacity } unless can_inhibit? comp.use(cost: INHIBITION_COST) apply_common_ef_fatigue(:inhibition) entry = { target: target, reason: reason, suppressed_at: Time.now.utc, remaining_capacity: comp.effective_capacity } @inhibition_log << entry @inhibition_log = @inhibition_log.last(MAX_INHIBITIONS) { success: true, target: target, remaining_capacity: comp.effective_capacity } end |
#shift_task(from:, to:) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/legion/extensions/agentic/executive/executive_function/helpers/executive_controller.rb', line 43 def shift_task(from:, to:) comp = @components[:shifting] return { success: false, reason: :insufficient_capacity } unless can_shift? cost = same_task?(from, to) ? 0.0 : SWITCH_COST comp.use(cost: cost) apply_common_ef_fatigue(:shifting) old_task = @current_task_set @current_task_set = to @task_history << { from: from, to: to, switched_at: Time.now.utc, switch_cost: cost } @task_history = @task_history.last(MAX_TASK_HISTORY) { success: true, from: old_task, to: to, switch_cost: cost, remaining_capacity: comp.effective_capacity } end |
#tick ⇒ Object
91 92 93 |
# File 'lib/legion/extensions/agentic/executive/executive_function/helpers/executive_controller.rb', line 91 def tick @components.each_value(&:recover) end |
#to_h ⇒ Object
99 100 101 102 103 104 105 106 107 108 |
# File 'lib/legion/extensions/agentic/executive/executive_function/helpers/executive_controller.rb', line 99 def to_h { common_ef_level: common_ef_level.round(4), current_task_set: @current_task_set, components: @components.transform_values(&:to_h), task_history_size: @task_history.size, inhibition_count: @inhibition_log.size, update_count: @update_log.size } end |
#update_wm(slot:, old_value:, new_value:) ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/legion/extensions/agentic/executive/executive_function/helpers/executive_controller.rb', line 60 def update_wm(slot:, old_value:, new_value:) comp = @components[:updating] return { success: false, reason: :insufficient_capacity } unless can_update? comp.use(cost: UPDATE_COST) apply_common_ef_fatigue(:updating) entry = { slot: slot, old_value: old_value, new_value: new_value, updated_at: Time.now.utc, remaining_capacity: comp.effective_capacity } @update_log << entry { success: true, slot: slot, old_value: old_value, new_value: new_value, remaining_capacity: comp.effective_capacity } end |