Class: Legion::Extensions::Agentic::Integration::Mycelium::Helpers::Hypha

Inherits:
Object
  • Object
show all
Defined in:
lib/legion/extensions/agentic/integration/mycelium/helpers/hypha.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source_id:, target_id:, nutrient_type:, strength: 0.5) ⇒ Hypha

Returns a new instance of Hypha.



14
15
16
17
18
19
20
21
22
23
24
# File 'lib/legion/extensions/agentic/integration/mycelium/helpers/hypha.rb', line 14

def initialize(source_id:, target_id:, nutrient_type:,
               strength: 0.5)
  validate_nutrient!(nutrient_type)
  @id            = SecureRandom.uuid
  @source_id     = source_id
  @target_id     = target_id
  @nutrient_type = nutrient_type.to_sym
  @strength      = strength.to_f.clamp(0.0, 1.0).round(10)
  @state         = :growing
  @created_at    = Time.now.utc
end

Instance Attribute Details

#created_atObject (readonly)

Returns the value of attribute created_at.



10
11
12
# File 'lib/legion/extensions/agentic/integration/mycelium/helpers/hypha.rb', line 10

def created_at
  @created_at
end

#idObject (readonly)

Returns the value of attribute id.



10
11
12
# File 'lib/legion/extensions/agentic/integration/mycelium/helpers/hypha.rb', line 10

def id
  @id
end

#nutrient_typeObject (readonly)

Returns the value of attribute nutrient_type.



10
11
12
# File 'lib/legion/extensions/agentic/integration/mycelium/helpers/hypha.rb', line 10

def nutrient_type
  @nutrient_type
end

#source_idObject (readonly)

Returns the value of attribute source_id.



10
11
12
# File 'lib/legion/extensions/agentic/integration/mycelium/helpers/hypha.rb', line 10

def source_id
  @source_id
end

#stateObject

Returns the value of attribute state.



12
13
14
# File 'lib/legion/extensions/agentic/integration/mycelium/helpers/hypha.rb', line 12

def state
  @state
end

#strengthObject

Returns the value of attribute strength.



12
13
14
# File 'lib/legion/extensions/agentic/integration/mycelium/helpers/hypha.rb', line 12

def strength
  @strength
end

#target_idObject (readonly)

Returns the value of attribute target_id.



10
11
12
# File 'lib/legion/extensions/agentic/integration/mycelium/helpers/hypha.rb', line 10

def target_id
  @target_id
end

Instance Method Details

#active?Boolean

Returns:

  • (Boolean)


43
44
45
# File 'lib/legion/extensions/agentic/integration/mycelium/helpers/hypha.rb', line 43

def active?
  %i[growing mature].include?(@state)
end

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



32
33
34
35
36
37
# File 'lib/legion/extensions/agentic/integration/mycelium/helpers/hypha.rb', line 32

def decay!(rate: Constants::NUTRIENT_DECAY)
  @strength = (@strength - rate.abs).clamp(0.0, 1.0).round(10)
  @state = :decaying if @strength < 0.2
  @state = :dormant if @strength < 0.4 && @state == :mature
  self
end

#reinforce!(amount: 0.1) ⇒ Object



26
27
28
29
30
# File 'lib/legion/extensions/agentic/integration/mycelium/helpers/hypha.rb', line 26

def reinforce!(amount: 0.1)
  @strength = (@strength + amount.abs).clamp(0.0, 1.0).round(10)
  @state = :mature if @strength >= 0.6
  self
end

#to_hObject



47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/legion/extensions/agentic/integration/mycelium/helpers/hypha.rb', line 47

def to_h
  {
    id:                @id,
    source_id:         @source_id,
    target_id:         @target_id,
    nutrient_type:     @nutrient_type,
    strength:          @strength,
    state:             @state,
    transfer_capacity: transfer_capacity,
    active:            active?,
    created_at:        @created_at
  }
end

#transfer_capacityObject



39
40
41
# File 'lib/legion/extensions/agentic/integration/mycelium/helpers/hypha.rb', line 39

def transfer_capacity
  (@strength * Constants::TRANSFER_EFFICIENCY).round(10)
end