Class: Legion::Extensions::Agentic::Executive::Disengagement::Helpers::Goal
- Inherits:
-
Object
- Object
- Legion::Extensions::Agentic::Executive::Disengagement::Helpers::Goal
- Includes:
- Constants
- Defined in:
- lib/legion/extensions/agentic/executive/disengagement/helpers/goal.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 Attribute Summary collapse
-
#created_at ⇒ Object
readonly
Returns the value of attribute created_at.
-
#disengage_reason ⇒ Object
readonly
Returns the value of attribute disengage_reason.
-
#domain ⇒ Object
readonly
Returns the value of attribute domain.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#investment ⇒ Object
readonly
Returns the value of attribute investment.
-
#label ⇒ Object
readonly
Returns the value of attribute label.
-
#last_checked_at ⇒ Object
readonly
Returns the value of attribute last_checked_at.
-
#progress ⇒ Object
readonly
Returns the value of attribute progress.
-
#progress_history ⇒ Object
readonly
Returns the value of attribute progress_history.
-
#state ⇒ Object
readonly
Returns the value of attribute state.
Instance Method Summary collapse
- #check_progress!(new_progress:, effort:) ⇒ Object
- #disengage!(reason:) ⇒ Object
- #disengagement_score ⇒ Object
-
#initialize(label:, domain:) ⇒ Goal
constructor
A new instance of Goal.
- #opportunity_cost_estimate ⇒ Object
- #recent_progress_rate ⇒ Object
- #recommend_disengage? ⇒ Boolean
- #stalled? ⇒ Boolean
- #sunk_cost_resistance ⇒ Object
- #to_h ⇒ Object
Constructor Details
#initialize(label:, domain:) ⇒ Goal
Returns a new instance of Goal.
17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/legion/extensions/agentic/executive/disengagement/helpers/goal.rb', line 17 def initialize(label:, domain:) @id = SecureRandom.uuid @label = label @domain = domain @state = :active @progress = DEFAULT_PROGRESS @investment = DEFAULT_INVESTMENT @progress_history = [] @created_at = Time.now.utc @last_checked_at = Time.now.utc @disengage_reason = nil end |
Instance Attribute Details
#created_at ⇒ Object (readonly)
Returns the value of attribute created_at.
14 15 16 |
# File 'lib/legion/extensions/agentic/executive/disengagement/helpers/goal.rb', line 14 def created_at @created_at end |
#disengage_reason ⇒ Object (readonly)
Returns the value of attribute disengage_reason.
14 15 16 |
# File 'lib/legion/extensions/agentic/executive/disengagement/helpers/goal.rb', line 14 def disengage_reason @disengage_reason end |
#domain ⇒ Object (readonly)
Returns the value of attribute domain.
14 15 16 |
# File 'lib/legion/extensions/agentic/executive/disengagement/helpers/goal.rb', line 14 def domain @domain end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
14 15 16 |
# File 'lib/legion/extensions/agentic/executive/disengagement/helpers/goal.rb', line 14 def id @id end |
#investment ⇒ Object (readonly)
Returns the value of attribute investment.
14 15 16 |
# File 'lib/legion/extensions/agentic/executive/disengagement/helpers/goal.rb', line 14 def investment @investment end |
#label ⇒ Object (readonly)
Returns the value of attribute label.
14 15 16 |
# File 'lib/legion/extensions/agentic/executive/disengagement/helpers/goal.rb', line 14 def label @label end |
#last_checked_at ⇒ Object (readonly)
Returns the value of attribute last_checked_at.
14 15 16 |
# File 'lib/legion/extensions/agentic/executive/disengagement/helpers/goal.rb', line 14 def last_checked_at @last_checked_at end |
#progress ⇒ Object (readonly)
Returns the value of attribute progress.
14 15 16 |
# File 'lib/legion/extensions/agentic/executive/disengagement/helpers/goal.rb', line 14 def progress @progress end |
#progress_history ⇒ Object (readonly)
Returns the value of attribute progress_history.
14 15 16 |
# File 'lib/legion/extensions/agentic/executive/disengagement/helpers/goal.rb', line 14 def progress_history @progress_history end |
#state ⇒ Object (readonly)
Returns the value of attribute state.
14 15 16 |
# File 'lib/legion/extensions/agentic/executive/disengagement/helpers/goal.rb', line 14 def state @state end |
Instance Method Details
#check_progress!(new_progress:, effort:) ⇒ Object
30 31 32 33 34 35 36 37 38 39 |
# File 'lib/legion/extensions/agentic/executive/disengagement/helpers/goal.rb', line 30 def check_progress!(new_progress:, effort:) clamped = new_progress.clamp(0.0, 1.0) delta = clamped - @progress @progress_history << delta @progress_history.shift while @progress_history.size > MAX_HISTORY @progress = clamped @investment += effort @last_checked_at = Time.now.utc delta end |
#disengage!(reason:) ⇒ Object
73 74 75 76 |
# File 'lib/legion/extensions/agentic/executive/disengagement/helpers/goal.rb', line 73 def disengage!(reason:) @state = :disengaged @disengage_reason = reason end |
#disengagement_score ⇒ Object
51 52 53 54 55 56 |
# File 'lib/legion/extensions/agentic/executive/disengagement/helpers/goal.rb', line 51 def disengagement_score raw = ((1.0 - recent_progress_rate) * PROGRESS_WEIGHT) + (opportunity_cost_estimate * OPPORTUNITY_COST_WEIGHT) - (sunk_cost_resistance * SUNK_COST_WEIGHT) raw.clamp(0.0, 1.0) end |
#opportunity_cost_estimate ⇒ Object
62 63 64 |
# File 'lib/legion/extensions/agentic/executive/disengagement/helpers/goal.rb', line 62 def opportunity_cost_estimate 1.0 - @progress end |
#recent_progress_rate ⇒ Object
66 67 68 69 70 71 |
# File 'lib/legion/extensions/agentic/executive/disengagement/helpers/goal.rb', line 66 def recent_progress_rate return 0.0 if @progress_history.empty? last = @progress_history.last(3) last.sum / last.size.to_f end |
#recommend_disengage? ⇒ Boolean
47 48 49 |
# File 'lib/legion/extensions/agentic/executive/disengagement/helpers/goal.rb', line 47 def recommend_disengage? stalled? && disengagement_score > 0.6 end |
#stalled? ⇒ Boolean
41 42 43 44 45 |
# File 'lib/legion/extensions/agentic/executive/disengagement/helpers/goal.rb', line 41 def stalled? return false if @progress_history.size < 3 @progress_history.last(3).all? { |d| d < STALL_THRESHOLD } end |
#sunk_cost_resistance ⇒ Object
58 59 60 |
# File 'lib/legion/extensions/agentic/executive/disengagement/helpers/goal.rb', line 58 def sunk_cost_resistance @investment / (@investment + 1.0) end |
#to_h ⇒ Object
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/legion/extensions/agentic/executive/disengagement/helpers/goal.rb', line 78 def to_h { id: @id, label: @label, domain: @domain, state: @state, state_label: STATE_LABELS[@state], progress: @progress.round(4), investment: @investment.round(4), stalled: stalled?, recommend_disengage: recommend_disengage?, disengagement_score: disengagement_score.round(4), sunk_cost_resistance: sunk_cost_resistance.round(4), opportunity_cost: opportunity_cost_estimate.round(4), recent_progress_rate: recent_progress_rate.round(4), history_size: @progress_history.size, disengage_reason: @disengage_reason, created_at: @created_at, last_checked_at: @last_checked_at } end |