Class: Legion::Extensions::Agentic::Social::Symbiosis::Helpers::SymbioticBond

Inherits:
Object
  • Object
show all
Defined in:
lib/legion/extensions/agentic/social/symbiosis/helpers/symbiotic_bond.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(subsystem_a:, subsystem_b:, relationship_type:, strength: nil, benefit_ratio: nil) ⇒ SymbioticBond

Returns a new instance of SymbioticBond.



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/legion/extensions/agentic/social/symbiosis/helpers/symbiotic_bond.rb', line 16

def initialize(subsystem_a:, subsystem_b:, relationship_type:, strength: nil, benefit_ratio: nil)
  validate_relationship_type!(relationship_type)

  @bond_id           = SecureRandom.uuid
  @subsystem_a       = subsystem_a
  @subsystem_b       = subsystem_b
  @relationship_type = relationship_type
  @strength          = (strength || Constants::DEFAULT_STRENGTH).clamp(
    Constants::MIN_STRENGTH, Constants::MAX_STRENGTH
  )
  @benefit_ratio     = benefit_ratio || default_benefit_ratio(relationship_type)
  @activation_count  = 0
  @created_at        = Time.now.utc
  @last_activated_at = nil
end

Instance Attribute Details

#activation_countObject (readonly)

Returns the value of attribute activation_count.



13
14
15
# File 'lib/legion/extensions/agentic/social/symbiosis/helpers/symbiotic_bond.rb', line 13

def activation_count
  @activation_count
end

#benefit_ratioObject (readonly)

Returns the value of attribute benefit_ratio.



13
14
15
# File 'lib/legion/extensions/agentic/social/symbiosis/helpers/symbiotic_bond.rb', line 13

def benefit_ratio
  @benefit_ratio
end

#bond_idObject (readonly)

Returns the value of attribute bond_id.



13
14
15
# File 'lib/legion/extensions/agentic/social/symbiosis/helpers/symbiotic_bond.rb', line 13

def bond_id
  @bond_id
end

#created_atObject (readonly)

Returns the value of attribute created_at.



13
14
15
# File 'lib/legion/extensions/agentic/social/symbiosis/helpers/symbiotic_bond.rb', line 13

def created_at
  @created_at
end

#last_activated_atObject (readonly)

Returns the value of attribute last_activated_at.



13
14
15
# File 'lib/legion/extensions/agentic/social/symbiosis/helpers/symbiotic_bond.rb', line 13

def last_activated_at
  @last_activated_at
end

#relationship_typeObject (readonly)

Returns the value of attribute relationship_type.



13
14
15
# File 'lib/legion/extensions/agentic/social/symbiosis/helpers/symbiotic_bond.rb', line 13

def relationship_type
  @relationship_type
end

#subsystem_aObject (readonly)

Returns the value of attribute subsystem_a.



13
14
15
# File 'lib/legion/extensions/agentic/social/symbiosis/helpers/symbiotic_bond.rb', line 13

def subsystem_a
  @subsystem_a
end

#subsystem_bObject (readonly)

Returns the value of attribute subsystem_b.



13
14
15
# File 'lib/legion/extensions/agentic/social/symbiosis/helpers/symbiotic_bond.rb', line 13

def subsystem_b
  @subsystem_b
end

Instance Method Details

#activate!(amount: 0.05) ⇒ Object



36
37
38
39
40
41
42
# File 'lib/legion/extensions/agentic/social/symbiosis/helpers/symbiotic_bond.rb', line 36

def activate!(amount: 0.05)
  delta = amount.clamp(0.0, 1.0)
  @strength = (@strength + delta).clamp(Constants::MIN_STRENGTH, Constants::MAX_STRENGTH)
  @activation_count += 1
  @last_activated_at = Time.now.utc
  self
end

#decay!(rate: Constants::BOND_DECAY) ⇒ Object



44
45
46
47
# File 'lib/legion/extensions/agentic/social/symbiosis/helpers/symbiotic_bond.rb', line 44

def decay!(rate: Constants::BOND_DECAY)
  @strength = (@strength - rate).clamp(Constants::MIN_STRENGTH, Constants::MAX_STRENGTH)
  self
end

#dormant?Boolean

Returns:

  • (Boolean)


49
50
51
# File 'lib/legion/extensions/agentic/social/symbiosis/helpers/symbiotic_bond.rb', line 49

def dormant?
  @strength <= Constants::DORMANT_THRESHOLD
end

#involves?(subsystem_id) ⇒ Boolean

Returns:

  • (Boolean)


64
65
66
# File 'lib/legion/extensions/agentic/social/symbiosis/helpers/symbiotic_bond.rb', line 64

def involves?(subsystem_id)
  [@subsystem_a, @subsystem_b].include?(subsystem_id)
end

#partner_of(subsystem_id) ⇒ Object



68
69
70
71
72
73
# File 'lib/legion/extensions/agentic/social/symbiosis/helpers/symbiotic_bond.rb', line 68

def partner_of(subsystem_id)
  return @subsystem_b if @subsystem_a == subsystem_id
  return @subsystem_a if @subsystem_b == subsystem_id

  nil
end

#strengthObject



32
33
34
# File 'lib/legion/extensions/agentic/social/symbiosis/helpers/symbiotic_bond.rb', line 32

def strength
  @strength.round(10)
end

#strength_labelObject



57
58
59
60
61
62
# File 'lib/legion/extensions/agentic/social/symbiosis/helpers/symbiotic_bond.rb', line 57

def strength_label
  Constants::INTERACTION_STRENGTHS.each do |range, label|
    return label if range.cover?(@strength)
  end
  :dormant
end

#strong?Boolean

Returns:

  • (Boolean)


53
54
55
# File 'lib/legion/extensions/agentic/social/symbiosis/helpers/symbiotic_bond.rb', line 53

def strong?
  @strength >= Constants::STRONG_THRESHOLD
end

#to_hObject



75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/legion/extensions/agentic/social/symbiosis/helpers/symbiotic_bond.rb', line 75

def to_h
  {
    bond_id:           @bond_id,
    subsystem_a:       @subsystem_a,
    subsystem_b:       @subsystem_b,
    relationship_type: @relationship_type,
    strength:          strength,
    strength_label:    strength_label,
    benefit_ratio:     @benefit_ratio,
    activation_count:  @activation_count,
    dormant:           dormant?,
    strong:            strong?,
    created_at:        @created_at.iso8601,
    last_activated_at: @last_activated_at&.iso8601
  }
end