Module: Legion::Extensions::Agentic::Affect::SomaticMarker::Runners::SomaticMarker
- Includes:
- Helpers::Lex
- Included in:
- Client
- Defined in:
- lib/legion/extensions/agentic/affect/somatic_marker/runners/somatic_marker.rb
Instance Method Summary collapse
- #body_state ⇒ Object
- #evaluate_option(action:, domain:) ⇒ Object
- #make_decision(options:, domain:) ⇒ Object
- #markers_for_action(action:, domain:) ⇒ Object
- #recent_decisions(limit: 10) ⇒ Object
- #register_marker(action:, domain:, valence:, source: :experience) ⇒ Object
- #reinforce(marker_id:, outcome_valence:) ⇒ Object
- #somatic_marker_stats ⇒ Object
- #update_body(arousal: nil, tension: nil, comfort: nil, gut_signal: nil) ⇒ Object
- #update_somatic_markers ⇒ Object
Instance Method Details
#body_state ⇒ Object
73 74 75 76 77 78 79 80 |
# File 'lib/legion/extensions/agentic/affect/somatic_marker/runners/somatic_marker.rb', line 73 def body_state(**) state = store.body_state log.debug("[somatic_marker] body_state: composite=#{state.composite_valence.round(3)}") { success: true, body_state: state.to_h } rescue StandardError => e log.error("[somatic_marker] body_state failed: #{e.}") { success: false, error: e. } end |
#evaluate_option(action:, domain:) ⇒ Object
23 24 25 26 27 28 29 30 31 |
# File 'lib/legion/extensions/agentic/affect/somatic_marker/runners/somatic_marker.rb', line 23 def evaluate_option(action:, domain:, **) result = store.evaluate_option(action: action, domain: domain) log.debug("[somatic_marker] evaluate: action=#{action} domain=#{domain} " \ "signal=#{result[:signal]} valence=#{result[:valence].round(3)}") { success: true }.merge(result) rescue StandardError => e log.error("[somatic_marker] evaluate failed: #{e.}") { success: false, error: e. } end |
#make_decision(options:, domain:) ⇒ Object
33 34 35 36 37 38 39 40 41 |
# File 'lib/legion/extensions/agentic/affect/somatic_marker/runners/somatic_marker.rb', line 33 def make_decision(options:, domain:, **) result = store.decide(options: , domain: domain) log.debug("[somatic_marker] decide: domain=#{domain} options=#{.size} " \ "top=#{result[:ranked].first&.fetch(:action)}") { success: true, decision: result } rescue StandardError => e log.error("[somatic_marker] decide failed: #{e.}") { success: false, error: e. } end |
#markers_for_action(action:, domain:) ⇒ Object
82 83 84 85 86 87 88 89 90 |
# File 'lib/legion/extensions/agentic/affect/somatic_marker/runners/somatic_marker.rb', line 82 def markers_for_action(action:, domain:, **) markers = store.markers_for(action: action, domain: domain) log.debug("[somatic_marker] markers_for: action=#{action} domain=#{domain} " \ "count=#{markers.size}") { success: true, markers: markers.map(&:to_h), count: markers.size } rescue StandardError => e log.error("[somatic_marker] markers_for_action failed: #{e.}") { success: false, error: e. } end |
#recent_decisions(limit: 10) ⇒ Object
92 93 94 95 96 97 98 99 |
# File 'lib/legion/extensions/agentic/affect/somatic_marker/runners/somatic_marker.rb', line 92 def recent_decisions(limit: 10, **) decisions = store.decision_history(limit: limit) log.debug("[somatic_marker] recent_decisions: limit=#{limit} count=#{decisions.size}") { success: true, decisions: decisions, count: decisions.size } rescue StandardError => e log.error("[somatic_marker] recent_decisions failed: #{e.}") { success: false, error: e. } end |
#register_marker(action:, domain:, valence:, source: :experience) ⇒ Object
13 14 15 16 17 18 19 20 21 |
# File 'lib/legion/extensions/agentic/affect/somatic_marker/runners/somatic_marker.rb', line 13 def register_marker(action:, domain:, valence:, source: :experience, **) marker = store.register_marker(action: action, domain: domain, valence: valence, source: source) log.debug("[somatic_marker] register: action=#{action} domain=#{domain} " \ "valence=#{valence.round(3)} source=#{source} id=#{marker.id}") { success: true, marker: marker.to_h } rescue StandardError => e log.error("[somatic_marker] register failed: #{e.}") { success: false, error: e. } end |
#reinforce(marker_id:, outcome_valence:) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/legion/extensions/agentic/affect/somatic_marker/runners/somatic_marker.rb', line 43 def reinforce(marker_id:, outcome_valence:, **) marker = store.reinforce_marker(marker_id: marker_id, outcome_valence: outcome_valence) unless marker log.debug("[somatic_marker] reinforce: marker_id=#{marker_id} not found") return { success: false, error: 'marker not found' } end log.debug("[somatic_marker] reinforce: id=#{marker_id} " \ "outcome=#{outcome_valence.round(3)} new_valence=#{marker.valence.round(3)}") { success: true, marker: marker.to_h } rescue StandardError => e log.error("[somatic_marker] reinforce failed: #{e.}") { success: false, error: e. } end |
#somatic_marker_stats ⇒ Object
111 112 113 114 115 116 117 118 119 |
# File 'lib/legion/extensions/agentic/affect/somatic_marker/runners/somatic_marker.rb', line 111 def somatic_marker_stats(**) stats = store.to_h log.debug("[somatic_marker] stats: markers=#{stats[:marker_count]} " \ "decisions=#{stats[:decision_count]}") { success: true }.merge(stats) rescue StandardError => e log.error("[somatic_marker] stats failed: #{e.}") { success: false, error: e. } end |
#update_body(arousal: nil, tension: nil, comfort: nil, gut_signal: nil) ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/legion/extensions/agentic/affect/somatic_marker/runners/somatic_marker.rb', line 58 def update_body(arousal: nil, tension: nil, comfort: nil, gut_signal: nil, **) state = store.update_body_state( arousal: arousal, tension: tension, comfort: comfort, gut_signal: gut_signal ) log.debug("[somatic_marker] body_update: composite=#{state.composite_valence.round(3)} " \ "stressed=#{state.stressed?}") { success: true, body_state: state.to_h } rescue StandardError => e log.error("[somatic_marker] body update failed: #{e.}") { success: false, error: e. } end |
#update_somatic_markers ⇒ Object
101 102 103 104 105 106 107 108 109 |
# File 'lib/legion/extensions/agentic/affect/somatic_marker/runners/somatic_marker.rb', line 101 def update_somatic_markers(**) result = store.decay_all log.debug("[somatic_marker] decay: remaining=#{result[:markers_decayed]} " \ "removed=#{result[:markers_removed]}") { success: true }.merge(result) rescue StandardError => e log.error("[somatic_marker] decay failed: #{e.}") { success: false, error: e. } end |