Class: Legion::Extensions::Agentic::Executive::ExecutiveFunction::Helpers::EfComponent

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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

#capacityObject (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

#fatigueObject (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

#nameObject (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_usesObject (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_capacityObject



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

Returns:

  • (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

#recoverObject



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_hObject



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