Class: Legion::Extensions::Agentic::Inference::Gravity::Helpers::GravityEngine
- Inherits:
-
Object
- Object
- Legion::Extensions::Agentic::Inference::Gravity::Helpers::GravityEngine
- Defined in:
- lib/legion/extensions/agentic/inference/gravity/helpers/gravity_engine.rb
Instance Attribute Summary collapse
-
#attractors ⇒ Object
readonly
Returns the value of attribute attractors.
-
#capture_events ⇒ Object
readonly
Returns the value of attribute capture_events.
-
#escape_events ⇒ Object
readonly
Returns the value of attribute escape_events.
-
#orbiting_thoughts ⇒ Object
readonly
Returns the value of attribute orbiting_thoughts.
Instance Method Summary collapse
- #accrete_attractor(attractor_id, amount: Constants::MASS_ACCRETION) ⇒ Object
- #add_attractor(content:, domain: :unknown, mass: Constants::DEFAULT_MASS, pull_radius: 1.0, decay_rate: 0.01) ⇒ Object
- #add_orbiting_thought(content:, attractor_id:, orbital_distance: 1.0, velocity: 0.0) ⇒ Object
- #cognitive_density_map ⇒ Object
- #erode_attractor(attractor_id, amount: Constants::MASS_EROSION) ⇒ Object
- #gravity_report ⇒ Object
-
#initialize ⇒ GravityEngine
constructor
A new instance of GravityEngine.
- #simulate_tick ⇒ Object
- #strongest_attractors(limit: 5) ⇒ Object
- #thought_distribution ⇒ Object
Constructor Details
#initialize ⇒ GravityEngine
Returns a new instance of GravityEngine.
12 13 14 15 16 17 |
# File 'lib/legion/extensions/agentic/inference/gravity/helpers/gravity_engine.rb', line 12 def initialize @attractors = {} @orbiting_thoughts = {} @capture_events = [] @escape_events = [] end |
Instance Attribute Details
#attractors ⇒ Object (readonly)
Returns the value of attribute attractors.
10 11 12 |
# File 'lib/legion/extensions/agentic/inference/gravity/helpers/gravity_engine.rb', line 10 def attractors @attractors end |
#capture_events ⇒ Object (readonly)
Returns the value of attribute capture_events.
10 11 12 |
# File 'lib/legion/extensions/agentic/inference/gravity/helpers/gravity_engine.rb', line 10 def capture_events @capture_events end |
#escape_events ⇒ Object (readonly)
Returns the value of attribute escape_events.
10 11 12 |
# File 'lib/legion/extensions/agentic/inference/gravity/helpers/gravity_engine.rb', line 10 def escape_events @escape_events end |
#orbiting_thoughts ⇒ Object (readonly)
Returns the value of attribute orbiting_thoughts.
10 11 12 |
# File 'lib/legion/extensions/agentic/inference/gravity/helpers/gravity_engine.rb', line 10 def orbiting_thoughts @orbiting_thoughts end |
Instance Method Details
#accrete_attractor(attractor_id, amount: Constants::MASS_ACCRETION) ⇒ Object
81 82 83 84 85 86 87 |
# File 'lib/legion/extensions/agentic/inference/gravity/helpers/gravity_engine.rb', line 81 def accrete_attractor(attractor_id, amount: Constants::MASS_ACCRETION) attractor = @attractors[attractor_id] return { error: :not_found } unless attractor attractor.accrete!(amount) { accreted: true, id: attractor_id, mass: attractor.mass } end |
#add_attractor(content:, domain: :unknown, mass: Constants::DEFAULT_MASS, pull_radius: 1.0, decay_rate: 0.01) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/legion/extensions/agentic/inference/gravity/helpers/gravity_engine.rb', line 19 def add_attractor(content:, domain: :unknown, mass: Constants::DEFAULT_MASS, pull_radius: 1.0, decay_rate: 0.01) return { error: :capacity_exceeded, max: Constants::MAX_ATTRACTORS } if at_attractor_capacity? attractor = Attractor.new( content: content, domain: domain, mass: mass, pull_radius: pull_radius, decay_rate: decay_rate ) @attractors[attractor.id] = attractor attractor end |
#add_orbiting_thought(content:, attractor_id:, orbital_distance: 1.0, velocity: 0.0) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/legion/extensions/agentic/inference/gravity/helpers/gravity_engine.rb', line 34 def add_orbiting_thought(content:, attractor_id:, orbital_distance: 1.0, velocity: 0.0) return { error: :attractor_not_found } unless @attractors.key?(attractor_id) return { error: :capacity_exceeded, max: Constants::MAX_ORBITING } if at_orbiting_capacity? thought = OrbitingThought.new( content: content, attractor_id: attractor_id, orbital_distance: orbital_distance, velocity: velocity ) @orbiting_thoughts[thought.id] = thought thought end |
#cognitive_density_map ⇒ Object
108 109 110 111 112 |
# File 'lib/legion/extensions/agentic/inference/gravity/helpers/gravity_engine.rb', line 108 def cognitive_density_map thought_distribution.transform_values do |count| Constants.label_for(Constants::DENSITY_LABELS, count) end end |
#erode_attractor(attractor_id, amount: Constants::MASS_EROSION) ⇒ Object
89 90 91 92 93 94 95 |
# File 'lib/legion/extensions/agentic/inference/gravity/helpers/gravity_engine.rb', line 89 def erode_attractor(attractor_id, amount: Constants::MASS_EROSION) attractor = @attractors[attractor_id] return { error: :not_found } unless attractor attractor.erode!(amount) { eroded: true, id: attractor_id, mass: attractor.mass, collapsed: attractor.collapsed? } end |
#gravity_report ⇒ Object
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'lib/legion/extensions/agentic/inference/gravity/helpers/gravity_engine.rb', line 114 def gravity_report collapsed, active = @attractors.values.partition(&:collapsed?) supermass = @attractors.values.select(&:supermassive?) captured = @orbiting_thoughts.values.select(&:captured?) escaped = @orbiting_thoughts.values.select(&:escaped?) { total_attractors: @attractors.size, active_attractors: active.size, collapsed_attractors: collapsed.size, supermassive_count: supermass.size, total_orbiting: @orbiting_thoughts.size, captured_count: captured.size, escaped_count: escaped.size, total_captures: @capture_events.size, total_escapes: @escape_events.size, strongest: strongest_attractors(limit: 3).map(&:to_h) } end |
#simulate_tick ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/legion/extensions/agentic/inference/gravity/helpers/gravity_engine.rb', line 48 def simulate_tick captures = [] escapes = [] @attractors.each_value do |attractor| next if attractor.collapsed? thoughts_for(attractor.id).each do |thought| pull = attractor.pull_strength_at(distance: thought.orbital_distance) next unless pull.positive? was_captured = thought.captured? was_escaped = thought.escaped? thought.approach!(pull) if !was_captured && thought.captured? event = build_event(:capture, attractor, thought) captures << event @capture_events << event end next unless !was_escaped && thought.escaped? event = build_event(:escape, attractor, thought) escapes << event @escape_events << event end end { captures: captures, escapes: escapes, tick_processed: true } end |
#strongest_attractors(limit: 5) ⇒ Object
97 98 99 100 101 102 |
# File 'lib/legion/extensions/agentic/inference/gravity/helpers/gravity_engine.rb', line 97 def strongest_attractors(limit: 5) @attractors.values .reject(&:collapsed?) .sort_by { |a| -a.mass } .first(limit) end |
#thought_distribution ⇒ Object
104 105 106 |
# File 'lib/legion/extensions/agentic/inference/gravity/helpers/gravity_engine.rb', line 104 def thought_distribution @attractors.transform_values { |a| thoughts_for(a.id).size } end |