Class: Legion::Extensions::Agentic::Self::Reflection::Helpers::ReflectionStore
- Inherits:
-
Object
- Object
- Legion::Extensions::Agentic::Self::Reflection::Helpers::ReflectionStore
- Defined in:
- lib/legion/extensions/agentic/self/reflection/helpers/reflection_store.rb
Instance Attribute Summary collapse
-
#total_generated ⇒ Object
readonly
Returns the value of attribute total_generated.
Instance Method Summary collapse
- #by_category(category) ⇒ Object
- #by_severity(severity) ⇒ Object
- #category_counts ⇒ Object
- #category_score(category) ⇒ Object
- #cognitive_health ⇒ Object
- #count ⇒ Object
- #get(reflection_id) ⇒ Object
-
#initialize ⇒ ReflectionStore
constructor
A new instance of ReflectionStore.
- #mark_acted_on(reflection_id) ⇒ Object
- #recent(limit: 10) ⇒ Object
- #severity_counts ⇒ Object
- #store(reflection) ⇒ Object
- #unacted ⇒ Object
- #update_category_score(category, score) ⇒ Object
Constructor Details
#initialize ⇒ ReflectionStore
Returns a new instance of ReflectionStore.
12 13 14 15 16 |
# File 'lib/legion/extensions/agentic/self/reflection/helpers/reflection_store.rb', line 12 def initialize @reflections = {} @total_generated = 0 @category_scores = Hash.new(1.0) end |
Instance Attribute Details
#total_generated ⇒ Object (readonly)
Returns the value of attribute total_generated.
10 11 12 |
# File 'lib/legion/extensions/agentic/self/reflection/helpers/reflection_store.rb', line 10 def total_generated @total_generated end |
Instance Method Details
#by_category(category) ⇒ Object
36 37 38 |
# File 'lib/legion/extensions/agentic/self/reflection/helpers/reflection_store.rb', line 36 def by_category(category) @reflections.values.select { |r| r[:category] == category } end |
#by_severity(severity) ⇒ Object
40 41 42 |
# File 'lib/legion/extensions/agentic/self/reflection/helpers/reflection_store.rb', line 40 def by_severity(severity) @reflections.values.select { |r| r[:severity] == severity } end |
#category_counts ⇒ Object
65 66 67 68 69 |
# File 'lib/legion/extensions/agentic/self/reflection/helpers/reflection_store.rb', line 65 def category_counts counts = Hash.new(0) @reflections.each_value { |r| counts[r[:category]] += 1 } counts end |
#category_score(category) ⇒ Object
83 84 85 |
# File 'lib/legion/extensions/agentic/self/reflection/helpers/reflection_store.rb', line 83 def category_score(category) @category_scores[category] end |
#cognitive_health ⇒ Object
75 76 77 78 79 80 81 |
# File 'lib/legion/extensions/agentic/self/reflection/helpers/reflection_store.rb', line 75 def cognitive_health total_weight = Constants::HEALTH_WEIGHTS.values.sum weighted_sum = Constants::HEALTH_WEIGHTS.sum do |cat, weight| @category_scores[cat] * weight end (weighted_sum / total_weight).round(3) end |
#count ⇒ Object
55 56 57 |
# File 'lib/legion/extensions/agentic/self/reflection/helpers/reflection_store.rb', line 55 def count @reflections.size end |
#get(reflection_id) ⇒ Object
25 26 27 |
# File 'lib/legion/extensions/agentic/self/reflection/helpers/reflection_store.rb', line 25 def get(reflection_id) @reflections[reflection_id] end |
#mark_acted_on(reflection_id) ⇒ Object
44 45 46 47 48 49 |
# File 'lib/legion/extensions/agentic/self/reflection/helpers/reflection_store.rb', line 44 def mark_acted_on(reflection_id) reflection = @reflections[reflection_id] return nil unless reflection @reflections[reflection_id] = reflection.merge(acted_on: true) end |
#recent(limit: 10) ⇒ Object
29 30 31 32 33 34 |
# File 'lib/legion/extensions/agentic/self/reflection/helpers/reflection_store.rb', line 29 def recent(limit: 10) @reflections.values .sort_by { |r| r[:created_at] } .last(limit) .reverse end |
#severity_counts ⇒ Object
59 60 61 62 63 |
# File 'lib/legion/extensions/agentic/self/reflection/helpers/reflection_store.rb', line 59 def severity_counts counts = Hash.new(0) @reflections.each_value { |r| counts[r[:severity]] += 1 } counts end |
#store(reflection) ⇒ Object
18 19 20 21 22 23 |
# File 'lib/legion/extensions/agentic/self/reflection/helpers/reflection_store.rb', line 18 def store(reflection) prune_oldest if @reflections.size >= Constants::MAX_REFLECTIONS @reflections[reflection[:reflection_id]] = reflection @total_generated += 1 reflection end |
#unacted ⇒ Object
51 52 53 |
# File 'lib/legion/extensions/agentic/self/reflection/helpers/reflection_store.rb', line 51 def unacted @reflections.values.reject { |r| r[:acted_on] } end |
#update_category_score(category, score) ⇒ Object
71 72 73 |
# File 'lib/legion/extensions/agentic/self/reflection/helpers/reflection_store.rb', line 71 def update_category_score(category, score) @category_scores[category] = score.clamp(0.0, 1.0) end |