Class: Legion::Extensions::Agentic::Executive::Inertia::Helpers::InertiaEngine
- Inherits:
-
Object
- Object
- Legion::Extensions::Agentic::Executive::Inertia::Helpers::InertiaEngine
show all
- Includes:
- Constants
- Defined in:
- lib/legion/extensions/agentic/executive/inertia/helpers/inertia_engine.rb
Constant Summary
Constants included
from Constants
Constants::BELIEF_DOMAINS, Constants::CONVICTION_LABELS, Constants::CONVICTION_THRESHOLD, Constants::DEFAULT_INERTIA, Constants::FLEXIBILITY_THRESHOLD, Constants::INERTIA_GROWTH_RATE, Constants::INERTIA_LABELS, Constants::INERTIA_REDUCTION_RATE, Constants::MAX_BELIEFS, Constants::MAX_CHALLENGES
Instance Method Summary
collapse
Constructor Details
Returns a new instance of InertiaEngine.
12
13
14
|
# File 'lib/legion/extensions/agentic/executive/inertia/helpers/inertia_engine.rb', line 12
def initialize
@beliefs = {}
end
|
Instance Method Details
#average_conviction ⇒ Object
62
63
64
65
66
67
|
# File 'lib/legion/extensions/agentic/executive/inertia/helpers/inertia_engine.rb', line 62
def average_conviction
return 0.5 if @beliefs.empty?
convictions = @beliefs.values.map(&:conviction)
(convictions.sum / convictions.size).round(10)
end
|
#average_inertia ⇒ Object
55
56
57
58
59
60
|
# File 'lib/legion/extensions/agentic/executive/inertia/helpers/inertia_engine.rb', line 55
def average_inertia
return DEFAULT_INERTIA if @beliefs.empty?
inertias = @beliefs.values.map(&:inertia)
(inertias.sum / inertias.size).round(10)
end
|
#beliefs_by_domain(domain:) ⇒ Object
46
47
48
49
|
# File 'lib/legion/extensions/agentic/executive/inertia/helpers/inertia_engine.rb', line 46
def beliefs_by_domain(domain:)
d = domain.to_sym
@beliefs.values.select { |b| b.domain == d }
end
|
#challenge_belief(belief_id:, strength: 0.5) ⇒ Object
23
24
25
26
27
28
29
|
# File 'lib/legion/extensions/agentic/executive/inertia/helpers/inertia_engine.rb', line 23
def challenge_belief(belief_id:, strength: 0.5)
belief = @beliefs[belief_id]
return nil unless belief
outcome = belief.challenge!(strength: strength)
{ outcome: outcome, belief: belief }
end
|
#entrenched_beliefs ⇒ Object
38
39
40
|
# File 'lib/legion/extensions/agentic/executive/inertia/helpers/inertia_engine.rb', line 38
def entrenched_beliefs
@beliefs.values.select(&:entrenched?)
end
|
#flexible_beliefs ⇒ Object
42
43
44
|
# File 'lib/legion/extensions/agentic/executive/inertia/helpers/inertia_engine.rb', line 42
def flexible_beliefs
@beliefs.values.select(&:flexible?)
end
|
16
17
18
19
20
21
|
# File 'lib/legion/extensions/agentic/executive/inertia/helpers/inertia_engine.rb', line 16
def form_belief(content:, domain: :factual, conviction: 0.5)
prune_if_needed
belief = Belief.new(content: content, domain: domain, conviction: conviction)
@beliefs[belief.id] = belief
belief
end
|
#inertia_report ⇒ Object
75
76
77
78
79
80
81
82
83
84
85
|
# File 'lib/legion/extensions/agentic/executive/inertia/helpers/inertia_engine.rb', line 75
def inertia_report
{
total_beliefs: @beliefs.size,
entrenched_count: entrenched_beliefs.size,
flexible_count: flexible_beliefs.size,
average_inertia: average_inertia,
average_conviction: average_conviction,
overall_flexibility: overall_flexibility,
most_resistant: most_resistant(limit: 3).map(&:to_h)
}
end
|
#most_resistant(limit: 5) ⇒ Object
51
52
53
|
# File 'lib/legion/extensions/agentic/executive/inertia/helpers/inertia_engine.rb', line 51
def most_resistant(limit: 5)
@beliefs.values.sort_by { |b| -b.resistance_rate }.first(limit)
end
|
#overall_flexibility ⇒ Object
69
70
71
72
73
|
# File 'lib/legion/extensions/agentic/executive/inertia/helpers/inertia_engine.rb', line 69
def overall_flexibility
return 0.5 if @beliefs.empty?
(1.0 - average_inertia).round(10)
end
|
#reinforce_belief(belief_id:, amount: 0.1) ⇒ Object
31
32
33
34
35
36
|
# File 'lib/legion/extensions/agentic/executive/inertia/helpers/inertia_engine.rb', line 31
def reinforce_belief(belief_id:, amount: 0.1)
belief = @beliefs[belief_id]
return nil unless belief
belief.reinforce!(amount: amount)
end
|
#to_h ⇒ Object
87
88
89
90
91
92
93
94
95
|
# File 'lib/legion/extensions/agentic/executive/inertia/helpers/inertia_engine.rb', line 87
def to_h
{
total_beliefs: @beliefs.size,
entrenched_count: entrenched_beliefs.size,
flexible_count: flexible_beliefs.size,
average_inertia: average_inertia,
overall_flexibility: overall_flexibility
}
end
|