Class: Legion::Extensions::Agentic::Memory::ImmuneMemory::Helpers::MemoryCell
- Inherits:
-
Object
- Object
- Legion::Extensions::Agentic::Memory::ImmuneMemory::Helpers::MemoryCell
show all
- Includes:
- Constants
- Defined in:
- lib/legion/extensions/agentic/memory/immune_memory/helpers/memory_cell.rb
Constant Summary
Constants included
from Constants
Constants::B_CELL_ACTIVATION_THRESHOLD, Constants::B_CELL_ANTIBODY_PRODUCTION, Constants::B_CELL_BOOST, Constants::B_CELL_DECAY, Constants::CELL_TYPES, Constants::HEALTH_LABELS, Constants::IMMUNITY_LABELS, Constants::MATURITY_LABELS, Constants::MAX_ANTIBODY_LIBRARY, Constants::MAX_ENCOUNTERS, Constants::MAX_MEMORY_CELLS, Constants::MEMORY_RECOGNITION_THRESHOLD, Constants::PRIMARY_RESPONSE_SPEED, Constants::RESPONSE_SPEED_LABELS, Constants::SECONDARY_RESPONSE_SPEED, Constants::THREAT_TYPES, Constants::T_CELL_ACTIVATION_THRESHOLD, Constants::T_CELL_BOOST, Constants::T_CELL_DECAY, Constants::T_CELL_LIFESPAN, Constants::VACCINATION_STRENGTH
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods included from Constants
label_for
Constructor Details
#initialize(threat_type:, signature:, cell_type: :b_memory, strength: VACCINATION_STRENGTH) ⇒ MemoryCell
Returns a new instance of MemoryCell.
18
19
20
21
22
23
24
25
26
27
|
# File 'lib/legion/extensions/agentic/memory/immune_memory/helpers/memory_cell.rb', line 18
def initialize(threat_type:, signature:, cell_type: :b_memory, strength: VACCINATION_STRENGTH)
@id = SecureRandom.uuid
@threat_type = threat_type.to_sym
@signature = signature.to_s
@cell_type = valid_cell_type(cell_type)
@strength = strength.to_f.clamp(0.0, 1.0)
@encounter_count = 0
@decay_cycles = 0
@created_at = Time.now
end
|
Instance Attribute Details
#cell_type ⇒ Object
Returns the value of attribute cell_type.
14
15
16
|
# File 'lib/legion/extensions/agentic/memory/immune_memory/helpers/memory_cell.rb', line 14
def cell_type
@cell_type
end
|
#created_at ⇒ Object
Returns the value of attribute created_at.
14
15
16
|
# File 'lib/legion/extensions/agentic/memory/immune_memory/helpers/memory_cell.rb', line 14
def created_at
@created_at
end
|
#decay_cycles ⇒ Object
Returns the value of attribute decay_cycles.
14
15
16
|
# File 'lib/legion/extensions/agentic/memory/immune_memory/helpers/memory_cell.rb', line 14
def decay_cycles
@decay_cycles
end
|
#encounter_count ⇒ Object
Returns the value of attribute encounter_count.
14
15
16
|
# File 'lib/legion/extensions/agentic/memory/immune_memory/helpers/memory_cell.rb', line 14
def encounter_count
@encounter_count
end
|
#id ⇒ Object
Returns the value of attribute id.
14
15
16
|
# File 'lib/legion/extensions/agentic/memory/immune_memory/helpers/memory_cell.rb', line 14
def id
@id
end
|
#signature ⇒ Object
Returns the value of attribute signature.
14
15
16
|
# File 'lib/legion/extensions/agentic/memory/immune_memory/helpers/memory_cell.rb', line 14
def signature
@signature
end
|
#strength ⇒ Object
Returns the value of attribute strength.
16
17
18
|
# File 'lib/legion/extensions/agentic/memory/immune_memory/helpers/memory_cell.rb', line 16
def strength
@strength
end
|
#threat_type ⇒ Object
Returns the value of attribute threat_type.
14
15
16
|
# File 'lib/legion/extensions/agentic/memory/immune_memory/helpers/memory_cell.rb', line 14
def threat_type
@threat_type
end
|
Instance Method Details
#activate! ⇒ Object
29
30
31
32
33
34
35
|
# File 'lib/legion/extensions/agentic/memory/immune_memory/helpers/memory_cell.rb', line 29
def activate!
@encounter_count += 1
boost = t_cell? ? T_CELL_BOOST : B_CELL_BOOST
@strength = (@strength + boost).clamp(0.0, 1.0).round(10)
@decay_cycles = 0
self
end
|
#active? ⇒ Boolean
53
|
# File 'lib/legion/extensions/agentic/memory/immune_memory/helpers/memory_cell.rb', line 53
def active? = @strength > T_CELL_ACTIVATION_THRESHOLD
|
#b_cell? ⇒ Boolean
49
|
# File 'lib/legion/extensions/agentic/memory/immune_memory/helpers/memory_cell.rb', line 49
def b_cell? = %i[b_memory b_plasma].include?(@cell_type)
|
#decay! ⇒ Object
37
38
39
40
41
42
|
# File 'lib/legion/extensions/agentic/memory/immune_memory/helpers/memory_cell.rb', line 37
def decay!
@decay_cycles += 1
rate = t_cell? ? T_CELL_DECAY : B_CELL_DECAY
@strength = (@strength - rate).clamp(0.0, 1.0).round(10)
self
end
|
#expired? ⇒ Boolean
50
|
# File 'lib/legion/extensions/agentic/memory/immune_memory/helpers/memory_cell.rb', line 50
def expired? = @strength <= 0.0
|
#maturity ⇒ Object
61
|
# File 'lib/legion/extensions/agentic/memory/immune_memory/helpers/memory_cell.rb', line 61
def maturity = (@encounter_count / 10.0).clamp(0.0, 1.0).round(10)
|
#naive? ⇒ Boolean
52
|
# File 'lib/legion/extensions/agentic/memory/immune_memory/helpers/memory_cell.rb', line 52
def naive? = @encounter_count.zero?
|
#recognizes?(threat_signature) ⇒ Boolean
44
45
46
|
# File 'lib/legion/extensions/agentic/memory/immune_memory/helpers/memory_cell.rb', line 44
def recognizes?(threat_signature)
@signature == threat_signature.to_s && @strength >= MEMORY_RECOGNITION_THRESHOLD
end
|
#t_cell? ⇒ Boolean
48
|
# File 'lib/legion/extensions/agentic/memory/immune_memory/helpers/memory_cell.rb', line 48
def t_cell? = %i[t_helper t_killer].include?(@cell_type)
|
#to_h ⇒ Object
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
|
# File 'lib/legion/extensions/agentic/memory/immune_memory/helpers/memory_cell.rb', line 66
def to_h
{
id: @id,
threat_type: @threat_type,
signature: @signature,
cell_type: @cell_type,
strength: @strength,
encounter_count: @encounter_count,
decay_cycles: @decay_cycles,
response_speed: response_speed,
immunity_label: immunity_label,
maturity_label: maturity_label,
t_cell: t_cell?,
b_cell: b_cell?,
expired: expired?,
created_at: @created_at.iso8601
}
end
|
#veteran? ⇒ Boolean
51
|
# File 'lib/legion/extensions/agentic/memory/immune_memory/helpers/memory_cell.rb', line 51
def veteran? = @encounter_count >= 5
|