Class: Legion::Extensions::Agentic::Executive::Control::Helpers::Controller

Inherits:
Object
  • Object
show all
Includes:
Constants
Defined in:
lib/legion/extensions/agentic/executive/control/helpers/controller.rb

Constant Summary

Constants included from Constants

Legion::Extensions::Agentic::Executive::Control::Helpers::Constants::ADAPTATION_ALPHA, Legion::Extensions::Agentic::Executive::Control::Helpers::Constants::AUTOMATIC_THRESHOLD, Legion::Extensions::Agentic::Executive::Control::Helpers::Constants::CONFLICT_BOOST, Legion::Extensions::Agentic::Executive::Control::Helpers::Constants::CONTROLLED_THRESHOLD, Legion::Extensions::Agentic::Executive::Control::Helpers::Constants::CONTROL_MODES, Legion::Extensions::Agentic::Executive::Control::Helpers::Constants::DEFAULT_EFFORT, Legion::Extensions::Agentic::Executive::Control::Helpers::Constants::EFFORT_CEILING, Legion::Extensions::Agentic::Executive::Control::Helpers::Constants::EFFORT_DECAY, Legion::Extensions::Agentic::Executive::Control::Helpers::Constants::EFFORT_FLOOR, Legion::Extensions::Agentic::Executive::Control::Helpers::Constants::EFFORT_LABELS, Legion::Extensions::Agentic::Executive::Control::Helpers::Constants::EFFORT_RECOVERY, Legion::Extensions::Agentic::Executive::Control::Helpers::Constants::ERROR_BOOST, Legion::Extensions::Agentic::Executive::Control::Helpers::Constants::GOAL_STATES, Legion::Extensions::Agentic::Executive::Control::Helpers::Constants::MAX_GOALS, Legion::Extensions::Agentic::Executive::Control::Helpers::Constants::MAX_HISTORY, Legion::Extensions::Agentic::Executive::Control::Helpers::Constants::MAX_POLICIES, Legion::Extensions::Agentic::Executive::Control::Helpers::Constants::NOVELTY_BOOST, Legion::Extensions::Agentic::Executive::Control::Helpers::Constants::OVERRIDE_THRESHOLD

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeController

Returns a new instance of Controller.



14
15
16
17
18
19
# File 'lib/legion/extensions/agentic/executive/control/helpers/controller.rb', line 14

def initialize
  @goals    = {}
  @counter  = 0
  @signal   = ControlSignal.new
  @history  = []
end

Instance Attribute Details

#goalsObject (readonly)

Returns the value of attribute goals.



12
13
14
# File 'lib/legion/extensions/agentic/executive/control/helpers/controller.rb', line 12

def goals
  @goals
end

#historyObject (readonly)

Returns the value of attribute history.



12
13
14
# File 'lib/legion/extensions/agentic/executive/control/helpers/controller.rb', line 12

def history
  @history
end

#signalObject (readonly)

Returns the value of attribute signal.



12
13
14
# File 'lib/legion/extensions/agentic/executive/control/helpers/controller.rb', line 12

def signal
  @signal
end

Instance Method Details

#abandon_goal(goal_id:) ⇒ Object



52
53
54
55
56
57
# File 'lib/legion/extensions/agentic/executive/control/helpers/controller.rb', line 52

def abandon_goal(goal_id:)
  goal = @goals[goal_id]
  return nil unless goal

  goal.abandon!
end

#active_goalsObject



80
81
82
# File 'lib/legion/extensions/agentic/executive/control/helpers/controller.rb', line 80

def active_goals
  @goals.values.select(&:active?).sort_by { |g| -g.priority }.map(&:to_h)
end

#advance_goal(goal_id:, amount: 0.1) ⇒ Object



31
32
33
34
35
36
# File 'lib/legion/extensions/agentic/executive/control/helpers/controller.rb', line 31

def advance_goal(goal_id:, amount: 0.1)
  goal = @goals[goal_id]
  return nil unless goal

  goal.advance(amount: amount)
end

#current_modeObject



68
69
70
# File 'lib/legion/extensions/agentic/executive/control/helpers/controller.rb', line 68

def current_mode
  @signal.mode
end

#evaluate_control_demand(conflict: false, error: false, novelty: false) ⇒ Object



59
60
61
62
63
64
65
66
# File 'lib/legion/extensions/agentic/executive/control/helpers/controller.rb', line 59

def evaluate_control_demand(conflict: false, error: false, novelty: false)
  @signal.reset_detections
  @signal.detect_conflict if conflict
  @signal.detect_error if error
  @signal.detect_novelty if novelty
  record_evaluation
  @signal.to_h
end

#goal_conflict?Boolean

Returns:

  • (Boolean)


91
92
93
94
95
96
97
# File 'lib/legion/extensions/agentic/executive/control/helpers/controller.rb', line 91

def goal_conflict?
  active = @goals.values.select(&:active?)
  return false if active.size < 2

  priorities = active.map(&:priority)
  (priorities.max - priorities.min) < 0.2 && active.size > 1
end

#resume_goal(goal_id:) ⇒ Object



45
46
47
48
49
50
# File 'lib/legion/extensions/agentic/executive/control/helpers/controller.rb', line 45

def resume_goal(goal_id:)
  goal = @goals[goal_id]
  return nil unless goal

  goal.resume!
end

#set_goal(description:, domain: :general, priority: 0.5) ⇒ Object



21
22
23
24
25
26
27
28
29
# File 'lib/legion/extensions/agentic/executive/control/helpers/controller.rb', line 21

def set_goal(description:, domain: :general, priority: 0.5)
  return nil if @goals.size >= MAX_GOALS

  @counter += 1
  goal_id = :"goal_#{@counter}"
  goal = Goal.new(id: goal_id, description: description, domain: domain, priority: priority)
  @goals[goal_id] = goal
  goal
end

#should_control?Boolean

Returns:

  • (Boolean)


76
77
78
# File 'lib/legion/extensions/agentic/executive/control/helpers/controller.rb', line 76

def should_control?
  %i[controlled override].include?(@signal.mode)
end

#should_override?Boolean

Returns:

  • (Boolean)


72
73
74
# File 'lib/legion/extensions/agentic/executive/control/helpers/controller.rb', line 72

def should_override?
  @signal.mode == :override
end

#suspend_goal(goal_id:) ⇒ Object



38
39
40
41
42
43
# File 'lib/legion/extensions/agentic/executive/control/helpers/controller.rb', line 38

def suspend_goal(goal_id:)
  goal = @goals[goal_id]
  return nil unless goal

  goal.suspend!
end

#tickObject



99
100
101
102
103
# File 'lib/legion/extensions/agentic/executive/control/helpers/controller.rb', line 99

def tick
  @signal.decay
  check_goal_conflicts
  @signal.to_h
end

#to_hObject



105
106
107
108
109
110
111
112
113
114
115
# File 'lib/legion/extensions/agentic/executive/control/helpers/controller.rb', line 105

def to_h
  {
    goal_count:    @goals.size,
    active_goals:  @goals.values.count(&:active?),
    effort_level:  @signal.effort_level.round(4),
    mode:          current_mode,
    effort_label:  @signal.effort_label,
    goal_conflict: goal_conflict?,
    history_size:  @history.size
  }
end

#top_goalObject



84
85
86
87
88
89
# File 'lib/legion/extensions/agentic/executive/control/helpers/controller.rb', line 84

def top_goal
  active = @goals.values.select(&:active?)
  return nil if active.empty?

  active.max_by(&:priority).to_h
end