Class: Legion::Extensions::Agentic::Executive::Inhibition::Helpers::InhibitionModel

Inherits:
Object
  • Object
show all
Defined in:
lib/legion/extensions/agentic/executive/inhibition/helpers/inhibition_model.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeInhibitionModel

Returns a new instance of InhibitionModel.



12
13
14
15
16
17
18
# File 'lib/legion/extensions/agentic/executive/inhibition/helpers/inhibition_model.rb', line 12

def initialize
  @willpower        = 0.8
  @inhibition_log   = []
  @suppressed_count = 0
  @failed_count     = 0
  @redirected_count = 0
end

Instance Attribute Details

#failed_countObject (readonly)

Returns the value of attribute failed_count.



10
11
12
# File 'lib/legion/extensions/agentic/executive/inhibition/helpers/inhibition_model.rb', line 10

def failed_count
  @failed_count
end

#inhibition_logObject (readonly)

Returns the value of attribute inhibition_log.



10
11
12
# File 'lib/legion/extensions/agentic/executive/inhibition/helpers/inhibition_model.rb', line 10

def inhibition_log
  @inhibition_log
end

#redirected_countObject (readonly)

Returns the value of attribute redirected_count.



10
11
12
# File 'lib/legion/extensions/agentic/executive/inhibition/helpers/inhibition_model.rb', line 10

def redirected_count
  @redirected_count
end

#suppressed_countObject (readonly)

Returns the value of attribute suppressed_count.



10
11
12
# File 'lib/legion/extensions/agentic/executive/inhibition/helpers/inhibition_model.rb', line 10

def suppressed_count
  @suppressed_count
end

#willpowerObject (readonly)

Returns the value of attribute willpower.



10
11
12
# File 'lib/legion/extensions/agentic/executive/inhibition/helpers/inhibition_model.rb', line 10

def willpower
  @willpower
end

Instance Method Details

#apply_strategy(impulse, strategy) ⇒ Object



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
56
57
# File 'lib/legion/extensions/agentic/executive/inhibition/helpers/inhibition_model.rb', line 30

def apply_strategy(impulse, strategy)
  deplete_willpower(impulse.strength) unless strategy == :auto_suppress

  case strategy
  when :failed
    @failed_count += 1
  when :redirect
    @redirected_count += 1
    @suppressed_count += 1
  else
    @suppressed_count += 1
  end

  entry = {
    impulse_id: impulse.id,
    type:       impulse.type,
    action:     impulse.action,
    strength:   impulse.strength,
    strategy:   strategy,
    willpower:  @willpower.round(4),
    at:         Time.now.utc
  }

  @inhibition_log << entry
  @inhibition_log.shift while @inhibition_log.size > Constants::MAX_INHIBITION_LOG

  entry
end

#delay_discount(reward_value, delay_ticks) ⇒ Object



80
81
82
# File 'lib/legion/extensions/agentic/executive/inhibition/helpers/inhibition_model.rb', line 80

def delay_discount(reward_value, delay_ticks)
  reward_value / (1.0 + (Constants::DELAY_DISCOUNT_RATE * delay_ticks))
end

#evaluate_impulse(impulse) ⇒ Object



20
21
22
23
24
25
26
27
28
# File 'lib/legion/extensions/agentic/executive/inhibition/helpers/inhibition_model.rb', line 20

def evaluate_impulse(impulse)
  if impulse.auto_suppressible?
    :auto_suppress
  elsif @willpower < Constants::WILLPOWER_THRESHOLD
    :failed
  else
    select_strategy(impulse)
  end
end

#recover_willpowerObject



59
60
61
# File 'lib/legion/extensions/agentic/executive/inhibition/helpers/inhibition_model.rb', line 59

def recover_willpower
  @willpower = [@willpower + Constants::FATIGUE_RECOVERY_RATE, 1.0].min
end

#stroop_conflict?(automatic_response, controlled_response) ⇒ Boolean

Returns:

  • (Boolean)


84
85
86
87
# File 'lib/legion/extensions/agentic/executive/inhibition/helpers/inhibition_model.rb', line 84

def stroop_conflict?(automatic_response, controlled_response)
  automatic_response != controlled_response &&
    automatic_strength(automatic_response) >= Constants::STROOP_CONFLICT_THRESHOLD
end

#success_rateObject



73
74
75
76
77
78
# File 'lib/legion/extensions/agentic/executive/inhibition/helpers/inhibition_model.rb', line 73

def success_rate
  total = @suppressed_count + @failed_count
  return 1.0 if total.zero?

  @suppressed_count.to_f / total
end

#willpower_statusObject



63
64
65
66
67
68
69
70
71
# File 'lib/legion/extensions/agentic/executive/inhibition/helpers/inhibition_model.rb', line 63

def willpower_status
  if @willpower >= 0.6
    :healthy
  elsif @willpower >= Constants::WILLPOWER_THRESHOLD
    :depleted
  else
    :exhausted
  end
end