Class: Legion::Extensions::Agentic::Executive::DecisionFatigue::Helpers::FatigueEngine
- Inherits:
-
Object
- Object
- Legion::Extensions::Agentic::Executive::DecisionFatigue::Helpers::FatigueEngine
- Defined in:
- lib/legion/extensions/agentic/executive/decision_fatigue/helpers/fatigue_engine.rb
Instance Attribute Summary collapse
-
#session_start ⇒ Object
readonly
Returns the value of attribute session_start.
-
#total_decisions ⇒ Object
readonly
Returns the value of attribute total_decisions.
-
#willpower ⇒ Object
readonly
Returns the value of attribute willpower.
Instance Method Summary collapse
- #current_quality ⇒ Object
- #decision_rate ⇒ Object
- #decisions_by_type(decision_type:) ⇒ Object
- #decisions_since_rest ⇒ Object
- #fatigue_report ⇒ Object
- #full_rest! ⇒ Object
-
#initialize ⇒ FatigueEngine
constructor
A new instance of FatigueEngine.
- #make_decision(label:, decision_type: :routine, complexity: 0.5) ⇒ Object
- #quality_label ⇒ Object
- #quality_trend(window: 10) ⇒ Object
- #recent_decisions(limit: 10) ⇒ Object
- #rest!(amount: Constants::RECOVERY_RATE) ⇒ Object
- #should_rest? ⇒ Boolean
- #to_h ⇒ Object
Constructor Details
#initialize ⇒ FatigueEngine
Returns a new instance of FatigueEngine.
12 13 14 15 16 17 18 |
# File 'lib/legion/extensions/agentic/executive/decision_fatigue/helpers/fatigue_engine.rb', line 12 def initialize @decisions = [] @willpower = Constants::DEFAULT_WILLPOWER @total_decisions = 0 @session_start = Time.now.utc @next_id = 1 end |
Instance Attribute Details
#session_start ⇒ Object (readonly)
Returns the value of attribute session_start.
10 11 12 |
# File 'lib/legion/extensions/agentic/executive/decision_fatigue/helpers/fatigue_engine.rb', line 10 def session_start @session_start end |
#total_decisions ⇒ Object (readonly)
Returns the value of attribute total_decisions.
10 11 12 |
# File 'lib/legion/extensions/agentic/executive/decision_fatigue/helpers/fatigue_engine.rb', line 10 def total_decisions @total_decisions end |
#willpower ⇒ Object (readonly)
Returns the value of attribute willpower.
10 11 12 |
# File 'lib/legion/extensions/agentic/executive/decision_fatigue/helpers/fatigue_engine.rb', line 10 def willpower @willpower end |
Instance Method Details
#current_quality ⇒ Object
42 43 44 |
# File 'lib/legion/extensions/agentic/executive/decision_fatigue/helpers/fatigue_engine.rb', line 42 def current_quality @willpower.clamp(Constants::QUALITY_FLOOR, 1.0) end |
#decision_rate ⇒ Object
62 63 64 65 |
# File 'lib/legion/extensions/agentic/executive/decision_fatigue/helpers/fatigue_engine.rb', line 62 def decision_rate elapsed = [(Time.now.utc - @session_start) / 60.0, 1.0].max @total_decisions / elapsed end |
#decisions_by_type(decision_type:) ⇒ Object
75 76 77 |
# File 'lib/legion/extensions/agentic/executive/decision_fatigue/helpers/fatigue_engine.rb', line 75 def decisions_by_type(decision_type:) @decisions.select { |d| d.decision_type == decision_type } end |
#decisions_since_rest ⇒ Object
58 59 60 |
# File 'lib/legion/extensions/agentic/executive/decision_fatigue/helpers/fatigue_engine.rb', line 58 def decisions_since_rest @decisions.size end |
#fatigue_report ⇒ Object
86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/legion/extensions/agentic/executive/decision_fatigue/helpers/fatigue_engine.rb', line 86 def fatigue_report { willpower: @willpower.round(4), current_quality: current_quality.round(4), quality_label: quality_label, total_decisions: @total_decisions, session_decisions: @decisions.size, decision_rate: decision_rate.round(4), should_rest: should_rest?, quality_trend: quality_trend.round(4), session_start: @session_start } end |
#full_rest! ⇒ Object
54 55 56 |
# File 'lib/legion/extensions/agentic/executive/decision_fatigue/helpers/fatigue_engine.rb', line 54 def full_rest! @willpower = Constants::DEFAULT_WILLPOWER end |
#make_decision(label:, decision_type: :routine, complexity: 0.5) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/legion/extensions/agentic/executive/decision_fatigue/helpers/fatigue_engine.rb', line 20 def make_decision(label:, decision_type: :routine, complexity: 0.5) complexity = complexity.clamp(0.0, 1.0) cost = complexity * Constants::DEPLETION_RATE @willpower = [@willpower - cost, Constants::QUALITY_FLOOR].max record = DecisionRecord.new( id: @next_id, label: label, decision_type: decision_type, complexity: complexity, quality_at_time: current_quality, willpower_cost: cost ) @next_id += 1 @total_decisions += 1 @decisions << record @decisions.shift while @decisions.size > Constants::MAX_DECISIONS record end |
#quality_label ⇒ Object
46 47 48 |
# File 'lib/legion/extensions/agentic/executive/decision_fatigue/helpers/fatigue_engine.rb', line 46 def quality_label Constants.quality_label_for(current_quality) end |
#quality_trend(window: 10) ⇒ Object
79 80 81 82 83 84 |
# File 'lib/legion/extensions/agentic/executive/decision_fatigue/helpers/fatigue_engine.rb', line 79 def quality_trend(window: 10) recent = @decisions.last(window) return current_quality if recent.empty? recent.sum(&:quality_at_time) / recent.size end |
#recent_decisions(limit: 10) ⇒ Object
71 72 73 |
# File 'lib/legion/extensions/agentic/executive/decision_fatigue/helpers/fatigue_engine.rb', line 71 def recent_decisions(limit: 10) @decisions.last(limit) end |
#rest!(amount: Constants::RECOVERY_RATE) ⇒ Object
50 51 52 |
# File 'lib/legion/extensions/agentic/executive/decision_fatigue/helpers/fatigue_engine.rb', line 50 def rest!(amount: Constants::RECOVERY_RATE) @willpower = [@willpower + amount, 1.0].min end |
#should_rest? ⇒ Boolean
67 68 69 |
# File 'lib/legion/extensions/agentic/executive/decision_fatigue/helpers/fatigue_engine.rb', line 67 def should_rest? @willpower < 0.3 end |
#to_h ⇒ Object
100 101 102 103 104 105 106 107 |
# File 'lib/legion/extensions/agentic/executive/decision_fatigue/helpers/fatigue_engine.rb', line 100 def to_h { willpower: @willpower, total_decisions: @total_decisions, session_start: @session_start, decisions: @decisions.map(&:to_h) } end |