Module: Legion::Extensions::Agentic::Executive::Inhibition::Runners::Inhibition

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

Instance Method Summary collapse

Instance Method Details

#check_stroop(automatic:, controlled:) ⇒ Object



73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/legion/extensions/agentic/executive/inhibition/runners/inhibition.rb', line 73

def check_stroop(automatic:, controlled:, **)
  conflict = inhibition_store.model.stroop_conflict?(automatic, controlled)

  Legion::Logging.debug "[inhibition] stroop check: conflict=#{conflict}"

  {
    automatic:  automatic,
    controlled: controlled,
    conflict:   conflict,
    threshold:  Helpers::Constants::STROOP_CONFLICT_THRESHOLD
  }
end

#delay_gratification(reward:, delay:) ⇒ Object



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/legion/extensions/agentic/executive/inhibition/runners/inhibition.rb', line 57

def delay_gratification(reward:, delay:, **)
  present_value = inhibition_store.model.delay_discount(reward.to_f, delay.to_i)
  worth_waiting = present_value >= (reward.to_f * 0.7)

  Legion::Logging.debug "[inhibition] delay_gratification: reward=#{reward} delay=#{delay} " \
                        "present_value=#{present_value.round(4)} worth_waiting=#{worth_waiting}"

  {
    reward:        reward,
    delay:         delay,
    present_value: present_value.round(4),
    discount_rate: Helpers::Constants::DELAY_DISCOUNT_RATE,
    worth_waiting: worth_waiting
  }
end

#evaluate_impulse(action:, type: :reactive, strength: :moderate, source: nil, context: {}) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/legion/extensions/agentic/executive/inhibition/runners/inhibition.rb', line 25

def evaluate_impulse(action:, type: :reactive, strength: :moderate, source: nil, context: {}, **)
  type = type.to_sym
  unless Helpers::Constants::IMPULSE_TYPES.include?(type)
    Legion::Logging.warn "[inhibition] unknown impulse type: #{type}"
    return { success: false, error: "unknown impulse type: #{type}" }
  end

  impulse = inhibition_store.create_impulse(
    type:     type,
    action:   action,
    strength: strength,
    source:   source,
    context:  context
  )

  result = inhibition_store.evaluate_and_apply(impulse)

  Legion::Logging.info "[inhibition] impulse evaluated: action=#{action} " \
                       "type=#{type} strategy=#{result[:strategy]}"

  {
    success:    true,
    impulse_id: impulse.id,
    action:     action,
    type:       type,
    strength:   impulse.strength,
    strategy:   result[:strategy],
    allowed:    result[:strategy] == :failed,
    log_entry:  result[:log_entry]
  }
end

#inhibition_historyObject



98
99
100
101
102
# File 'lib/legion/extensions/agentic/executive/inhibition/runners/inhibition.rb', line 98

def inhibition_history(**)
  log = inhibition_store.recent_log
  Legion::Logging.debug "[inhibition] history: #{log.size} entries"
  { log: log, total: inhibition_store.model.inhibition_log.size }
end

#inhibition_statsObject



104
105
106
107
# File 'lib/legion/extensions/agentic/executive/inhibition/runners/inhibition.rb', line 104

def inhibition_stats(**)
  Legion::Logging.debug '[inhibition] stats requested'
  inhibition_store.stats
end

#update_inhibition(tick_results: {}) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
# File 'lib/legion/extensions/agentic/executive/inhibition/runners/inhibition.rb', line 13

def update_inhibition(tick_results: {}, **)
  detect_impulse_triggers(tick_results)
  inhibition_store.recover

  summary = inhibition_store.stats
  Legion::Logging.debug "[inhibition] willpower=#{summary[:willpower]} " \
                        "status=#{summary[:willpower_status]} " \
                        "success_rate=#{summary[:success_rate]}"

  summary
end

#willpower_statusObject



86
87
88
89
90
91
92
93
94
95
96
# File 'lib/legion/extensions/agentic/executive/inhibition/runners/inhibition.rb', line 86

def willpower_status(**)
  model = inhibition_store.model
  Legion::Logging.debug "[inhibition] willpower=#{model.willpower.round(4)} status=#{model.willpower_status}"

  {
    willpower:    model.willpower.round(4),
    status:       model.willpower_status,
    threshold:    Helpers::Constants::WILLPOWER_THRESHOLD,
    success_rate: model.success_rate.round(4)
  }
end