Class: Legion::Extensions::Agentic::Affect::Defusion::Helpers::Thought

Inherits:
Object
  • Object
show all
Includes:
Constants
Defined in:
lib/legion/extensions/agentic/affect/defusion/helpers/thought.rb

Constant Summary

Constants included from Constants

Constants::BELIEF_LABELS, Constants::DEFAULT_FUSION, Constants::DEFUSED_THRESHOLD, Constants::DEFUSION_TECHNIQUES, Constants::FUSION_DELTA_FUSE, Constants::FUSION_DELTA_VISIT, Constants::FUSION_LABELS, Constants::FUSION_THRESHOLD, Constants::MAX_THOUGHTS, Constants::RECOMMENDED_TECHNIQUES, Constants::RUMINATION_COUNT, Constants::TECHNIQUE_POTENCY, Constants::THOUGHT_TYPES

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(content:, thought_type:, belief_strength:) ⇒ Thought

Returns a new instance of Thought.



17
18
19
20
21
22
23
24
25
26
# File 'lib/legion/extensions/agentic/affect/defusion/helpers/thought.rb', line 17

def initialize(content:, thought_type:, belief_strength:)
  @id              = SecureRandom.uuid
  @content         = content
  @thought_type    = thought_type
  @belief_strength = belief_strength.clamp(0.0, 1.0)
  @fusion_level    = DEFAULT_FUSION
  @defusion_count  = 0
  @visit_count     = 0
  @created_at      = Time.now.utc
end

Instance Attribute Details

#belief_strengthObject (readonly)

Returns the value of attribute belief_strength.



14
15
16
# File 'lib/legion/extensions/agentic/affect/defusion/helpers/thought.rb', line 14

def belief_strength
  @belief_strength
end

#contentObject (readonly)

Returns the value of attribute content.



14
15
16
# File 'lib/legion/extensions/agentic/affect/defusion/helpers/thought.rb', line 14

def content
  @content
end

#created_atObject (readonly)

Returns the value of attribute created_at.



14
15
16
# File 'lib/legion/extensions/agentic/affect/defusion/helpers/thought.rb', line 14

def created_at
  @created_at
end

#defusion_countObject (readonly)

Returns the value of attribute defusion_count.



14
15
16
# File 'lib/legion/extensions/agentic/affect/defusion/helpers/thought.rb', line 14

def defusion_count
  @defusion_count
end

#fusion_levelObject (readonly)

Returns the value of attribute fusion_level.



14
15
16
# File 'lib/legion/extensions/agentic/affect/defusion/helpers/thought.rb', line 14

def fusion_level
  @fusion_level
end

#idObject (readonly)

Returns the value of attribute id.



14
15
16
# File 'lib/legion/extensions/agentic/affect/defusion/helpers/thought.rb', line 14

def id
  @id
end

#thought_typeObject (readonly)

Returns the value of attribute thought_type.



14
15
16
# File 'lib/legion/extensions/agentic/affect/defusion/helpers/thought.rb', line 14

def thought_type
  @thought_type
end

#visit_countObject (readonly)

Returns the value of attribute visit_count.



14
15
16
# File 'lib/legion/extensions/agentic/affect/defusion/helpers/thought.rb', line 14

def visit_count
  @visit_count
end

Instance Method Details

#belief_labelObject



65
66
67
# File 'lib/legion/extensions/agentic/affect/defusion/helpers/thought.rb', line 65

def belief_label
  BELIEF_LABELS.find { |range, _| range.cover?(@belief_strength) }&.last || :unknown
end

#defuse!(technique:) ⇒ Object



28
29
30
31
32
33
34
# File 'lib/legion/extensions/agentic/affect/defusion/helpers/thought.rb', line 28

def defuse!(technique:)
  potency = TECHNIQUE_POTENCY.fetch(technique, 0.0)
  before  = @fusion_level
  @fusion_level = (@fusion_level - potency).clamp(0.0, 1.0).round(10)
  @defusion_count += 1
  { before: before, after: @fusion_level, technique: technique, reduction: (before - @fusion_level).round(10) }
end

#defused?Boolean

Returns:

  • (Boolean)


53
54
55
# File 'lib/legion/extensions/agentic/affect/defusion/helpers/thought.rb', line 53

def defused?
  @fusion_level <= DEFUSED_THRESHOLD
end

#enmeshed?Boolean

Returns:

  • (Boolean)


49
50
51
# File 'lib/legion/extensions/agentic/affect/defusion/helpers/thought.rb', line 49

def enmeshed?
  @fusion_level >= FUSION_THRESHOLD
end

#fuse!Object



36
37
38
39
40
# File 'lib/legion/extensions/agentic/affect/defusion/helpers/thought.rb', line 36

def fuse!
  before = @fusion_level
  @fusion_level = (@fusion_level + FUSION_DELTA_FUSE).clamp(0.0, 1.0).round(10)
  { before: before, after: @fusion_level }
end

#fusion_labelObject



61
62
63
# File 'lib/legion/extensions/agentic/affect/defusion/helpers/thought.rb', line 61

def fusion_label
  FUSION_LABELS.find { |range, _| range.cover?(@fusion_level) }&.last || :unknown
end

#ruminating?Boolean

Returns:

  • (Boolean)


57
58
59
# File 'lib/legion/extensions/agentic/affect/defusion/helpers/thought.rb', line 57

def ruminating?
  @visit_count >= RUMINATION_COUNT
end

#to_hObject



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/legion/extensions/agentic/affect/defusion/helpers/thought.rb', line 69

def to_h
  {
    id:              @id,
    content:         @content,
    thought_type:    @thought_type,
    belief_strength: @belief_strength,
    fusion_level:    @fusion_level,
    defusion_count:  @defusion_count,
    visit_count:     @visit_count,
    fusion_label:    fusion_label,
    belief_label:    belief_label,
    enmeshed:        enmeshed?,
    defused:         defused?,
    ruminating:      ruminating?,
    created_at:      @created_at
  }
end

#visit!Object



42
43
44
45
46
47
# File 'lib/legion/extensions/agentic/affect/defusion/helpers/thought.rb', line 42

def visit!
  @visit_count += 1
  before = @fusion_level
  @fusion_level = (@fusion_level + FUSION_DELTA_VISIT).clamp(0.0, 1.0).round(10)
  { visit_count: @visit_count, fusion_before: before, fusion_after: @fusion_level }
end