Class: Legion::Extensions::Agentic::Executive::DissonanceResolution::Helpers::DissonanceConflict

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

Constant Summary

Constants included from Constants

Constants::DEFAULT_TENSION, Constants::MAX_CONFLICTS, Constants::MAX_STRATEGIES, Constants::OUTCOME_LABELS, Constants::RESOLUTION_THRESHOLD, Constants::STRATEGIES, Constants::TENSION_DECAY, Constants::TENSION_LABELS

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(belief_a:, belief_b:, domain: :general, tension: DEFAULT_TENSION) ⇒ DissonanceConflict

Returns a new instance of DissonanceConflict.



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

def initialize(belief_a:, belief_b:, domain: :general, tension: DEFAULT_TENSION)
  @id            = SecureRandom.uuid
  @belief_a      = belief_a
  @belief_b      = belief_b
  @domain        = domain.to_sym
  @tension       = tension.to_f.clamp(0.0, 1.0)
  @strategy_used = nil
  @outcome       = :ongoing
  @attempts      = 0
  @created_at    = Time.now.utc
  @resolved_at   = nil
end

Instance Attribute Details

#attemptsObject (readonly)

Returns the value of attribute attempts.



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

def attempts
  @attempts
end

#belief_aObject (readonly)

Returns the value of attribute belief_a.



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

def belief_a
  @belief_a
end

#belief_bObject (readonly)

Returns the value of attribute belief_b.



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

def belief_b
  @belief_b
end

#created_atObject (readonly)

Returns the value of attribute created_at.



14
15
16
# File 'lib/legion/extensions/agentic/executive/dissonance_resolution/helpers/dissonance_conflict.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/dissonance_resolution/helpers/dissonance_conflict.rb', line 14

def domain
  @domain
end

#idObject (readonly)

Returns the value of attribute id.



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

def id
  @id
end

#outcomeObject (readonly)

Returns the value of attribute outcome.



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

def outcome
  @outcome
end

#resolved_atObject (readonly)

Returns the value of attribute resolved_at.



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

def resolved_at
  @resolved_at
end

#strategy_usedObject (readonly)

Returns the value of attribute strategy_used.



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

def strategy_used
  @strategy_used
end

#tensionObject (readonly)

Returns the value of attribute tension.



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

def tension
  @tension
end

Instance Method Details

#abandon!Object



62
63
64
65
66
# File 'lib/legion/extensions/agentic/executive/dissonance_resolution/helpers/dissonance_conflict.rb', line 62

def abandon!
  @outcome = :abandoned
  @resolved_at = Time.now.utc
  self
end

#apply_strategy!(strategy:, effectiveness: 0.3) ⇒ Object



39
40
41
42
43
44
45
46
47
# File 'lib/legion/extensions/agentic/executive/dissonance_resolution/helpers/dissonance_conflict.rb', line 39

def apply_strategy!(strategy:, effectiveness: 0.3)
  @strategy_used = strategy.to_sym
  @attempts += 1
  reduction = effectiveness.to_f.clamp(0.0, 0.5)
  @tension = (@tension - reduction).clamp(0.0, 1.0).round(10)
  @outcome = :resolved if resolved?
  @resolved_at = Time.now.utc if resolved?
  self
end

#decay!Object



55
56
57
58
59
60
# File 'lib/legion/extensions/agentic/executive/dissonance_resolution/helpers/dissonance_conflict.rb', line 55

def decay!
  @tension = (@tension - TENSION_DECAY).clamp(0.0, 1.0).round(10)
  @outcome = :resolved if resolved? && @outcome == :ongoing
  @resolved_at = Time.now.utc if resolved? && @resolved_at.nil?
  self
end

#escalate!(amount: 0.15) ⇒ Object



49
50
51
52
53
# File 'lib/legion/extensions/agentic/executive/dissonance_resolution/helpers/dissonance_conflict.rb', line 49

def escalate!(amount: 0.15)
  @tension = (@tension + amount).clamp(0.0, 1.0).round(10)
  @outcome = :escalated if @tension >= 0.9
  self
end

#resolved?Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/legion/extensions/agentic/executive/dissonance_resolution/helpers/dissonance_conflict.rb', line 35

def resolved?
  @tension <= RESOLUTION_THRESHOLD
end

#tension_labelObject



30
31
32
33
# File 'lib/legion/extensions/agentic/executive/dissonance_resolution/helpers/dissonance_conflict.rb', line 30

def tension_label
  match = TENSION_LABELS.find { |range, _| range.cover?(@tension) }
  match ? match.last : :resolved
end

#to_hObject



68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/legion/extensions/agentic/executive/dissonance_resolution/helpers/dissonance_conflict.rb', line 68

def to_h
  {
    id:            @id,
    belief_a:      @belief_a,
    belief_b:      @belief_b,
    domain:        @domain,
    tension:       @tension,
    tension_label: tension_label,
    resolved:      resolved?,
    strategy_used: @strategy_used,
    outcome:       @outcome,
    attempts:      @attempts,
    created_at:    @created_at,
    resolved_at:   @resolved_at
  }
end