Class: Legion::Extensions::Agentic::Homeostasis::FatigueModel::Helpers::FatigueEngine

Inherits:
Object
  • Object
show all
Includes:
Constants
Defined in:
lib/legion/extensions/agentic/homeostasis/fatigue_model/helpers/fatigue_engine.rb

Constant Summary

Constants included from Constants

Constants::CHANNELS, Constants::DEFAULT_ENERGY, Constants::DELEGATION_THRESHOLD, Constants::DEPLETION_RATES, Constants::ENERGY_CEILING, Constants::ENERGY_FLOOR, Constants::FATIGUE_LABELS, Constants::MAX_HISTORY, Constants::RECOVERY_RATES, Constants::REST_THRESHOLD

Instance Method Summary collapse

Constructor Details

#initializeFatigueEngine

Returns a new instance of FatigueEngine.



12
13
14
15
# File 'lib/legion/extensions/agentic/homeostasis/fatigue_model/helpers/fatigue_engine.rb', line 12

def initialize
  @channels = {}
  CHANNELS.each { |name| create_channel(name: name) }
end

Instance Method Details

#channel_status(channel_name:) ⇒ Object



38
39
40
# File 'lib/legion/extensions/agentic/homeostasis/fatigue_model/helpers/fatigue_engine.rb', line 38

def channel_status(channel_name:)
  fetch_channel(channel_name).to_h
end

#channels_needing_restObject



55
56
57
# File 'lib/legion/extensions/agentic/homeostasis/fatigue_model/helpers/fatigue_engine.rb', line 55

def channels_needing_rest
  @channels.values.select(&:needs_rest?).map(&:to_h)
end

#create_channel(name:) ⇒ Object



17
18
19
# File 'lib/legion/extensions/agentic/homeostasis/fatigue_model/helpers/fatigue_engine.rb', line 17

def create_channel(name:)
  @channels[name] = Channel.new(name: name)
end

#delegation_recommendationsObject



59
60
61
# File 'lib/legion/extensions/agentic/homeostasis/fatigue_model/helpers/fatigue_engine.rb', line 59

def delegation_recommendations
  @channels.values.select(&:needs_delegation?).map(&:to_h)
end

#most_fatigued_channelObject



49
50
51
52
53
# File 'lib/legion/extensions/agentic/homeostasis/fatigue_model/helpers/fatigue_engine.rb', line 49

def most_fatigued_channel
  return nil if @channels.empty?

  @channels.values.min_by(&:energy).to_h
end

#overall_fatigueObject



42
43
44
45
46
47
# File 'lib/legion/extensions/agentic/homeostasis/fatigue_model/helpers/fatigue_engine.rb', line 42

def overall_fatigue
  return 0.0 if @channels.empty?

  total = @channels.values.sum(&:energy)
  total / @channels.size
end

#process_task(channel_name:) ⇒ Object



21
22
23
24
25
# File 'lib/legion/extensions/agentic/homeostasis/fatigue_model/helpers/fatigue_engine.rb', line 21

def process_task(channel_name:)
  channel = fetch_channel(channel_name)
  channel.deplete!
  channel.to_h
end

#quality_reportObject



63
64
65
# File 'lib/legion/extensions/agentic/homeostasis/fatigue_model/helpers/fatigue_engine.rb', line 63

def quality_report
  @channels.transform_values(&:quality_modifier)
end

#rest_allObject



33
34
35
36
# File 'lib/legion/extensions/agentic/homeostasis/fatigue_model/helpers/fatigue_engine.rb', line 33

def rest_all
  @channels.each_value(&:recover!)
  to_h
end

#rest_channel(channel_name:) ⇒ Object



27
28
29
30
31
# File 'lib/legion/extensions/agentic/homeostasis/fatigue_model/helpers/fatigue_engine.rb', line 27

def rest_channel(channel_name:)
  channel = fetch_channel(channel_name)
  channel.recover!
  channel.to_h
end

#to_hObject



67
68
69
70
71
72
73
# File 'lib/legion/extensions/agentic/homeostasis/fatigue_model/helpers/fatigue_engine.rb', line 67

def to_h
  {
    channels:        @channels.transform_values(&:to_h),
    overall_fatigue: overall_fatigue.round(4),
    channel_count:   @channels.size
  }
end