Class: Legion::Extensions::Agentic::Executive::Inertia::Helpers::Belief

Inherits:
Object
  • Object
show all
Includes:
Constants
Defined in:
lib/legion/extensions/agentic/executive/inertia/helpers/belief.rb

Constant Summary

Constants included from Constants

Constants::BELIEF_DOMAINS, Constants::CONVICTION_LABELS, Constants::CONVICTION_THRESHOLD, Constants::DEFAULT_INERTIA, Constants::FLEXIBILITY_THRESHOLD, Constants::INERTIA_GROWTH_RATE, Constants::INERTIA_LABELS, Constants::INERTIA_REDUCTION_RATE, Constants::MAX_BELIEFS, Constants::MAX_CHALLENGES

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(content:, domain: :factual, conviction: 0.5) ⇒ Belief

Returns a new instance of Belief.



17
18
19
20
21
22
23
24
25
26
# File 'lib/legion/extensions/agentic/executive/inertia/helpers/belief.rb', line 17

def initialize(content:, domain: :factual, conviction: 0.5)
  @id                  = SecureRandom.uuid
  @content             = content
  @domain              = domain.to_sym
  @conviction          = conviction.to_f.clamp(0.0, 1.0)
  @inertia             = DEFAULT_INERTIA
  @challenges_resisted = 0
  @challenges_accepted = 0
  @created_at          = Time.now.utc
end

Instance Attribute Details

#challenges_acceptedObject (readonly)

Returns the value of attribute challenges_accepted.



14
15
16
# File 'lib/legion/extensions/agentic/executive/inertia/helpers/belief.rb', line 14

def challenges_accepted
  @challenges_accepted
end

#challenges_resistedObject (readonly)

Returns the value of attribute challenges_resisted.



14
15
16
# File 'lib/legion/extensions/agentic/executive/inertia/helpers/belief.rb', line 14

def challenges_resisted
  @challenges_resisted
end

#contentObject (readonly)

Returns the value of attribute content.



14
15
16
# File 'lib/legion/extensions/agentic/executive/inertia/helpers/belief.rb', line 14

def content
  @content
end

#convictionObject (readonly)

Returns the value of attribute conviction.



14
15
16
# File 'lib/legion/extensions/agentic/executive/inertia/helpers/belief.rb', line 14

def conviction
  @conviction
end

#created_atObject (readonly)

Returns the value of attribute created_at.



14
15
16
# File 'lib/legion/extensions/agentic/executive/inertia/helpers/belief.rb', line 14

def created_at
  @created_at
end

#domainObject (readonly)

Returns the value of attribute domain.



14
15
16
# File 'lib/legion/extensions/agentic/executive/inertia/helpers/belief.rb', line 14

def domain
  @domain
end

#idObject (readonly)

Returns the value of attribute id.



14
15
16
# File 'lib/legion/extensions/agentic/executive/inertia/helpers/belief.rb', line 14

def id
  @id
end

#inertiaObject (readonly)

Returns the value of attribute inertia.



14
15
16
# File 'lib/legion/extensions/agentic/executive/inertia/helpers/belief.rb', line 14

def inertia
  @inertia
end

Instance Method Details

#challenge!(strength: 0.5) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/legion/extensions/agentic/executive/inertia/helpers/belief.rb', line 28

def challenge!(strength: 0.5)
  effective = (strength * (1.0 - @inertia)).round(10)
  if effective > @conviction * 0.5
    @conviction = (@conviction - (effective * 0.3)).clamp(0.0, 1.0).round(10)
    @challenges_accepted += 1
    @inertia = (@inertia - INERTIA_REDUCTION_RATE).clamp(0.0, 1.0).round(10)
    :accepted
  else
    @challenges_resisted += 1
    @inertia = (@inertia + INERTIA_GROWTH_RATE).clamp(0.0, 1.0).round(10)
    :resisted
  end
end

#conviction_labelObject



71
72
73
74
# File 'lib/legion/extensions/agentic/executive/inertia/helpers/belief.rb', line 71

def conviction_label
  match = CONVICTION_LABELS.find { |range, _| range.cover?(@conviction) }
  match ? match.last : :uncertain
end

#entrenched?Boolean

Returns:

  • (Boolean)


48
49
50
# File 'lib/legion/extensions/agentic/executive/inertia/helpers/belief.rb', line 48

def entrenched?
  @inertia >= CONVICTION_THRESHOLD
end

#flexible?Boolean

Returns:

  • (Boolean)


52
53
54
# File 'lib/legion/extensions/agentic/executive/inertia/helpers/belief.rb', line 52

def flexible?
  @inertia <= FLEXIBILITY_THRESHOLD
end

#inertia_labelObject



66
67
68
69
# File 'lib/legion/extensions/agentic/executive/inertia/helpers/belief.rb', line 66

def inertia_label
  match = INERTIA_LABELS.find { |range, _| range.cover?(@inertia) }
  match ? match.last : :fluid
end

#reinforce!(amount: 0.1) ⇒ Object



42
43
44
45
46
# File 'lib/legion/extensions/agentic/executive/inertia/helpers/belief.rb', line 42

def reinforce!(amount: 0.1)
  @conviction = (@conviction + amount).clamp(0.0, 1.0).round(10)
  @inertia = (@inertia + INERTIA_GROWTH_RATE).clamp(0.0, 1.0).round(10)
  self
end

#resistance_rateObject



60
61
62
63
64
# File 'lib/legion/extensions/agentic/executive/inertia/helpers/belief.rb', line 60

def resistance_rate
  return 0.0 if total_challenges.zero?

  (@challenges_resisted.to_f / total_challenges).round(4)
end

#to_hObject



76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/legion/extensions/agentic/executive/inertia/helpers/belief.rb', line 76

def to_h
  {
    id:                  @id,
    content:             @content,
    domain:              @domain,
    conviction:          @conviction,
    conviction_label:    conviction_label,
    inertia:             @inertia,
    inertia_label:       inertia_label,
    entrenched:          entrenched?,
    flexible:            flexible?,
    challenges_resisted: @challenges_resisted,
    challenges_accepted: @challenges_accepted,
    resistance_rate:     resistance_rate,
    created_at:          @created_at
  }
end

#total_challengesObject



56
57
58
# File 'lib/legion/extensions/agentic/executive/inertia/helpers/belief.rb', line 56

def total_challenges
  @challenges_resisted + @challenges_accepted
end