Module: Legion::Extensions::Agentic::Executive::ExecutiveFunction::Runners::ExecutiveFunction

Includes:
Helpers::Lex
Included in:
Client
Defined in:
lib/legion/extensions/agentic/executive/executive_function/runners/executive_function.rb

Instance Method Summary collapse

Instance Method Details

#can_perform(operation:) ⇒ Object



47
48
49
50
51
52
53
54
55
56
# File 'lib/legion/extensions/agentic/executive/executive_function/runners/executive_function.rb', line 47

def can_perform(operation:, **)
  result = case operation.to_sym
           when :inhibit  then { can_perform: controller.can_inhibit? }
           when :shift    then { can_perform: controller.can_shift? }
           when :update   then { can_perform: controller.can_update? }
           else           { can_perform: false, reason: :unknown_operation }
           end
  Legion::Logging.debug "[executive_function] can_perform #{operation} => #{result[:can_perform]}"
  result.merge(success: true, operation: operation)
end

#common_ef_statusObject



32
33
34
35
36
# File 'lib/legion/extensions/agentic/executive/executive_function/runners/executive_function.rb', line 32

def common_ef_status(**)
  level = controller.common_ef_level
  Legion::Logging.debug "[executive_function] common_ef_level=#{level.round(3)}"
  { success: true, common_ef_level: level, components: controller.to_h[:components] }
end

#component_status(component:) ⇒ Object



38
39
40
41
42
43
44
45
# File 'lib/legion/extensions/agentic/executive/executive_function/runners/executive_function.rb', line 38

def component_status(component:, **)
  comp = controller.component(component)
  return { success: false, reason: :unknown_component } unless comp

  Legion::Logging.debug "[executive_function] component_status #{component} " \
                        "effective=#{comp.effective_capacity.round(3)}"
  { success: true, component: comp.to_h }
end

#executive_function_statsObject



87
88
89
90
91
# File 'lib/legion/extensions/agentic/executive/executive_function/runners/executive_function.rb', line 87

def executive_function_stats(**)
  stats = controller.to_h
  Legion::Logging.debug "[executive_function] stats common_ef=#{stats[:common_ef_level]}"
  { success: true }.merge(stats)
end

#executive_loadObject



65
66
67
68
69
70
71
72
# File 'lib/legion/extensions/agentic/executive/executive_function/runners/executive_function.rb', line 65

def executive_load(**)
  stats = controller.to_h
  comps = stats[:components]
  load  = comps.values.sum { |c| c[:fatigue] } / comps.size.to_f
  Legion::Logging.debug "[executive_function] executive_load=#{load.round(3)}"
  { success: true, executive_load: load.round(4), common_ef_level: stats[:common_ef_level],
    components: comps }
end

#inhibit(target:, reason: :prepotent_response) ⇒ Object



13
14
15
16
17
# File 'lib/legion/extensions/agentic/executive/executive_function/runners/executive_function.rb', line 13

def inhibit(target:, reason: :prepotent_response, **)
  result = controller.inhibit(target: target, reason: reason)
  Legion::Logging.debug "[executive_function] inhibit target=#{target} success=#{result[:success]}"
  result
end

#shift_task(from:, to:) ⇒ Object



19
20
21
22
23
24
# File 'lib/legion/extensions/agentic/executive/executive_function/runners/executive_function.rb', line 19

def shift_task(from:, to:, **)
  result = controller.shift_task(from: from, to: to)
  Legion::Logging.debug "[executive_function] shift from=#{from} to=#{to} " \
                        "cost=#{result[:switch_cost]&.round(3)} success=#{result[:success]}"
  result
end

#task_switch_cost(from:, to:) ⇒ Object



58
59
60
61
62
63
# File 'lib/legion/extensions/agentic/executive/executive_function/runners/executive_function.rb', line 58

def task_switch_cost(from:, to:, **)
  cost = from.to_s == to.to_s ? 0.0 : Helpers::ExecutiveController::SWITCH_COST
  cap  = controller.component(:shifting)&.effective_capacity || 0.0
  Legion::Logging.debug "[executive_function] task_switch_cost from=#{from} to=#{to} cost=#{cost}"
  { success: true, from: from, to: to, switch_cost: cost, shifting_capacity: cap }
end

#update_executive_function(component:, capacity:) ⇒ Object



74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/legion/extensions/agentic/executive/executive_function/runners/executive_function.rb', line 74

def update_executive_function(component:, capacity:, **)
  comp = controller.component(component)
  return { success: false, reason: :unknown_component } unless comp

  clamped = capacity.to_f.clamp(
    Helpers::EfComponent::CAPACITY_FLOOR,
    Helpers::EfComponent::CAPACITY_CEILING
  )
  comp.instance_variable_set(:@capacity, clamped)
  Legion::Logging.debug "[executive_function] update component=#{component} capacity=#{clamped}"
  { success: true, component: component, new_capacity: clamped }
end

#update_wm(slot:, new_value:, old_value: nil) ⇒ Object



26
27
28
29
30
# File 'lib/legion/extensions/agentic/executive/executive_function/runners/executive_function.rb', line 26

def update_wm(slot:, new_value:, old_value: nil, **)
  result = controller.update_wm(slot: slot, old_value: old_value, new_value: new_value)
  Legion::Logging.debug "[executive_function] update_wm slot=#{slot} success=#{result[:success]}"
  result
end