Class: Legion::Extensions::Agentic::Learning::Catalyst::Helpers::CatalystEngine
- Inherits:
-
Object
- Object
- Legion::Extensions::Agentic::Learning::Catalyst::Helpers::CatalystEngine
show all
- Includes:
- Constants
- Defined in:
- lib/legion/extensions/agentic/learning/catalyst/helpers/catalyst_engine.rb
Constant Summary
Constants included
from Constants
Legion::Extensions::Agentic::Learning::Catalyst::Helpers::Constants::ACTIVATION_ENERGY, Legion::Extensions::Agentic::Learning::Catalyst::Helpers::Constants::CATALYST_REDUCTION, Legion::Extensions::Agentic::Learning::Catalyst::Helpers::Constants::CATALYST_TYPES, Legion::Extensions::Agentic::Learning::Catalyst::Helpers::Constants::MAX_CATALYSTS, Legion::Extensions::Agentic::Learning::Catalyst::Helpers::Constants::MAX_REACTIONS, Legion::Extensions::Agentic::Learning::Catalyst::Helpers::Constants::POTENCY_DECAY, Legion::Extensions::Agentic::Learning::Catalyst::Helpers::Constants::POTENCY_LABELS, Legion::Extensions::Agentic::Learning::Catalyst::Helpers::Constants::REACTION_TYPES, Legion::Extensions::Agentic::Learning::Catalyst::Helpers::Constants::SPECIFICITY_BONUS, Legion::Extensions::Agentic::Learning::Catalyst::Helpers::Constants::YIELD_LABELS
Instance Method Summary
collapse
Constructor Details
Returns a new instance of CatalystEngine.
12
13
14
15
|
# File 'lib/legion/extensions/agentic/learning/catalyst/helpers/catalyst_engine.rb', line 12
def initialize
@catalysts = {}
@reactions = {}
end
|
Instance Method Details
#all_catalysts ⇒ Object
95
96
97
|
# File 'lib/legion/extensions/agentic/learning/catalyst/helpers/catalyst_engine.rb', line 95
def all_catalysts
@catalysts.values
end
|
#all_reactions ⇒ Object
99
100
101
|
# File 'lib/legion/extensions/agentic/learning/catalyst/helpers/catalyst_engine.rb', line 99
def all_reactions
@reactions.values
end
|
#apply_catalyst(catalyst_id:, reaction_id:) ⇒ Object
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
# File 'lib/legion/extensions/agentic/learning/catalyst/helpers/catalyst_engine.rb', line 50
def apply_catalyst(catalyst_id:, reaction_id:)
catalyst = @catalysts[catalyst_id]
reaction = @reactions[reaction_id]
return { success: false, reason: :catalyst_not_found } unless catalyst
return { success: false, reason: :reaction_not_found } unless reaction
return { success: false, reason: :already_completed } if reaction.complete?
reaction.apply_catalyst!(catalyst)
{
success: true,
activation_energy: reaction.activation_energy,
catalyst_id: catalyst_id,
reaction_id: reaction_id
}
end
|
#attempt_reaction(reaction_id:, energy_input:) ⇒ Object
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
|
# File 'lib/legion/extensions/agentic/learning/catalyst/helpers/catalyst_engine.rb', line 67
def attempt_reaction(reaction_id:, energy_input:)
reaction = @reactions[reaction_id]
return { success: false, reason: :not_found } unless reaction
return { success: false, reason: :already_completed } if reaction.complete?
completed = reaction.attempt!(energy_input)
{
success: true,
completed: completed,
yield_value: reaction.yield_value,
yield_label: reaction.yield_label,
catalyzed: reaction.catalyzed?,
activation_energy: reaction.activation_energy
}
end
|
#catalyst_report ⇒ Object
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
|
# File 'lib/legion/extensions/agentic/learning/catalyst/helpers/catalyst_engine.rb', line 115
def catalyst_report
completed = completed_reactions
catalyzed_cnt = completed.count(&:catalyzed?)
avg_potency = if @catalysts.empty?
0.0
else
(@catalysts.values.sum(&:potency) / @catalysts.size).round(10)
end
{
total_catalysts: @catalysts.size,
total_reactions: @reactions.size,
completed: completed.size,
catalyzed_count: catalyzed_cnt,
catalyzed_rate: catalyzed_rate,
avg_potency: avg_potency,
powerful_count: @catalysts.values.count(&:powerful?),
inert_count: @catalysts.values.count(&:inert?)
}
end
|
#catalyzed_rate ⇒ Object
107
108
109
110
111
112
113
|
# File 'lib/legion/extensions/agentic/learning/catalyst/helpers/catalyst_engine.rb', line 107
def catalyzed_rate
completed = completed_reactions
return 0.0 if completed.empty?
catalyzed_count = completed.count(&:catalyzed?)
(catalyzed_count.to_f / completed.size).round(10)
end
|
#completed_reactions ⇒ Object
103
104
105
|
# File 'lib/legion/extensions/agentic/learning/catalyst/helpers/catalyst_engine.rb', line 103
def completed_reactions
@reactions.values.select(&:complete?)
end
|
#create_catalyst(catalyst_type:, domain:, potency: 0.5, specificity: 0.5) ⇒ Object
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
# File 'lib/legion/extensions/agentic/learning/catalyst/helpers/catalyst_engine.rb', line 17
def create_catalyst(catalyst_type:, domain:, potency: 0.5, specificity: 0.5, **)
unless CATALYST_TYPES.include?(catalyst_type.to_sym)
raise ArgumentError,
"invalid catalyst_type: #{catalyst_type}"
end
evict_oldest_catalyst if @catalysts.size >= MAX_CATALYSTS
catalyst = Catalyst.new(
catalyst_type: catalyst_type.to_sym,
domain: domain,
potency: potency,
specificity: specificity
)
@catalysts[catalyst.id] = catalyst
catalyst
end
|
#create_reaction(reaction_type:, reactants:, activation_energy: ACTIVATION_ENERGY) ⇒ Object
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
# File 'lib/legion/extensions/agentic/learning/catalyst/helpers/catalyst_engine.rb', line 34
def create_reaction(reaction_type:, reactants:, activation_energy: ACTIVATION_ENERGY, **)
unless REACTION_TYPES.include?(reaction_type.to_sym)
raise ArgumentError,
"invalid reaction_type: #{reaction_type}"
end
evict_oldest_reaction if @reactions.size >= MAX_REACTIONS
reaction = Reaction.new(
reaction_type: reaction_type.to_sym,
reactants: reactants,
activation_energy: activation_energy
)
@reactions[reaction.id] = reaction
reaction
end
|
#degrade_all! ⇒ Object
83
84
85
|
# File 'lib/legion/extensions/agentic/learning/catalyst/helpers/catalyst_engine.rb', line 83
def degrade_all!
@catalysts.each_value(&:degrade!)
end
|
#recharge_catalyst(catalyst_id:, amount:) ⇒ Object
87
88
89
90
91
92
93
|
# File 'lib/legion/extensions/agentic/learning/catalyst/helpers/catalyst_engine.rb', line 87
def recharge_catalyst(catalyst_id:, amount:)
catalyst = @catalysts[catalyst_id]
return { success: false, reason: :not_found } unless catalyst
catalyst.recharge!(amount)
{ success: true, potency: catalyst.potency, potency_label: catalyst.potency_label }
end
|