Class: Legion::Extensions::Agentic::Executive::ExecutiveFunction::Helpers::EfComponent
- Inherits:
-
Object
- Object
- Legion::Extensions::Agentic::Executive::ExecutiveFunction::Helpers::EfComponent
- Defined in:
- lib/legion/extensions/agentic/executive/executive_function/helpers/ef_component.rb
Constant Summary collapse
- DEFAULT_CAPACITY =
0.7- CAPACITY_FLOOR =
0.1- CAPACITY_CEILING =
1.0- RECOVERY_RATE =
0.02
Instance Attribute Summary collapse
-
#capacity ⇒ Object
readonly
Returns the value of attribute capacity.
-
#fatigue ⇒ Object
readonly
Returns the value of attribute fatigue.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#recent_uses ⇒ Object
readonly
Returns the value of attribute recent_uses.
Instance Method Summary collapse
- #effective_capacity ⇒ Object
- #fatigued? ⇒ Boolean
-
#initialize(name:, capacity: DEFAULT_CAPACITY) ⇒ EfComponent
constructor
A new instance of EfComponent.
- #recover ⇒ Object
- #to_h ⇒ Object
- #use(cost:) ⇒ Object
Constructor Details
#initialize(name:, capacity: DEFAULT_CAPACITY) ⇒ EfComponent
Returns a new instance of EfComponent.
17 18 19 20 21 22 |
# File 'lib/legion/extensions/agentic/executive/executive_function/helpers/ef_component.rb', line 17 def initialize(name:, capacity: DEFAULT_CAPACITY) @name = name @capacity = capacity.clamp(CAPACITY_FLOOR, CAPACITY_CEILING) @fatigue = 0.0 @recent_uses = [] end |
Instance Attribute Details
#capacity ⇒ Object (readonly)
Returns the value of attribute capacity.
15 16 17 |
# File 'lib/legion/extensions/agentic/executive/executive_function/helpers/ef_component.rb', line 15 def capacity @capacity end |
#fatigue ⇒ Object (readonly)
Returns the value of attribute fatigue.
15 16 17 |
# File 'lib/legion/extensions/agentic/executive/executive_function/helpers/ef_component.rb', line 15 def fatigue @fatigue end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
15 16 17 |
# File 'lib/legion/extensions/agentic/executive/executive_function/helpers/ef_component.rb', line 15 def name @name end |
#recent_uses ⇒ Object (readonly)
Returns the value of attribute recent_uses.
15 16 17 |
# File 'lib/legion/extensions/agentic/executive/executive_function/helpers/ef_component.rb', line 15 def recent_uses @recent_uses end |
Instance Method Details
#effective_capacity ⇒ Object
34 35 36 |
# File 'lib/legion/extensions/agentic/executive/executive_function/helpers/ef_component.rb', line 34 def effective_capacity [@capacity - @fatigue, CAPACITY_FLOOR].max end |
#fatigued? ⇒ Boolean
38 39 40 |
# File 'lib/legion/extensions/agentic/executive/executive_function/helpers/ef_component.rb', line 38 def fatigued? effective_capacity <= CAPACITY_FLOOR + 0.05 end |
#recover ⇒ Object
30 31 32 |
# File 'lib/legion/extensions/agentic/executive/executive_function/helpers/ef_component.rb', line 30 def recover @fatigue = [@fatigue - RECOVERY_RATE, 0.0].max end |
#to_h ⇒ Object
42 43 44 45 46 47 48 49 50 51 |
# File 'lib/legion/extensions/agentic/executive/executive_function/helpers/ef_component.rb', line 42 def to_h { name: @name, capacity: @capacity, fatigue: @fatigue.round(4), effective_capacity: effective_capacity.round(4), fatigued: fatigued?, recent_use_count: @recent_uses.size } end |
#use(cost:) ⇒ Object
24 25 26 27 28 |
# File 'lib/legion/extensions/agentic/executive/executive_function/helpers/ef_component.rb', line 24 def use(cost:) @fatigue = [@fatigue + cost, capacity].min @recent_uses << { used_at: Time.now.utc, cost: cost } @recent_uses = @recent_uses.last(50) end |