Class: Legion::Extensions::Agentic::Learning::Procedural::Helpers::LearningEngine
- Inherits:
-
Object
- Object
- Legion::Extensions::Agentic::Learning::Procedural::Helpers::LearningEngine
show all
- Includes:
- Constants
- Defined in:
- lib/legion/extensions/agentic/learning/procedural/helpers/learning_engine.rb
Constant Summary
Constants included
from Constants
Constants::AUTOMATION_THRESHOLD, Constants::COMPILATION_THRESHOLD, Constants::DECAY_RATE, Constants::DEFAULT_PROFICIENCY, Constants::MAX_HISTORY, Constants::MAX_PRODUCTIONS, Constants::MAX_SKILLS, Constants::PRACTICE_GAIN, Constants::PROFICIENCY_CEILING, Constants::PROFICIENCY_FLOOR, Constants::PROFICIENCY_LABELS, Constants::SKILL_STAGES, Constants::STAGE_LABELS, Constants::STALE_THRESHOLD
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
Returns a new instance of LearningEngine.
14
15
16
17
18
|
# File 'lib/legion/extensions/agentic/learning/procedural/helpers/learning_engine.rb', line 14
def initialize
@skills = {}
@productions = {}
@history = []
end
|
Instance Attribute Details
#history ⇒ Object
Returns the value of attribute history.
12
13
14
|
# File 'lib/legion/extensions/agentic/learning/procedural/helpers/learning_engine.rb', line 12
def history
@history
end
|
Instance Method Details
#add_production(skill_id:, condition:, action:, domain:) ⇒ Object
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
# File 'lib/legion/extensions/agentic/learning/procedural/helpers/learning_engine.rb', line 29
def add_production(skill_id:, condition:, action:, domain:)
skill = @skills[skill_id]
return { success: false, reason: :skill_not_found } unless skill
return { success: false, reason: :max_productions } if @productions.size >= MAX_PRODUCTIONS
production = Production.new(
condition: condition, action: action,
domain: domain, skill_id: skill_id
)
@productions[production.id] = production
skill.add_production(production.id)
record_history(:production_added, production.id)
production
end
|
#autonomous_skills ⇒ Object
74
75
76
|
# File 'lib/legion/extensions/agentic/learning/procedural/helpers/learning_engine.rb', line 74
def autonomous_skills
@skills.values.select(&:autonomous?)
end
|
#by_domain(domain:) ⇒ Object
78
79
80
|
# File 'lib/legion/extensions/agentic/learning/procedural/helpers/learning_engine.rb', line 78
def by_domain(domain:)
@skills.values.select { |s| s.domain == domain }
end
|
#compiled_skills ⇒ Object
70
71
72
|
# File 'lib/legion/extensions/agentic/learning/procedural/helpers/learning_engine.rb', line 70
def compiled_skills
@skills.values.select(&:compiled?)
end
|
#create_skill(name:, domain:) ⇒ Object
20
21
22
23
24
25
26
27
|
# File 'lib/legion/extensions/agentic/learning/procedural/helpers/learning_engine.rb', line 20
def create_skill(name:, domain:)
evict_oldest_skill if @skills.size >= MAX_SKILLS
skill = Skill.new(name: name, domain: domain)
@skills[skill.id] = skill
record_history(:skill_created, skill.id)
skill
end
|
#decay_all ⇒ Object
86
87
88
|
# File 'lib/legion/extensions/agentic/learning/procedural/helpers/learning_engine.rb', line 86
def decay_all
@skills.each_value(&:decay!)
end
|
#execute_production(production_id:, success:) ⇒ Object
53
54
55
56
57
58
59
60
|
# File 'lib/legion/extensions/agentic/learning/procedural/helpers/learning_engine.rb', line 53
def execute_production(production_id:, success:)
production = @productions[production_id]
return { success: false, reason: :not_found } unless production
production.execute!(success: success)
record_history(:production_executed, production_id)
{ success: true, production_id: production_id, success_rate: production.success_rate }
end
|
#most_practiced(limit: 5) ⇒ Object
82
83
84
|
# File 'lib/legion/extensions/agentic/learning/procedural/helpers/learning_engine.rb', line 82
def most_practiced(limit: 5)
@skills.values.sort_by { |s| -s.practice_count }.first(limit)
end
|
#practice_skill(skill_id:, success:) ⇒ Object
44
45
46
47
48
49
50
51
|
# File 'lib/legion/extensions/agentic/learning/procedural/helpers/learning_engine.rb', line 44
def practice_skill(skill_id:, success:)
skill = @skills[skill_id]
return { success: false, reason: :not_found } unless skill
skill.practice!(success: success)
record_history(:practiced, skill_id)
build_practice_result(skill)
end
|
#prune_stale ⇒ Object
90
91
92
93
94
95
96
97
|
# File 'lib/legion/extensions/agentic/learning/procedural/helpers/learning_engine.rb', line 90
def prune_stale
stale_ids = @skills.select { |_id, s| s.proficiency <= 0.02 }.keys
stale_ids.each do |sid|
remove_skill_productions(sid)
@skills.delete(sid)
end
stale_ids.size
end
|
#skill_assessment(skill_id:) ⇒ Object
62
63
64
65
66
67
68
|
# File 'lib/legion/extensions/agentic/learning/procedural/helpers/learning_engine.rb', line 62
def skill_assessment(skill_id:)
skill = @skills[skill_id]
return { success: false, reason: :not_found } unless skill
productions = skill.productions.filter_map { |pid| @productions[pid] }
build_assessment(skill, productions)
end
|
#to_h ⇒ Object
99
100
101
102
103
104
105
106
107
108
|
# File 'lib/legion/extensions/agentic/learning/procedural/helpers/learning_engine.rb', line 99
def to_h
{
total_skills: @skills.size,
total_productions: @productions.size,
compiled_count: compiled_skills.size,
autonomous_count: autonomous_skills.size,
history_count: @history.size,
stage_counts: stage_counts
}
end
|