Class: Legion::Extensions::Agentic::Executive::Disengagement::Helpers::DisengagementEngine
- Inherits:
-
Object
- Object
- Legion::Extensions::Agentic::Executive::Disengagement::Helpers::DisengagementEngine
show all
- Includes:
- Constants
- Defined in:
- lib/legion/extensions/agentic/executive/disengagement/helpers/disengagement_engine.rb
Constant Summary
Constants included
from Constants
Constants::DECAY_RATE, Constants::DEFAULT_INVESTMENT, Constants::DEFAULT_PROGRESS, Constants::DISENGAGE_REASONS, Constants::DISENGAGE_THRESHOLD, Constants::GOAL_STATES, Constants::MAX_GOALS, Constants::MAX_HISTORY, Constants::OPPORTUNITY_COST_WEIGHT, Constants::PROGRESS_WEIGHT, Constants::STALL_THRESHOLD, Constants::STATE_LABELS, Constants::SUNK_COST_WEIGHT
Instance Method Summary
collapse
Constructor Details
Returns a new instance of DisengagementEngine.
12
13
14
|
# File 'lib/legion/extensions/agentic/executive/disengagement/helpers/disengagement_engine.rb', line 12
def initialize
@goals = {}
end
|
Instance Method Details
#active_goals ⇒ Object
59
60
61
|
# File 'lib/legion/extensions/agentic/executive/disengagement/helpers/disengagement_engine.rb', line 59
def active_goals
@goals.values.select { |g| g.state == :active }
end
|
#assess_goal(goal_id:) ⇒ Object
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
# File 'lib/legion/extensions/agentic/executive/disengagement/helpers/disengagement_engine.rb', line 27
def assess_goal(goal_id:)
goal = fetch_goal!(goal_id)
{
id: goal.id,
label: goal.label,
domain: goal.domain,
state: goal.state,
progress: goal.progress.round(4),
investment: goal.investment.round(4),
stalled: goal.stalled?,
recommend_disengage: goal.recommend_disengage?,
disengagement_score: goal.disengagement_score.round(4),
sunk_cost_resistance: goal.sunk_cost_resistance.round(4),
opportunity_cost: goal.opportunity_cost_estimate.round(4)
}
end
|
#check_progress(goal_id:, new_progress:, effort:) ⇒ Object
22
23
24
25
|
# File 'lib/legion/extensions/agentic/executive/disengagement/helpers/disengagement_engine.rb', line 22
def check_progress(goal_id:, new_progress:, effort:)
goal = fetch_goal!(goal_id)
goal.check_progress!(new_progress: new_progress, effort: effort)
end
|
#create_goal(label:, domain:) ⇒ Object
16
17
18
19
20
|
# File 'lib/legion/extensions/agentic/executive/disengagement/helpers/disengagement_engine.rb', line 16
def create_goal(label:, domain:)
goal = Goal.new(label: label, domain: domain)
@goals[goal.id] = goal
goal
end
|
#decay_all ⇒ Object
79
80
81
82
83
84
|
# File 'lib/legion/extensions/agentic/executive/disengagement/helpers/disengagement_engine.rb', line 79
def decay_all
active_goals.each do |goal|
new_progress = (goal.progress - DECAY_RATE).clamp(0.0, 1.0)
goal.check_progress!(new_progress: new_progress, effort: 0.0)
end
end
|
#disengage_goal(goal_id:, reason:) ⇒ Object
44
45
46
47
48
49
50
51
52
53
|
# File 'lib/legion/extensions/agentic/executive/disengagement/helpers/disengagement_engine.rb', line 44
def disengage_goal(goal_id:, reason:)
unless Constants::DISENGAGE_REASONS.include?(reason.to_sym)
raise ArgumentError,
"invalid reason: #{reason.inspect}, must be one of #{Constants::DISENGAGE_REASONS}"
end
goal = fetch_goal!(goal_id)
goal.disengage!(reason: reason)
goal
end
|
#disengaged_goals ⇒ Object
63
64
65
|
# File 'lib/legion/extensions/agentic/executive/disengagement/helpers/disengagement_engine.rb', line 63
def disengaged_goals
@goals.values.select { |g| g.state == :disengaged }
end
|
#goals_by_domain(domain:) ⇒ Object
67
68
69
|
# File 'lib/legion/extensions/agentic/executive/disengagement/helpers/disengagement_engine.rb', line 67
def goals_by_domain(domain:)
@goals.values.select { |g| g.domain == domain }
end
|
#highest_disengage_score(limit: 5) ⇒ Object
75
76
77
|
# File 'lib/legion/extensions/agentic/executive/disengagement/helpers/disengagement_engine.rb', line 75
def highest_disengage_score(limit: 5)
@goals.values.sort_by { |g| -g.disengagement_score }.first(limit)
end
|
#most_invested(limit: 5) ⇒ Object
71
72
73
|
# File 'lib/legion/extensions/agentic/executive/disengagement/helpers/disengagement_engine.rb', line 71
def most_invested(limit: 5)
@goals.values.sort_by { |g| -g.investment }.first(limit)
end
|
#stalled_goals ⇒ Object
55
56
57
|
# File 'lib/legion/extensions/agentic/executive/disengagement/helpers/disengagement_engine.rb', line 55
def stalled_goals
@goals.values.select(&:stalled?)
end
|
#to_h ⇒ Object
86
87
88
89
90
91
92
93
|
# File 'lib/legion/extensions/agentic/executive/disengagement/helpers/disengagement_engine.rb', line 86
def to_h
{
total_goals: @goals.size,
active_goals: active_goals.size,
stalled_goals: stalled_goals.size,
disengaged_goals: disengaged_goals.size
}
end
|