Module: Legion::Extensions::Agentic::Affect::Interoception::Runners::Interoception

Includes:
Helpers::Lex
Included in:
Client
Defined in:
lib/legion/extensions/agentic/affect/interoception/runners/interoception.rb

Instance Method Summary collapse

Instance Method Details

#body_statusObject



61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/legion/extensions/agentic/affect/interoception/runners/interoception.rb', line 61

def body_status(**)
  health = body_budget.overall_health
  label = body_budget.body_budget_label
  log.debug("[interoception] status: health=#{health.round(3)} label=#{label}")
  {
    success:  true,
    health:   health.round(4),
    label:    label,
    channels: body_budget.channel_count,
    markers:  body_budget.marker_count
  }
end

#create_somatic_marker(action:, domain:, valence:, strength: 1.0) ⇒ Object



29
30
31
32
33
34
# File 'lib/legion/extensions/agentic/affect/interoception/runners/interoception.rb', line 29

def create_somatic_marker(action:, domain:, valence:, strength: 1.0, **)
  marker = body_budget.create_marker(action: action, domain: domain, valence: valence.to_f, strength: strength.to_f)
  log.debug("[interoception] marker: action=#{action} domain=#{domain} " \
            "valence=#{marker.valence.round(2)} label=#{marker.label}")
  { success: true, marker: marker.to_h }
end

#deviating_vitalsObject



55
56
57
58
59
# File 'lib/legion/extensions/agentic/affect/interoception/runners/interoception.rb', line 55

def deviating_vitals(**)
  deviations = body_budget.deviating_channels
  log.debug("[interoception] deviating: count=#{deviations.size}")
  { success: true, deviations: deviations, count: deviations.size }
end

#interoception_statsObject



88
89
90
# File 'lib/legion/extensions/agentic/affect/interoception/runners/interoception.rb', line 88

def interoception_stats(**)
  { success: true, stats: body_budget.to_h }
end

#query_bias(action:, domain: nil) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/legion/extensions/agentic/affect/interoception/runners/interoception.rb', line 36

def query_bias(action:, domain: nil, **)
  bias = body_budget.bias_for_action(action: action, domain: domain)
  label = if bias > Helpers::Constants::MARKER_POSITIVE_THRESHOLD * Helpers::Constants::MARKER_INFLUENCE
            :approach
          elsif bias < Helpers::Constants::MARKER_NEGATIVE_THRESHOLD * Helpers::Constants::MARKER_INFLUENCE
            :avoid
          else
            :neutral
          end
  log.debug("[interoception] bias: action=#{action} domain=#{domain} bias=#{bias.round(3)} label=#{label}")
  { success: true, action: action, domain: domain, bias: bias.round(4), label: label }
end

#reinforce_somatic(action:, domain: nil, amount: 0.1) ⇒ Object



49
50
51
52
53
# File 'lib/legion/extensions/agentic/affect/interoception/runners/interoception.rb', line 49

def reinforce_somatic(action:, domain: nil, amount: 0.1, **)
  body_budget.reinforce_markers(action: action, domain: domain, amount: amount.to_f)
  log.debug("[interoception] reinforce: action=#{action} domain=#{domain} amount=#{amount}")
  { success: true, action: action, domain: domain }
end

#report_vital(channel:, value:) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/legion/extensions/agentic/affect/interoception/runners/interoception.rb', line 13

def report_vital(channel:, value:, **)
  smoothed = body_budget.report_vital(channel: channel, value: value.to_f)
  return { success: false, error: :invalid_channel, valid_channels: Helpers::Constants::VITAL_CHANNELS } unless smoothed

  deviation = body_budget.deviation_for(channel)
  log.debug("[interoception] vital: channel=#{channel} raw=#{value} " \
            "smoothed=#{smoothed.round(3)} deviation=#{deviation.round(3)}")
  {
    success:   true,
    channel:   channel,
    smoothed:  smoothed.round(4),
    deviation: deviation.round(4),
    label:     body_budget.vital_label(channel)
  }
end

#update_interoceptionObject



74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/legion/extensions/agentic/affect/interoception/runners/interoception.rb', line 74

def update_interoception(**)
  body_budget.decay_markers
  health = body_budget.overall_health
  log.debug("[interoception] tick: health=#{health.round(3)} " \
            "channels=#{body_budget.channel_count} markers=#{body_budget.marker_count}")
  {
    success:  true,
    health:   health.round(4),
    label:    body_budget.body_budget_label,
    channels: body_budget.channel_count,
    markers:  body_budget.marker_count
  }
end