Module: Legion::Extensions::Agentic::Self::Metacognition::Helpers::SelfModel
- Defined in:
- lib/legion/extensions/agentic/self/metacognition/helpers/self_model.rb
Class Method Summary collapse
- .build(subsystem_states: {}, tick_results: {}) ⇒ Object
- .build_architecture(loaded_map) ⇒ Object
- .build_cognitive_snapshot(tick_results) ⇒ Object
- .build_identity ⇒ Object
- .build_subsystem_states(states) ⇒ Object
- .discover_loaded_extensions ⇒ Object
- .extension_loaded?(ext_sym) ⇒ Boolean
- .extract_attention(tick_results) ⇒ Object
- .extract_curiosity(tick_results) ⇒ Object
- .extract_drives(tick_results) ⇒ Object
- .extract_health(tick_results) ⇒ Object
- .extract_mode(tick_results) ⇒ Object
- .extract_prediction(tick_results) ⇒ Object
- .health_label(score) ⇒ Object
- .log ⇒ Object
- .map_capabilities(loaded_map) ⇒ Object
- .normalize_subsystem_state(state) ⇒ Object
Class Method Details
.build(subsystem_states: {}, tick_results: {}) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/legion/extensions/agentic/self/metacognition/helpers/self_model.rb', line 16 def build(subsystem_states: {}, tick_results: {}) loaded = discover_loaded_extensions capabilities = map_capabilities(loaded) { identity: build_identity, architecture: build_architecture(loaded), capabilities: capabilities, subsystems: build_subsystem_states(subsystem_states), cognitive: build_cognitive_snapshot(tick_results), assembled_at: Time.now.utc } end |
.build_architecture(loaded_map) ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/legion/extensions/agentic/self/metacognition/helpers/self_model.rb', line 71 def build_architecture(loaded_map) total = loaded_map.size active = loaded_map.count { |_, v| v[:loaded] } { total_extensions: total, loaded_count: active, unloaded_count: total - active, loaded: loaded_map.select { |_, v| v[:loaded] }.keys, unloaded: loaded_map.reject { |_, v| v[:loaded] }.keys } end |
.build_cognitive_snapshot(tick_results) ⇒ Object
98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/legion/extensions/agentic/self/metacognition/helpers/self_model.rb', line 98 def build_cognitive_snapshot(tick_results) return { status: :no_tick_data } unless tick_results.is_a?(Hash) && !tick_results.empty? { mode: extract_mode(tick_results), phases_run: tick_results.keys.size, has_reflection: tick_results.key?(:post_tick_reflection), health: extract_health(tick_results), active_drives: extract_drives(tick_results), attention: extract_attention(tick_results), curiosity: extract_curiosity(tick_results), prediction: extract_prediction(tick_results) } end |
.build_identity ⇒ Object
62 63 64 65 66 67 68 69 |
# File 'lib/legion/extensions/agentic/self/metacognition/helpers/self_model.rb', line 62 def build_identity { framework: 'LegionIO', role: :cognitive_agent, model: :brain_modeled, extensions: Constants::EXTENSION_CAPABILITIES.size } end |
.build_subsystem_states(states) ⇒ Object
84 85 86 87 88 89 90 |
# File 'lib/legion/extensions/agentic/self/metacognition/helpers/self_model.rb', line 84 def build_subsystem_states(states) return {} unless states.is_a?(Hash) states.each_with_object({}) do |(key, state), acc| acc[key] = normalize_subsystem_state(state) end end |
.discover_loaded_extensions ⇒ Object
43 44 45 46 47 48 49 50 |
# File 'lib/legion/extensions/agentic/self/metacognition/helpers/self_model.rb', line 43 def discover_loaded_extensions Constants::EXTENSION_CAPABILITIES.each_with_object({}) do |(ext_sym, _cat), acc| acc[ext_sym] = { loaded: extension_loaded?(ext_sym) } end rescue StandardError => e log.error "[metacognition] discover_loaded_extensions failed: #{e.}" {} end |
.extension_loaded?(ext_sym) ⇒ Boolean
30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/legion/extensions/agentic/self/metacognition/helpers/self_model.rb', line 30 def extension_loaded?(ext_sym) return true if Legion::Extensions.const_defined?(ext_sym, false) agentic = Legion::Extensions.const_get(:Agentic, false) agentic.constants(false).any? do |domain| ns = agentic.const_get(domain, false) ns.is_a?(Module) && ns.const_defined?(ext_sym, false) end rescue StandardError => e log.error "[metacognition] extension_loaded? check failed: #{e.}" false end |
.extract_attention(tick_results) ⇒ Object
131 132 133 134 135 136 |
# File 'lib/legion/extensions/agentic/self/metacognition/helpers/self_model.rb', line 131 def extract_attention(tick_results) attention = tick_results[:sensory_processing] return nil unless attention.is_a?(Hash) { spotlight: attention[:spotlight_count], total: attention[:total_signals] } end |
.extract_curiosity(tick_results) ⇒ Object
138 139 140 141 142 143 |
# File 'lib/legion/extensions/agentic/self/metacognition/helpers/self_model.rb', line 138 def extract_curiosity(tick_results) curiosity = tick_results[:working_memory_integration] return nil unless curiosity.is_a?(Hash) { intensity: curiosity[:curiosity_intensity], open_wonders: curiosity[:open_wonders] } end |
.extract_drives(tick_results) ⇒ Object
124 125 126 127 128 129 |
# File 'lib/legion/extensions/agentic/self/metacognition/helpers/self_model.rb', line 124 def extract_drives(tick_results) volition = tick_results[:action_selection] return [] unless volition.is_a?(Hash) && volition[:intentions].is_a?(Array) volition[:intentions].first(3).filter_map { |i| i[:drive] } end |
.extract_health(tick_results) ⇒ Object
117 118 119 120 121 122 |
# File 'lib/legion/extensions/agentic/self/metacognition/helpers/self_model.rb', line 117 def extract_health(tick_results) reflection = tick_results[:post_tick_reflection] return nil unless reflection.is_a?(Hash) reflection[:cognitive_health] end |
.extract_mode(tick_results) ⇒ Object
113 114 115 |
# File 'lib/legion/extensions/agentic/self/metacognition/helpers/self_model.rb', line 113 def extract_mode(tick_results) tick_results.dig(:tick_meta, :mode) || :unknown end |
.extract_prediction(tick_results) ⇒ Object
145 146 147 148 149 150 |
# File 'lib/legion/extensions/agentic/self/metacognition/helpers/self_model.rb', line 145 def extract_prediction(tick_results) prediction = tick_results[:prediction_engine] return nil unless prediction.is_a?(Hash) { confidence: prediction[:confidence], mode: prediction[:mode] } end |
.health_label(score) ⇒ Object
152 153 154 155 156 157 158 159 |
# File 'lib/legion/extensions/agentic/self/metacognition/helpers/self_model.rb', line 152 def health_label(score) return :unknown unless score.is_a?(Numeric) Constants::HEALTH_LABELS.each do |range, label| return label if range.include?(score) end :unknown end |
.log ⇒ Object
10 11 12 |
# File 'lib/legion/extensions/agentic/self/metacognition/helpers/self_model.rb', line 10 def self.log Legion::Logging end |
.map_capabilities(loaded_map) ⇒ Object
52 53 54 55 56 57 58 59 60 |
# File 'lib/legion/extensions/agentic/self/metacognition/helpers/self_model.rb', line 52 def map_capabilities(loaded_map) active = loaded_map.select { |_, v| v[:loaded] } grouped = active.keys.group_by { |ext| Constants::EXTENSION_CAPABILITIES[ext] || :unknown } Constants::CAPABILITY_CATEGORIES.to_h do |cat| extensions = grouped[cat] || [] [cat, { active: extensions.size.positive?, extensions: extensions }] end end |
.normalize_subsystem_state(state) ⇒ Object
92 93 94 95 96 |
# File 'lib/legion/extensions/agentic/self/metacognition/helpers/self_model.rb', line 92 def normalize_subsystem_state(state) return { status: :unknown } unless state.is_a?(Hash) state.slice(:health, :status, :mode, :count, :active_count, :score) end |