Class: Legion::Extensions::Agentic::Memory::Reserve::Helpers::Pathway
- Inherits:
-
Object
- Object
- Legion::Extensions::Agentic::Memory::Reserve::Helpers::Pathway
show all
- Includes:
- Constants
- Defined in:
- lib/legion/extensions/agentic/memory/reserve/helpers/pathway.rb
Constant Summary
Constants included
from Constants
Constants::CAPACITY_CEILING, Constants::CAPACITY_FLOOR, Constants::COMPENSATION_DECAY, Constants::COMPENSATION_EFFICIENCY, Constants::DEFAULT_CAPACITY, Constants::DEGRADED_THRESHOLD, Constants::FAILED_THRESHOLD, Constants::MAX_COMPENSATIONS, Constants::MAX_HISTORY, Constants::MAX_PATHWAYS, Constants::PATHWAY_STATES, Constants::RECOVERY_RATE, Constants::RESERVE_LABELS
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(id:, function:, domain: :general, capacity: DEFAULT_CAPACITY) ⇒ Pathway
Returns a new instance of Pathway.
15
16
17
18
19
20
21
22
23
24
25
|
# File 'lib/legion/extensions/agentic/memory/reserve/helpers/pathway.rb', line 15
def initialize(id:, function:, domain: :general, capacity: DEFAULT_CAPACITY)
@id = id
@function = function
@domain = domain
@capacity = capacity.clamp(CAPACITY_FLOOR, CAPACITY_CEILING)
@backup_ids = []
@damage_count = 0
@compensation_count = 0
@created_at = Time.now.utc
@updated_at = @created_at
end
|
Instance Attribute Details
#backup_ids ⇒ Object
Returns the value of attribute backup_ids.
12
13
14
|
# File 'lib/legion/extensions/agentic/memory/reserve/helpers/pathway.rb', line 12
def backup_ids
@backup_ids
end
|
#capacity ⇒ Object
Returns the value of attribute capacity.
12
13
14
|
# File 'lib/legion/extensions/agentic/memory/reserve/helpers/pathway.rb', line 12
def capacity
@capacity
end
|
#compensation_count ⇒ Object
Returns the value of attribute compensation_count.
12
13
14
|
# File 'lib/legion/extensions/agentic/memory/reserve/helpers/pathway.rb', line 12
def compensation_count
@compensation_count
end
|
#created_at ⇒ Object
Returns the value of attribute created_at.
12
13
14
|
# File 'lib/legion/extensions/agentic/memory/reserve/helpers/pathway.rb', line 12
def created_at
@created_at
end
|
#damage_count ⇒ Object
Returns the value of attribute damage_count.
12
13
14
|
# File 'lib/legion/extensions/agentic/memory/reserve/helpers/pathway.rb', line 12
def damage_count
@damage_count
end
|
#domain ⇒ Object
Returns the value of attribute domain.
12
13
14
|
# File 'lib/legion/extensions/agentic/memory/reserve/helpers/pathway.rb', line 12
def domain
@domain
end
|
#function ⇒ Object
Returns the value of attribute function.
12
13
14
|
# File 'lib/legion/extensions/agentic/memory/reserve/helpers/pathway.rb', line 12
def function
@function
end
|
#id ⇒ Object
Returns the value of attribute id.
12
13
14
|
# File 'lib/legion/extensions/agentic/memory/reserve/helpers/pathway.rb', line 12
def id
@id
end
|
#updated_at ⇒ Object
Returns the value of attribute updated_at.
12
13
14
|
# File 'lib/legion/extensions/agentic/memory/reserve/helpers/pathway.rb', line 12
def updated_at
@updated_at
end
|
Instance Method Details
#add_backup(pathway_id:) ⇒ Object
40
41
42
43
44
45
46
|
# File 'lib/legion/extensions/agentic/memory/reserve/helpers/pathway.rb', line 40
def add_backup(pathway_id:)
return self if @backup_ids.include?(pathway_id)
@backup_ids << pathway_id
@updated_at = Time.now.utc
self
end
|
#compensate! ⇒ Object
54
55
56
57
|
# File 'lib/legion/extensions/agentic/memory/reserve/helpers/pathway.rb', line 54
def compensate!
@compensation_count += 1
@updated_at = Time.now.utc
end
|
#damage(amount:) ⇒ Object
27
28
29
30
31
32
|
# File 'lib/legion/extensions/agentic/memory/reserve/helpers/pathway.rb', line 27
def damage(amount:)
@capacity = (@capacity - amount.abs).clamp(CAPACITY_FLOOR, CAPACITY_CEILING)
@damage_count += 1
@updated_at = Time.now.utc
self
end
|
#degraded? ⇒ Boolean
71
72
73
|
# File 'lib/legion/extensions/agentic/memory/reserve/helpers/pathway.rb', line 71
def degraded?
@capacity <= DEGRADED_THRESHOLD
end
|
#effective_capacity(backup_capacities: []) ⇒ Object
#failed? ⇒ Boolean
75
76
77
|
# File 'lib/legion/extensions/agentic/memory/reserve/helpers/pathway.rb', line 75
def failed?
@capacity <= FAILED_THRESHOLD
end
|
#healthy? ⇒ Boolean
67
68
69
|
# File 'lib/legion/extensions/agentic/memory/reserve/helpers/pathway.rb', line 67
def healthy?
state == :healthy
end
|
#recover(amount: RECOVERY_RATE) ⇒ Object
34
35
36
37
38
|
# File 'lib/legion/extensions/agentic/memory/reserve/helpers/pathway.rb', line 34
def recover(amount: RECOVERY_RATE)
@capacity = (@capacity + amount.abs).clamp(CAPACITY_FLOOR, CAPACITY_CEILING)
@updated_at = Time.now.utc
self
end
|
#redundancy ⇒ Object
87
88
89
|
# File 'lib/legion/extensions/agentic/memory/reserve/helpers/pathway.rb', line 87
def redundancy
@backup_ids.size
end
|
#remove_backup(pathway_id:) ⇒ Object
48
49
50
51
52
|
# File 'lib/legion/extensions/agentic/memory/reserve/helpers/pathway.rb', line 48
def remove_backup(pathway_id:)
@backup_ids.delete(pathway_id)
@updated_at = Time.now.utc
self
end
|
#state ⇒ Object
59
60
61
62
63
64
65
|
# File 'lib/legion/extensions/agentic/memory/reserve/helpers/pathway.rb', line 59
def state
return :failed if @capacity <= FAILED_THRESHOLD
return :compensating if @capacity <= DEGRADED_THRESHOLD && !@backup_ids.empty?
return :degraded if @capacity <= DEGRADED_THRESHOLD
:healthy
end
|
#to_h ⇒ Object
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
|
# File 'lib/legion/extensions/agentic/memory/reserve/helpers/pathway.rb', line 91
def to_h
{
id: @id,
function: @function,
domain: @domain,
capacity: @capacity.round(4),
state: state,
backup_count: @backup_ids.size,
backup_ids: @backup_ids.dup,
damage_count: @damage_count,
compensation_count: @compensation_count,
created_at: @created_at,
updated_at: @updated_at
}
end
|