Class: Legion::Extensions::Agentic::Executive::Dwell::Helpers::DwellTopic

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

Constant Summary

Constants included from Constants

Constants::BASE_DWELL, Constants::COMPLEXITY_WEIGHT, Constants::DISENGAGE_LABELS, Constants::DWELL_DECAY, Constants::DWELL_LABELS, Constants::EMOTION_WEIGHT, Constants::ENGAGEMENT_BOOST, Constants::ENGAGEMENT_LABELS, Constants::FLEETING_THRESHOLD, Constants::MAX_DWELL_HISTORY, Constants::MAX_TOPICS, Constants::NOVELTY_WEIGHT, Constants::RUMINATION_THRESHOLD, Constants::SALIENCE_WEIGHT, Constants::STICKY_THRESHOLD, Constants::TOPIC_TYPES

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(content:, topic_type: :concept, salience: 0.5, novelty: 0.5, emotional_intensity: 0.3, complexity: 0.5) ⇒ DwellTopic

Returns a new instance of DwellTopic.



18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/legion/extensions/agentic/executive/dwell/helpers/dwell_topic.rb', line 18

def initialize(content:, topic_type: :concept, salience: 0.5,
               novelty: 0.5, emotional_intensity: 0.3, complexity: 0.5)
  @id                  = SecureRandom.uuid
  @content             = content
  @topic_type          = topic_type.to_sym
  @salience            = salience.to_f.clamp(0.0, 1.0).round(10)
  @novelty             = novelty.to_f.clamp(0.0, 1.0).round(10)
  @emotional_intensity = emotional_intensity.to_f.clamp(0.0, 1.0).round(10)
  @complexity          = complexity.to_f.clamp(0.0, 1.0).round(10)
  @dwell_level         = compute_initial_dwell
  @engagement_count    = 0
  @created_at          = Time.now.utc
end

Instance Attribute Details

#complexityObject (readonly)

Returns the value of attribute complexity.



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

def complexity
  @complexity
end

#contentObject (readonly)

Returns the value of attribute content.



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

def created_at
  @created_at
end

#dwell_levelObject (readonly)

Returns the value of attribute dwell_level.



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

def dwell_level
  @dwell_level
end

#emotional_intensityObject (readonly)

Returns the value of attribute emotional_intensity.



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

def emotional_intensity
  @emotional_intensity
end

#engagement_countObject (readonly)

Returns the value of attribute engagement_count.



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

def engagement_count
  @engagement_count
end

#idObject (readonly)

Returns the value of attribute id.



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

def id
  @id
end

#noveltyObject (readonly)

Returns the value of attribute novelty.



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

def novelty
  @novelty
end

#salienceObject (readonly)

Returns the value of attribute salience.



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

def salience
  @salience
end

#topic_typeObject (readonly)

Returns the value of attribute topic_type.



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

def topic_type
  @topic_type
end

Instance Method Details

#decay!Object



38
39
40
41
42
# File 'lib/legion/extensions/agentic/executive/dwell/helpers/dwell_topic.rb', line 38

def decay!
  @dwell_level = (@dwell_level - DWELL_DECAY).clamp(0.0, 1.0).round(10)
  @novelty = (@novelty - 0.02).clamp(0.0, 1.0).round(10)
  self
end

#disengage!(force: 0.0) ⇒ Object



44
45
46
47
48
# File 'lib/legion/extensions/agentic/executive/dwell/helpers/dwell_topic.rb', line 44

def disengage!(force: 0.0)
  reduction = (0.1 + force).clamp(0.0, 1.0)
  @dwell_level = (@dwell_level - reduction).clamp(0.0, 1.0).round(10)
  self
end

#disengage_labelObject



77
78
79
80
# File 'lib/legion/extensions/agentic/executive/dwell/helpers/dwell_topic.rb', line 77

def disengage_label
  match = DISENGAGE_LABELS.find { |range, _| range.cover?(disengagement_difficulty) }
  match ? match.last : :effortless
end

#disengagement_difficultyObject



62
63
64
# File 'lib/legion/extensions/agentic/executive/dwell/helpers/dwell_topic.rb', line 62

def disengagement_difficulty
  ((@emotional_intensity * 0.4) + (@dwell_level * 0.4) + (@complexity * 0.2)).round(10)
end

#dwell_labelObject



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

def dwell_label
  match = DWELL_LABELS.find { |range, _| range.cover?(@dwell_level) }
  match ? match.last : :fleeting
end

#engage!Object



32
33
34
35
36
# File 'lib/legion/extensions/agentic/executive/dwell/helpers/dwell_topic.rb', line 32

def engage!
  @engagement_count += 1
  @dwell_level = (@dwell_level + ENGAGEMENT_BOOST).clamp(0.0, 1.0).round(10)
  self
end

#engagement_labelObject



71
72
73
74
75
# File 'lib/legion/extensions/agentic/executive/dwell/helpers/dwell_topic.rb', line 71

def engagement_label
  score = ((@dwell_level * 0.6) + (@salience * 0.4)).round(10)
  match = ENGAGEMENT_LABELS.find { |range, _| range.cover?(score) }
  match ? match.last : :disengaged
end

#fleeting?Boolean

Returns:

  • (Boolean)


54
55
56
# File 'lib/legion/extensions/agentic/executive/dwell/helpers/dwell_topic.rb', line 54

def fleeting?
  @dwell_level <= FLEETING_THRESHOLD
end

#ruminating?Boolean

Returns:

  • (Boolean)


58
59
60
# File 'lib/legion/extensions/agentic/executive/dwell/helpers/dwell_topic.rb', line 58

def ruminating?
  @dwell_level >= RUMINATION_THRESHOLD
end

#sticky?Boolean

Returns:

  • (Boolean)


50
51
52
# File 'lib/legion/extensions/agentic/executive/dwell/helpers/dwell_topic.rb', line 50

def sticky?
  @dwell_level >= STICKY_THRESHOLD
end

#to_hObject



82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/legion/extensions/agentic/executive/dwell/helpers/dwell_topic.rb', line 82

def to_h
  {
    id:                       @id,
    content:                  @content,
    topic_type:               @topic_type,
    salience:                 @salience,
    novelty:                  @novelty,
    emotional_intensity:      @emotional_intensity,
    complexity:               @complexity,
    dwell_level:              @dwell_level,
    dwell_label:              dwell_label,
    sticky:                   sticky?,
    fleeting:                 fleeting?,
    ruminating:               ruminating?,
    disengagement_difficulty: disengagement_difficulty,
    disengage_label:          disengage_label,
    engagement_count:         @engagement_count,
    engagement_label:         engagement_label,
    created_at:               @created_at
  }
end