Class: Legion::Extensions::Agentic::Executive::Inertia::Helpers::Belief
- Inherits:
-
Object
- Object
- Legion::Extensions::Agentic::Executive::Inertia::Helpers::Belief
- 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
-
#challenges_accepted ⇒ Object
readonly
Returns the value of attribute challenges_accepted.
-
#challenges_resisted ⇒ Object
readonly
Returns the value of attribute challenges_resisted.
-
#content ⇒ Object
readonly
Returns the value of attribute content.
-
#conviction ⇒ Object
readonly
Returns the value of attribute conviction.
-
#created_at ⇒ Object
readonly
Returns the value of attribute created_at.
-
#domain ⇒ Object
readonly
Returns the value of attribute domain.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#inertia ⇒ Object
readonly
Returns the value of attribute inertia.
Instance Method Summary collapse
- #challenge!(strength: 0.5) ⇒ Object
- #conviction_label ⇒ Object
- #entrenched? ⇒ Boolean
- #flexible? ⇒ Boolean
- #inertia_label ⇒ Object
-
#initialize(content:, domain: :factual, conviction: 0.5) ⇒ Belief
constructor
A new instance of Belief.
- #reinforce!(amount: 0.1) ⇒ Object
- #resistance_rate ⇒ Object
- #to_h ⇒ Object
- #total_challenges ⇒ Object
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_accepted ⇒ Object (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_resisted ⇒ Object (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 |
#content ⇒ Object (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 |
#conviction ⇒ Object (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_at ⇒ Object (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 |
#domain ⇒ Object (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 |
#id ⇒ Object (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 |
#inertia ⇒ Object (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_label ⇒ Object
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
48 49 50 |
# File 'lib/legion/extensions/agentic/executive/inertia/helpers/belief.rb', line 48 def entrenched? @inertia >= CONVICTION_THRESHOLD end |
#flexible? ⇒ Boolean
52 53 54 |
# File 'lib/legion/extensions/agentic/executive/inertia/helpers/belief.rb', line 52 def flexible? @inertia <= FLEXIBILITY_THRESHOLD end |
#inertia_label ⇒ Object
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_rate ⇒ Object
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_h ⇒ Object
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_challenges ⇒ Object
56 57 58 |
# File 'lib/legion/extensions/agentic/executive/inertia/helpers/belief.rb', line 56 def total_challenges @challenges_resisted + @challenges_accepted end |