Class: Legion::Extensions::Agentic::Self::Architecture::Helpers::Subsystem

Inherits:
Object
  • Object
show all
Includes:
Constants
Defined in:
lib/legion/extensions/agentic/self/architecture/helpers/subsystem.rb

Constant Summary

Constants included from Constants

Constants::BOTTLENECK_THRESHOLD, Constants::CONNECTION_TYPES, Constants::DEFAULT_HEALTH, Constants::HEALTH_BOOST, Constants::HEALTH_DECAY, Constants::HEALTH_LABELS, Constants::MAX_CONNECTIONS, Constants::MAX_HISTORY, Constants::MAX_SUBSYSTEMS, Constants::STATUS_LEVELS, Constants::SUBSYSTEM_TYPES

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name:, subsystem_type:, health: Constants::DEFAULT_HEALTH) ⇒ Subsystem

Returns a new instance of Subsystem.



17
18
19
20
21
22
23
24
25
26
27
# File 'lib/legion/extensions/agentic/self/architecture/helpers/subsystem.rb', line 17

def initialize(name:, subsystem_type:, health: Constants::DEFAULT_HEALTH)
  @id               = SecureRandom.uuid
  @name             = name.to_sym
  @subsystem_type   = subsystem_type.to_sym
  @health           = health.clamp(0.0, 1.0)
  @status           = :active
  @load             = 0.0
  @activation_count = 0
  @last_activated_at = nil
  @created_at       = Time.now.utc
end

Instance Attribute Details

#activation_countObject (readonly)

Returns the value of attribute activation_count.



14
15
16
# File 'lib/legion/extensions/agentic/self/architecture/helpers/subsystem.rb', line 14

def activation_count
  @activation_count
end

#created_atObject (readonly)

Returns the value of attribute created_at.



14
15
16
# File 'lib/legion/extensions/agentic/self/architecture/helpers/subsystem.rb', line 14

def created_at
  @created_at
end

#healthObject

Returns the value of attribute health.



15
16
17
# File 'lib/legion/extensions/agentic/self/architecture/helpers/subsystem.rb', line 15

def health
  @health
end

#idObject (readonly)

Returns the value of attribute id.



14
15
16
# File 'lib/legion/extensions/agentic/self/architecture/helpers/subsystem.rb', line 14

def id
  @id
end

#last_activated_atObject (readonly)

Returns the value of attribute last_activated_at.



14
15
16
# File 'lib/legion/extensions/agentic/self/architecture/helpers/subsystem.rb', line 14

def last_activated_at
  @last_activated_at
end

#loadObject

Returns the value of attribute load.



15
16
17
# File 'lib/legion/extensions/agentic/self/architecture/helpers/subsystem.rb', line 15

def load
  @load
end

#nameObject (readonly)

Returns the value of attribute name.



14
15
16
# File 'lib/legion/extensions/agentic/self/architecture/helpers/subsystem.rb', line 14

def name
  @name
end

#statusObject

Returns the value of attribute status.



15
16
17
# File 'lib/legion/extensions/agentic/self/architecture/helpers/subsystem.rb', line 15

def status
  @status
end

#subsystem_typeObject (readonly)

Returns the value of attribute subsystem_type.



14
15
16
# File 'lib/legion/extensions/agentic/self/architecture/helpers/subsystem.rb', line 14

def subsystem_type
  @subsystem_type
end

Instance Method Details

#activate!Object



29
30
31
32
33
34
# File 'lib/legion/extensions/agentic/self/architecture/helpers/subsystem.rb', line 29

def activate!
  @activation_count += 1
  @last_activated_at = Time.now.utc
  @health = (@health + Constants::HEALTH_BOOST).clamp(0.0, 1.0)
  self
end

#bottlenecked?Boolean

Returns:

  • (Boolean)


48
49
50
# File 'lib/legion/extensions/agentic/self/architecture/helpers/subsystem.rb', line 48

def bottlenecked?
  @load > Constants::BOTTLENECK_THRESHOLD && @health < 0.5
end

#degrade!(amount = Constants::HEALTH_DECAY) ⇒ Object



36
37
38
39
40
# File 'lib/legion/extensions/agentic/self/architecture/helpers/subsystem.rb', line 36

def degrade!(amount = Constants::HEALTH_DECAY)
  @health = (@health - amount).clamp(0.0, 1.0)
  @status = :degraded if @health < 0.4
  self
end

#health_labelObject



52
53
54
55
56
57
# File 'lib/legion/extensions/agentic/self/architecture/helpers/subsystem.rb', line 52

def health_label
  Constants::HEALTH_LABELS.each do |range, label|
    return label if range.cover?(@health)
  end
  :critical
end

#recover!(amount = Constants::HEALTH_BOOST) ⇒ Object



42
43
44
45
46
# File 'lib/legion/extensions/agentic/self/architecture/helpers/subsystem.rb', line 42

def recover!(amount = Constants::HEALTH_BOOST)
  @health = (@health + amount).clamp(0.0, 1.0)
  @status = :active if @health >= 0.4
  self
end

#to_hObject



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/legion/extensions/agentic/self/architecture/helpers/subsystem.rb', line 59

def to_h
  {
    id:                @id,
    name:              @name,
    subsystem_type:    @subsystem_type,
    health:            @health,
    health_label:      health_label,
    status:            @status,
    load:              @load,
    activation_count:  @activation_count,
    last_activated_at: @last_activated_at,
    created_at:        @created_at,
    bottlenecked:      bottlenecked?
  }
end