Module: Legion::Extensions::Agentic::Executive::DecisionFatigue::Runners::DecisionFatigue

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

Instance Method Summary collapse

Instance Method Details

#decisions_by_type(decision_type:) ⇒ Object



64
65
66
67
68
# File 'lib/legion/extensions/agentic/executive/decision_fatigue/runners/decision_fatigue.rb', line 64

def decisions_by_type(decision_type:, **)
  decisions = fatigue_engine.decisions_by_type(decision_type: decision_type)
  Legion::Logging.debug "[decision_fatigue] decisions_by_type: type=#{decision_type} count=#{decisions.size}"
  { decisions: decisions.map(&:to_h), count: decisions.size, decision_type: decision_type }
end

#fatigue_statusObject



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

def fatigue_status(**)
  report = fatigue_engine.fatigue_report
  Legion::Logging.debug "[decision_fatigue] status: quality=#{report[:quality_label]} " \
                        "willpower=#{report[:willpower]} total=#{report[:total_decisions]}"
  report
end

#full_restObject



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

def full_rest(**)
  before = fatigue_engine.willpower
  fatigue_engine.full_rest!
  Legion::Logging.info "[decision_fatigue] full_rest: willpower #{before.round(2)}->1.0"
  {
    recovered:     (1.0 - before).round(4),
    willpower:     1.0,
    quality:       1.0,
    quality_label: :optimal
  }
end

#make_decision(label:, decision_type: :routine, complexity: 0.5) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
# File 'lib/legion/extensions/agentic/executive/decision_fatigue/runners/decision_fatigue.rb', line 13

def make_decision(label:, decision_type: :routine, complexity: 0.5, **)
  record = fatigue_engine.make_decision(
    label:         label,
    decision_type: decision_type,
    complexity:    complexity
  )
  Legion::Logging.info "[decision_fatigue] decision made: label=#{label} type=#{decision_type} " \
                       "complexity=#{complexity.round(2)} quality=#{record.quality_at_time.round(2)} " \
                       "willpower=#{fatigue_engine.willpower.round(2)}"
  record.to_h
end

#quality_trend(window: 10) ⇒ Object



70
71
72
73
74
75
# File 'lib/legion/extensions/agentic/executive/decision_fatigue/runners/decision_fatigue.rb', line 70

def quality_trend(window: 10, **)
  trend = fatigue_engine.quality_trend(window: window)
  label = Helpers::Constants.quality_label_for(trend)
  Legion::Logging.debug "[decision_fatigue] quality_trend: window=#{window} trend=#{trend.round(2)} label=#{label}"
  { trend: trend.round(4), label: label, window: window }
end

#recent_decisions(limit: 10) ⇒ Object



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

def recent_decisions(limit: 10, **)
  decisions = fatigue_engine.recent_decisions(limit: limit)
  Legion::Logging.debug "[decision_fatigue] recent_decisions: limit=#{limit} returned=#{decisions.size}"
  { decisions: decisions.map(&:to_h), count: decisions.size }
end

#rest(amount: nil) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/legion/extensions/agentic/executive/decision_fatigue/runners/decision_fatigue.rb', line 32

def rest(amount: nil, **)
  amt = amount || Helpers::Constants::RECOVERY_RATE
  before = fatigue_engine.willpower
  fatigue_engine.rest!(amount: amt)
  after = fatigue_engine.willpower
  Legion::Logging.debug "[decision_fatigue] rest: amount=#{amt} willpower #{before.round(2)}->#{after.round(2)}"
  {
    recovered:     (after - before).round(4),
    willpower:     after.round(4),
    quality:       fatigue_engine.current_quality.round(4),
    quality_label: fatigue_engine.quality_label
  }
end

#should_restObject



77
78
79
80
81
# File 'lib/legion/extensions/agentic/executive/decision_fatigue/runners/decision_fatigue.rb', line 77

def should_rest(**)
  result = fatigue_engine.should_rest?
  Legion::Logging.debug "[decision_fatigue] should_rest: #{result}"
  { should_rest: result, willpower: fatigue_engine.willpower.round(4) }
end