Class: Legion::Extensions::Agentic::Inference::Momentum::Helpers::MomentumEngine
- Inherits:
-
Object
- Object
- Legion::Extensions::Agentic::Inference::Momentum::Helpers::MomentumEngine
show all
- Includes:
- Constants
- Defined in:
- lib/legion/extensions/agentic/inference/momentum/helpers/momentum_engine.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
Returns a new instance of MomentumEngine.
14
15
16
17
|
# File 'lib/legion/extensions/agentic/inference/momentum/helpers/momentum_engine.rb', line 14
def initialize
@ideas = {}
@history = []
end
|
Instance Attribute Details
#history ⇒ Object
Returns the value of attribute history.
12
13
14
|
# File 'lib/legion/extensions/agentic/inference/momentum/helpers/momentum_engine.rb', line 12
def history
@history
end
|
Instance Method Details
#apply_force(idea_id:, force:) ⇒ Object
48
49
50
51
52
53
54
55
|
# File 'lib/legion/extensions/agentic/inference/momentum/helpers/momentum_engine.rb', line 48
def apply_force(idea_id:, force:)
idea = @ideas[idea_id]
return { success: false, reason: :not_found } unless idea
idea.apply_force(force: force)
record_history(:force_applied, idea_id)
{ success: true, momentum: idea.momentum, velocity: idea.velocity }
end
|
#apply_friction_all ⇒ Object
85
86
87
|
# File 'lib/legion/extensions/agentic/inference/momentum/helpers/momentum_engine.rb', line 85
def apply_friction_all
@ideas.each_value(&:apply_friction!)
end
|
#challenge_idea(idea_id:) ⇒ Object
39
40
41
42
43
44
45
46
|
# File 'lib/legion/extensions/agentic/inference/momentum/helpers/momentum_engine.rb', line 39
def challenge_idea(idea_id:)
idea = @ideas[idea_id]
return { success: false, reason: :not_found } unless idea
idea.challenge!
record_history(:challenged, idea_id)
{ success: true, momentum: idea.momentum, mass: idea.mass, velocity: idea.velocity }
end
|
#create_idea(content:, idea_type:, domain:, mass: DEFAULT_MASS) ⇒ Object
19
20
21
22
23
24
25
26
27
28
|
# File 'lib/legion/extensions/agentic/inference/momentum/helpers/momentum_engine.rb', line 19
def create_idea(content:, idea_type:, domain:, mass: DEFAULT_MASS)
return nil unless IDEA_TYPES.include?(idea_type)
evict_oldest if @ideas.size >= MAX_IDEAS
idea = Idea.new(content: content, idea_type: idea_type, domain: domain, mass: mass)
@ideas[idea.id] = idea
record_history(:created, idea.id)
idea
end
|
#entrenched_ideas ⇒ Object
65
66
67
|
# File 'lib/legion/extensions/agentic/inference/momentum/helpers/momentum_engine.rb', line 65
def entrenched_ideas
@ideas.values.select(&:entrenched?)
end
|
#highest_momentum(limit: 5) ⇒ Object
77
78
79
|
# File 'lib/legion/extensions/agentic/inference/momentum/helpers/momentum_engine.rb', line 77
def highest_momentum(limit: 5)
@ideas.values.sort_by { |idea| -idea.momentum }.first(limit)
end
|
#ideas_by_domain(domain:) ⇒ Object
73
74
75
|
# File 'lib/legion/extensions/agentic/inference/momentum/helpers/momentum_engine.rb', line 73
def ideas_by_domain(domain:)
@ideas.values.select { |idea| idea.domain == domain }
end
|
#ideas_by_type(idea_type:) ⇒ Object
69
70
71
|
# File 'lib/legion/extensions/agentic/inference/momentum/helpers/momentum_engine.rb', line 69
def ideas_by_type(idea_type:)
@ideas.values.select { |idea| idea.idea_type == idea_type }
end
|
#most_entrenched(limit: 5) ⇒ Object
81
82
83
|
# File 'lib/legion/extensions/agentic/inference/momentum/helpers/momentum_engine.rb', line 81
def most_entrenched(limit: 5)
@ideas.values.sort_by { |idea| -idea.mass }.first(limit)
end
|
#prune_at_rest ⇒ Object
89
90
91
92
93
|
# File 'lib/legion/extensions/agentic/inference/momentum/helpers/momentum_engine.rb', line 89
def prune_at_rest
ids = @ideas.select { |_id, idea| idea.at_rest? && idea.mass <= MASS_FLOOR + 0.01 }.keys
ids.each { |idea_id| @ideas.delete(idea_id) }
ids.size
end
|
#reinforce_idea(idea_id:) ⇒ Object
30
31
32
33
34
35
36
37
|
# File 'lib/legion/extensions/agentic/inference/momentum/helpers/momentum_engine.rb', line 30
def reinforce_idea(idea_id:)
idea = @ideas[idea_id]
return { success: false, reason: :not_found } unless idea
idea.reinforce!
record_history(:reinforced, idea_id)
{ success: true, momentum: idea.momentum, mass: idea.mass, velocity: idea.velocity }
end
|
#reversing_ideas ⇒ Object
61
62
63
|
# File 'lib/legion/extensions/agentic/inference/momentum/helpers/momentum_engine.rb', line 61
def reversing_ideas
@ideas.values.select(&:reversing?)
end
|
#surging_ideas ⇒ Object
57
58
59
|
# File 'lib/legion/extensions/agentic/inference/momentum/helpers/momentum_engine.rb', line 57
def surging_ideas
@ideas.values.select(&:surging?)
end
|
#to_h ⇒ Object
95
96
97
98
99
100
101
102
103
104
|
# File 'lib/legion/extensions/agentic/inference/momentum/helpers/momentum_engine.rb', line 95
def to_h
{
total_ideas: @ideas.size,
surging_count: surging_ideas.size,
reversing_count: reversing_ideas.size,
entrenched_count: entrenched_ideas.size,
avg_momentum: avg_momentum,
history_count: @history.size
}
end
|