Module: Legion::Extensions::Agentic::Executive::Volition::Helpers::DriveSynthesizer
- Defined in:
- lib/legion/extensions/agentic/executive/volition/helpers/drive_synthesizer.rb
Class Method Summary collapse
- .build_corrective_intention(strength, cognitive_state) ⇒ Object
- .build_curiosity_intention(strength, cognitive_state) ⇒ Object
- .build_epistemic_intention(strength, _cognitive_state) ⇒ Object
- .build_intention_for_drive(drive, strength, cognitive_state) ⇒ Object
- .build_social_intention(strength, _cognitive_state) ⇒ Object
- .build_urgency_intention(strength, _cognitive_state) ⇒ Object
- .compute_corrective_drive(cognitive_state) ⇒ Object
- .compute_curiosity_drive(tick_results, cognitive_state) ⇒ Object
- .compute_epistemic_drive(tick_results, cognitive_state) ⇒ Object
- .compute_social_drive(cognitive_state) ⇒ Object
- .compute_urgency_drive(tick_results, cognitive_state) ⇒ Object
- .dominant_drive(drives) ⇒ Object
- .extract_gut_strength(gut) ⇒ Object
- .generate_intentions(drives, cognitive_state: {}) ⇒ Object
- .synthesize(tick_results: {}, cognitive_state: {}) ⇒ Object
- .weighted_drives(drives) ⇒ Object
Class Method Details
.build_corrective_intention(strength, cognitive_state) ⇒ Object
141 142 143 144 |
# File 'lib/legion/extensions/agentic/executive/volition/helpers/drive_synthesizer.rb', line 141 def build_corrective_intention(strength, cognitive_state) severity = cognitive_state.dig(:reflection, :recent_severity) || 'cognitive health' Intention.new_intention(drive: :corrective, domain: :self, goal: "address #{severity}", salience: strength) end |
.build_curiosity_intention(strength, cognitive_state) ⇒ Object
135 136 137 138 139 |
# File 'lib/legion/extensions/agentic/executive/volition/helpers/drive_synthesizer.rb', line 135 def build_curiosity_intention(strength, cognitive_state) question = cognitive_state.dig(:curiosity, :top_question) || 'explore knowledge gaps' domain = cognitive_state.dig(:curiosity, :top_domain) || :general Intention.new_intention(drive: :curiosity, domain: domain, goal: question, salience: strength) end |
.build_epistemic_intention(strength, _cognitive_state) ⇒ Object
150 151 152 |
# File 'lib/legion/extensions/agentic/executive/volition/helpers/drive_synthesizer.rb', line 150 def build_epistemic_intention(strength, _cognitive_state) Intention.new_intention(drive: :epistemic, domain: :general, goal: 'reduce prediction uncertainty', salience: strength) end |
.build_intention_for_drive(drive, strength, cognitive_state) ⇒ Object
125 126 127 128 129 130 131 132 133 |
# File 'lib/legion/extensions/agentic/executive/volition/helpers/drive_synthesizer.rb', line 125 def build_intention_for_drive(drive, strength, cognitive_state) case drive when :curiosity then build_curiosity_intention(strength, cognitive_state) when :corrective then build_corrective_intention(strength, cognitive_state) when :urgency then build_urgency_intention(strength, cognitive_state) when :epistemic then build_epistemic_intention(strength, cognitive_state) when :social then (strength, cognitive_state) end end |
.build_social_intention(strength, _cognitive_state) ⇒ Object
154 155 156 |
# File 'lib/legion/extensions/agentic/executive/volition/helpers/drive_synthesizer.rb', line 154 def (strength, _cognitive_state) Intention.new_intention(drive: :social, domain: :general, goal: 'engage with peer agents', salience: strength) end |
.build_urgency_intention(strength, _cognitive_state) ⇒ Object
146 147 148 |
# File 'lib/legion/extensions/agentic/executive/volition/helpers/drive_synthesizer.rb', line 146 def build_urgency_intention(strength, _cognitive_state) Intention.new_intention(drive: :urgency, domain: :general, goal: 'respond to urgent signal', salience: strength) end |
.compute_corrective_drive(cognitive_state) ⇒ Object
64 65 66 67 68 69 70 71 72 |
# File 'lib/legion/extensions/agentic/executive/volition/helpers/drive_synthesizer.rb', line 64 def compute_corrective_drive(cognitive_state) reflection = cognitive_state[:reflection] || {} health = reflection[:health] || 1.0 pending = reflection[:pending_adaptations] || 0 health_gap = 1.0 - health pending_factor = [pending / 3.0, 1.0].min ((health_gap * 0.6) + (pending_factor * 0.4)).clamp(0.0, 1.0) end |
.compute_curiosity_drive(tick_results, cognitive_state) ⇒ Object
53 54 55 56 57 58 59 60 61 62 |
# File 'lib/legion/extensions/agentic/executive/volition/helpers/drive_synthesizer.rb', line 53 def compute_curiosity_drive(tick_results, cognitive_state) curiosity = cognitive_state[:curiosity] || {} wonder_data = tick_results[:working_memory_integration] || {} intensity = curiosity[:intensity] || wonder_data[:curiosity_intensity] || 0.0 active_count = curiosity[:active_count] || wonder_data[:active_wonders] || 0 count_factor = [active_count / 5.0, 1.0].min ((intensity * 0.7) + (count_factor * 0.3)).clamp(0.0, 1.0) end |
.compute_epistemic_drive(tick_results, cognitive_state) ⇒ Object
84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/legion/extensions/agentic/executive/volition/helpers/drive_synthesizer.rb', line 84 def compute_epistemic_drive(tick_results, cognitive_state) pred = tick_results[:prediction_engine] || {} pred_state = cognitive_state[:prediction] || {} return 0.0 if pred.empty? && pred_state.empty? confidence = pred[:confidence] || pred_state[:confidence] || 1.0 pending = pred_state[:pending_count] || 0 confidence_gap = 1.0 - confidence pending_factor = [pending / 10.0, 1.0].min ((confidence_gap * 0.6) + (pending_factor * 0.4)).clamp(0.0, 1.0) end |
.compute_social_drive(cognitive_state) ⇒ Object
98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/legion/extensions/agentic/executive/volition/helpers/drive_synthesizer.rb', line 98 def (cognitive_state) mesh = cognitive_state[:mesh] || {} trust = cognitive_state[:trust] || {} return 0.0 if mesh.empty? && trust.empty? peer_count = mesh[:peer_count] || 0 trust_level = trust[:avg_composite] || 0.0 peer_factor = [peer_count / 5.0, 1.0].min ((peer_factor * 0.4) + (trust_level * 0.6)).clamp(0.0, 1.0) end |
.compute_urgency_drive(tick_results, cognitive_state) ⇒ Object
74 75 76 77 78 79 80 81 82 |
# File 'lib/legion/extensions/agentic/executive/volition/helpers/drive_synthesizer.rb', line 74 def compute_urgency_drive(tick_results, cognitive_state) gut = tick_results[:gut_instinct] || cognitive_state[:gut] || {} emotion = tick_results[:emotional_evaluation] || {} arousal = gut[:arousal] || emotion[:arousal] || cognitive_state.dig(:emotion, :arousal) || 0.0 gut_signal = extract_gut_strength(gut) ((arousal * 0.5) + (gut_signal * 0.5)).clamp(0.0, 1.0) end |
.dominant_drive(drives) ⇒ Object
33 34 35 36 37 38 |
# File 'lib/legion/extensions/agentic/executive/volition/helpers/drive_synthesizer.rb', line 33 def dominant_drive(drives) return nil if drives.empty? weighted = weighted_drives(drives) weighted.max_by { |_, data| data[:weighted] }&.first end |
.extract_gut_strength(gut) ⇒ Object
111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/legion/extensions/agentic/executive/volition/helpers/drive_synthesizer.rb', line 111 def extract_gut_strength(gut) signal = gut[:signal] return 0.0 unless signal case signal when :alarm then 1.0 when :heightened then 0.7 when :explore then 0.5 when :attend then 0.4 when :calm then 0.05 else 0.0 end end |
.generate_intentions(drives, cognitive_state: {}) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/legion/extensions/agentic/executive/volition/helpers/drive_synthesizer.rb', line 40 def generate_intentions(drives, cognitive_state: {}) intentions = [] drives.each do |drive, strength| next if strength < Constants::DRIVE_THRESHOLD intention = build_intention_for_drive(drive, strength, cognitive_state) intentions << intention if intention end intentions.sort_by { |i| -(i[:salience] || 0) } end |
.synthesize(tick_results: {}, cognitive_state: {}) ⇒ Object
12 13 14 15 16 17 18 19 20 |
# File 'lib/legion/extensions/agentic/executive/volition/helpers/drive_synthesizer.rb', line 12 def synthesize(tick_results: {}, cognitive_state: {}) drives = {} drives[:curiosity] = compute_curiosity_drive(tick_results, cognitive_state) drives[:corrective] = compute_corrective_drive(cognitive_state) drives[:urgency] = compute_urgency_drive(tick_results, cognitive_state) drives[:epistemic] = compute_epistemic_drive(tick_results, cognitive_state) drives[:social] = (cognitive_state) drives end |
.weighted_drives(drives) ⇒ Object
22 23 24 25 26 27 28 29 30 31 |
# File 'lib/legion/extensions/agentic/executive/volition/helpers/drive_synthesizer.rb', line 22 def weighted_drives(drives) drives.each_with_object({}) do |(drive, strength), result| weight = Constants::DRIVE_WEIGHTS[drive] || 0.0 result[drive] = { raw: strength, weighted: (strength * weight).round(4), weight: weight } end end |