Class: Legion::Extensions::Agentic::Inference::Momentum::Helpers::Idea

Inherits:
Object
  • Object
show all
Includes:
Constants
Defined in:
lib/legion/extensions/agentic/inference/momentum/helpers/idea.rb

Constant Summary

Constants included from Constants

Constants::CHALLENGE_MASS_REDUCTION, Constants::CHALLENGE_VELOCITY_PENALTY, Constants::DEFAULT_MASS, Constants::DEFAULT_VELOCITY, Constants::FRICTION_RATE, Constants::IDEA_TYPES, Constants::INERTIA_LABELS, Constants::MASS_CEILING, Constants::MASS_FLOOR, Constants::MAX_HISTORY, Constants::MAX_IDEAS, Constants::MIN_FORCE, Constants::MOMENTUM_LABELS, Constants::REINFORCE_MASS_BOOST, Constants::REINFORCE_VELOCITY_BOOST, Constants::VELOCITY_CEILING, Constants::VELOCITY_FLOOR

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(content:, idea_type:, domain:, mass: DEFAULT_MASS) ⇒ Idea

Returns a new instance of Idea.



17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/legion/extensions/agentic/inference/momentum/helpers/idea.rb', line 17

def initialize(content:, idea_type:, domain:, mass: DEFAULT_MASS)
  @id                  = SecureRandom.uuid
  @content             = content
  @idea_type           = idea_type
  @domain              = domain
  @mass                = mass.clamp(MASS_FLOOR, MASS_CEILING)
  @velocity            = DEFAULT_VELOCITY
  @reinforcement_count = 0
  @challenge_count     = 0
  @created_at          = Time.now.utc
  @last_updated_at     = @created_at
end

Instance Attribute Details

#challenge_countObject (readonly)

Returns the value of attribute challenge_count.



14
15
16
# File 'lib/legion/extensions/agentic/inference/momentum/helpers/idea.rb', line 14

def challenge_count
  @challenge_count
end

#contentObject (readonly)

Returns the value of attribute content.



14
15
16
# File 'lib/legion/extensions/agentic/inference/momentum/helpers/idea.rb', line 14

def content
  @content
end

#created_atObject (readonly)

Returns the value of attribute created_at.



14
15
16
# File 'lib/legion/extensions/agentic/inference/momentum/helpers/idea.rb', line 14

def created_at
  @created_at
end

#domainObject (readonly)

Returns the value of attribute domain.



14
15
16
# File 'lib/legion/extensions/agentic/inference/momentum/helpers/idea.rb', line 14

def domain
  @domain
end

#idObject (readonly)

Returns the value of attribute id.



14
15
16
# File 'lib/legion/extensions/agentic/inference/momentum/helpers/idea.rb', line 14

def id
  @id
end

#idea_typeObject (readonly)

Returns the value of attribute idea_type.



14
15
16
# File 'lib/legion/extensions/agentic/inference/momentum/helpers/idea.rb', line 14

def idea_type
  @idea_type
end

#last_updated_atObject (readonly)

Returns the value of attribute last_updated_at.



14
15
16
# File 'lib/legion/extensions/agentic/inference/momentum/helpers/idea.rb', line 14

def last_updated_at
  @last_updated_at
end

#massObject (readonly)

Returns the value of attribute mass.



14
15
16
# File 'lib/legion/extensions/agentic/inference/momentum/helpers/idea.rb', line 14

def mass
  @mass
end

#reinforcement_countObject (readonly)

Returns the value of attribute reinforcement_count.



14
15
16
# File 'lib/legion/extensions/agentic/inference/momentum/helpers/idea.rb', line 14

def reinforcement_count
  @reinforcement_count
end

#velocityObject (readonly)

Returns the value of attribute velocity.



14
15
16
# File 'lib/legion/extensions/agentic/inference/momentum/helpers/idea.rb', line 14

def velocity
  @velocity
end

Instance Method Details

#apply_force(force:) ⇒ Object



56
57
58
59
60
# File 'lib/legion/extensions/agentic/inference/momentum/helpers/idea.rb', line 56

def apply_force(force:)
  acceleration = force / @mass
  @velocity = (@velocity + acceleration).clamp(VELOCITY_FLOOR, VELOCITY_CEILING)
  @last_updated_at = Time.now.utc
end

#apply_friction!Object



62
63
64
65
66
67
68
69
70
71
# File 'lib/legion/extensions/agentic/inference/momentum/helpers/idea.rb', line 62

def apply_friction!
  return if @velocity.zero?

  @velocity = if @velocity.positive?
                [(@velocity - FRICTION_RATE), 0.0].max
              else
                [(@velocity + FRICTION_RATE), 0.0].min
              end
  @last_updated_at = Time.now.utc
end

#at_rest?Boolean

Returns:

  • (Boolean)


81
82
83
# File 'lib/legion/extensions/agentic/inference/momentum/helpers/idea.rb', line 81

def at_rest?
  @velocity.abs < 0.01
end

#challenge!Object



49
50
51
52
53
54
# File 'lib/legion/extensions/agentic/inference/momentum/helpers/idea.rb', line 49

def challenge!
  @challenge_count += 1
  @velocity = (@velocity - CHALLENGE_VELOCITY_PENALTY).clamp(VELOCITY_FLOOR, VELOCITY_CEILING)
  @mass     = (@mass - CHALLENGE_MASS_REDUCTION).clamp(MASS_FLOOR, MASS_CEILING)
  @last_updated_at = Time.now.utc
end

#entrenched?Boolean

Returns:

  • (Boolean)


85
86
87
# File 'lib/legion/extensions/agentic/inference/momentum/helpers/idea.rb', line 85

def entrenched?
  @mass >= 0.8
end

#inertia_labelObject



38
39
40
# File 'lib/legion/extensions/agentic/inference/momentum/helpers/idea.rb', line 38

def inertia_label
  INERTIA_LABELS.find { |range, _| range.cover?(@mass) }&.last || :moderate
end

#momentumObject



30
31
32
# File 'lib/legion/extensions/agentic/inference/momentum/helpers/idea.rb', line 30

def momentum
  @mass * @velocity
end

#momentum_labelObject



34
35
36
# File 'lib/legion/extensions/agentic/inference/momentum/helpers/idea.rb', line 34

def momentum_label
  MOMENTUM_LABELS.find { |range, _| range.cover?(momentum) }&.last || :coasting
end

#reinforce!Object



42
43
44
45
46
47
# File 'lib/legion/extensions/agentic/inference/momentum/helpers/idea.rb', line 42

def reinforce!
  @reinforcement_count += 1
  @mass     = (@mass + REINFORCE_MASS_BOOST).clamp(MASS_FLOOR, MASS_CEILING)
  @velocity = (@velocity + REINFORCE_VELOCITY_BOOST).clamp(VELOCITY_FLOOR, VELOCITY_CEILING)
  @last_updated_at = Time.now.utc
end

#reversing?Boolean

Returns:

  • (Boolean)


77
78
79
# File 'lib/legion/extensions/agentic/inference/momentum/helpers/idea.rb', line 77

def reversing?
  momentum <= -0.2
end

#surging?Boolean

Returns:

  • (Boolean)


73
74
75
# File 'lib/legion/extensions/agentic/inference/momentum/helpers/idea.rb', line 73

def surging?
  momentum >= 0.5
end

#to_hObject



89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/legion/extensions/agentic/inference/momentum/helpers/idea.rb', line 89

def to_h
  {
    id:                  @id,
    content:             @content,
    idea_type:           @idea_type,
    domain:              @domain,
    mass:                @mass,
    velocity:            @velocity,
    momentum:            momentum,
    momentum_label:      momentum_label,
    inertia_label:       inertia_label,
    reinforcement_count: @reinforcement_count,
    challenge_count:     @challenge_count,
    created_at:          @created_at,
    last_updated_at:     @last_updated_at
  }
end