Class: Legion::Extensions::Agentic::Inference::Gravity::Helpers::OrbitingThought

Inherits:
Object
  • Object
show all
Defined in:
lib/legion/extensions/agentic/inference/gravity/helpers/orbiting_thought.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(content:, attractor_id:, orbital_distance: 1.0, velocity: 0.0) ⇒ OrbitingThought

Returns a new instance of OrbitingThought.



14
15
16
17
18
19
20
21
# File 'lib/legion/extensions/agentic/inference/gravity/helpers/orbiting_thought.rb', line 14

def initialize(content:, attractor_id:, orbital_distance: 1.0, velocity: 0.0)
  @id               = SecureRandom.uuid
  @content          = content
  @attractor_id     = attractor_id
  @orbital_distance = orbital_distance.clamp(0.0, Float::INFINITY).round(10)
  @velocity         = velocity.to_f.round(10)
  @created_at       = Time.now.utc
end

Instance Attribute Details

#attractor_idObject (readonly)

Returns the value of attribute attractor_id.



12
13
14
# File 'lib/legion/extensions/agentic/inference/gravity/helpers/orbiting_thought.rb', line 12

def attractor_id
  @attractor_id
end

#contentObject (readonly)

Returns the value of attribute content.



12
13
14
# File 'lib/legion/extensions/agentic/inference/gravity/helpers/orbiting_thought.rb', line 12

def content
  @content
end

#created_atObject (readonly)

Returns the value of attribute created_at.



12
13
14
# File 'lib/legion/extensions/agentic/inference/gravity/helpers/orbiting_thought.rb', line 12

def created_at
  @created_at
end

#idObject (readonly)

Returns the value of attribute id.



12
13
14
# File 'lib/legion/extensions/agentic/inference/gravity/helpers/orbiting_thought.rb', line 12

def id
  @id
end

#orbital_distanceObject (readonly)

Returns the value of attribute orbital_distance.



12
13
14
# File 'lib/legion/extensions/agentic/inference/gravity/helpers/orbiting_thought.rb', line 12

def orbital_distance
  @orbital_distance
end

#velocityObject (readonly)

Returns the value of attribute velocity.



12
13
14
# File 'lib/legion/extensions/agentic/inference/gravity/helpers/orbiting_thought.rb', line 12

def velocity
  @velocity
end

Instance Method Details

#approach!(delta) ⇒ Object



23
24
25
26
# File 'lib/legion/extensions/agentic/inference/gravity/helpers/orbiting_thought.rb', line 23

def approach!(delta)
  @orbital_distance = [(@orbital_distance - delta.abs).round(10), 0.0].max
  self
end

#captured?Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/legion/extensions/agentic/inference/gravity/helpers/orbiting_thought.rb', line 33

def captured?
  @orbital_distance < Constants::CAPTURE_RADIUS
end

#escape!(delta) ⇒ Object



28
29
30
31
# File 'lib/legion/extensions/agentic/inference/gravity/helpers/orbiting_thought.rb', line 28

def escape!(delta)
  @orbital_distance = (@orbital_distance + delta.abs).round(10)
  self
end

#escaped?Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/legion/extensions/agentic/inference/gravity/helpers/orbiting_thought.rb', line 37

def escaped?
  @orbital_distance > Constants::ESCAPE_RADIUS
end

#orbit_labelObject



41
42
43
# File 'lib/legion/extensions/agentic/inference/gravity/helpers/orbiting_thought.rb', line 41

def orbit_label
  Constants.label_for(Constants::ORBIT_LABELS, @orbital_distance)
end

#to_hObject



45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/legion/extensions/agentic/inference/gravity/helpers/orbiting_thought.rb', line 45

def to_h
  {
    id:               @id,
    content:          @content,
    attractor_id:     @attractor_id,
    orbital_distance: @orbital_distance,
    velocity:         @velocity,
    captured:         captured?,
    escaped:          escaped?,
    orbit_label:      orbit_label,
    created_at:       @created_at
  }
end