Class: Legion::Extensions::Agentic::Integration::Mycelium::Helpers::MyceliumEngine
- Inherits:
-
Object
- Object
- Legion::Extensions::Agentic::Integration::Mycelium::Helpers::MyceliumEngine
- Defined in:
- lib/legion/extensions/agentic/integration/mycelium/helpers/mycelium_engine.rb
Instance Method Summary collapse
- #all_fruiting_bodies ⇒ Object
- #all_hyphae ⇒ Object
- #all_nodes ⇒ Object
- #connect(source_id:, target_id:, nutrient_type:, strength: 0.5) ⇒ Object
- #connections_for(node_id) ⇒ Object
- #create_node(node_type:, domain:, content:, nutrient_level: 0.5) ⇒ Object
- #decay_network!(rate: Constants::NUTRIENT_DECAY) ⇒ Object
- #fruit!(node_id:, fruiting_type:, content:) ⇒ Object
-
#initialize ⇒ MyceliumEngine
constructor
A new instance of MyceliumEngine.
- #network_report ⇒ Object
- #transfer_nutrients(hypha_id:) ⇒ Object
Constructor Details
#initialize ⇒ MyceliumEngine
Returns a new instance of MyceliumEngine.
10 11 12 13 14 |
# File 'lib/legion/extensions/agentic/integration/mycelium/helpers/mycelium_engine.rb', line 10 def initialize @nodes = {} @hyphae = {} @fruiting_bodies = {} end |
Instance Method Details
#all_fruiting_bodies ⇒ Object
81 82 83 |
# File 'lib/legion/extensions/agentic/integration/mycelium/helpers/mycelium_engine.rb', line 81 def all_fruiting_bodies @fruiting_bodies.values end |
#all_hyphae ⇒ Object
77 78 79 |
# File 'lib/legion/extensions/agentic/integration/mycelium/helpers/mycelium_engine.rb', line 77 def all_hyphae @hyphae.values end |
#all_nodes ⇒ Object
73 74 75 |
# File 'lib/legion/extensions/agentic/integration/mycelium/helpers/mycelium_engine.rb', line 73 def all_nodes @nodes.values end |
#connect(source_id:, target_id:, nutrient_type:, strength: 0.5) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/legion/extensions/agentic/integration/mycelium/helpers/mycelium_engine.rb', line 27 def connect(source_id:, target_id:, nutrient_type:, strength: 0.5) validate_capacity!(@hyphae, Constants::MAX_HYPHAE, 'hyphae') fetch_node!(source_id) fetch_node!(target_id) hypha = Hypha.new( source_id: source_id, target_id: target_id, nutrient_type: nutrient_type, strength: strength ) @hyphae[hypha.id] = hypha increment_connections(source_id, target_id) hypha end |
#connections_for(node_id) ⇒ Object
85 86 87 88 89 |
# File 'lib/legion/extensions/agentic/integration/mycelium/helpers/mycelium_engine.rb', line 85 def connections_for(node_id) @hyphae.values.select do |h| h.source_id == node_id || h.target_id == node_id end end |
#create_node(node_type:, domain:, content:, nutrient_level: 0.5) ⇒ Object
16 17 18 19 20 21 22 23 24 25 |
# File 'lib/legion/extensions/agentic/integration/mycelium/helpers/mycelium_engine.rb', line 16 def create_node(node_type:, domain:, content:, nutrient_level: 0.5) validate_capacity!(@nodes, Constants::MAX_NODES, 'nodes') node = MycelialNode.new( node_type: node_type, domain: domain, content: content, nutrient_level: nutrient_level ) @nodes[node.id] = node node end |
#decay_network!(rate: Constants::NUTRIENT_DECAY) ⇒ Object
66 67 68 69 70 71 |
# File 'lib/legion/extensions/agentic/integration/mycelium/helpers/mycelium_engine.rb', line 66 def decay_network!(rate: Constants::NUTRIENT_DECAY) @hyphae.each_value { |h| h.decay!(rate: rate) } @nodes.each_value { |n| n.deplete!(rate * 0.5) } prune_dead! { nodes: @nodes.size, hyphae: @hyphae.size } end |
#fruit!(node_id:, fruiting_type:, content:) ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/legion/extensions/agentic/integration/mycelium/helpers/mycelium_engine.rb', line 51 def fruit!(node_id:, fruiting_type:, content:) validate_capacity!(@fruiting_bodies, Constants::MAX_FRUITING_BODIES, 'fruiting bodies') node = fetch_node!(node_id) raise ArgumentError, 'node not ready for fruiting' unless node.fruiting_ready? body = FruitingBody.new( fruiting_type: fruiting_type, source_node_id: node_id, content: content, potency: node.nutrient_level ) node.deplete!(0.3) @fruiting_bodies[body.id] = body body end |
#network_report ⇒ Object
91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/legion/extensions/agentic/integration/mycelium/helpers/mycelium_engine.rb', line 91 def network_report { total_nodes: @nodes.size, total_hyphae: @hyphae.size, total_fruiting: @fruiting_bodies.size, active_hyphae: @hyphae.values.count(&:active?), avg_nutrient: avg_field(@nodes, :nutrient_level), avg_strength: avg_field(@hyphae, :strength), fruiting_ready: @nodes.values.count(&:fruiting_ready?), starving_nodes: @nodes.values.count(&:starving?), network_health: network_health_label } end |
#transfer_nutrients(hypha_id:) ⇒ Object
41 42 43 44 45 46 47 48 49 |
# File 'lib/legion/extensions/agentic/integration/mycelium/helpers/mycelium_engine.rb', line 41 def transfer_nutrients(hypha_id:) hypha = fetch_hypha!(hypha_id) source = fetch_node!(hypha.source_id) target = fetch_node!(hypha.target_id) amount = [hypha.transfer_capacity, source.nutrient_level].min source.deplete!(amount) target.absorb!(amount) { transferred: amount, source: source.to_h, target: target.to_h } end |