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

Inherits:
Object
  • Object
show all
Includes:
Constants
Defined in:
lib/legion/extensions/agentic/executive/dwell/helpers/dwell_engine.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 Method Summary collapse

Constructor Details

#initializeDwellEngine

Returns a new instance of DwellEngine.



12
13
14
15
# File 'lib/legion/extensions/agentic/executive/dwell/helpers/dwell_engine.rb', line 12

def initialize
  @topics = {}
  @current_topic_id = nil
end

Instance Method Details

#add_topic(content:, topic_type: :concept, salience: 0.5, novelty: 0.5, emotional_intensity: 0.3, complexity: 0.5) ⇒ Object



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

def add_topic(content:, topic_type: :concept, salience: 0.5,
              novelty: 0.5, emotional_intensity: 0.3, complexity: 0.5)
  prune_if_needed
  topic = DwellTopic.new(
    content: content, topic_type: topic_type, salience: salience,
    novelty: novelty, emotional_intensity: emotional_intensity, complexity: complexity
  )
  @topics[topic.id] = topic
  topic
end

#average_disengagement_difficultyObject



82
83
84
85
86
87
# File 'lib/legion/extensions/agentic/executive/dwell/helpers/dwell_engine.rb', line 82

def average_disengagement_difficulty
  return 0.0 if @topics.empty?

  vals = @topics.values.map(&:disengagement_difficulty)
  (vals.sum / vals.size).round(10)
end

#average_dwellObject



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

def average_dwell
  return BASE_DWELL if @topics.empty?

  vals = @topics.values.map(&:dwell_level)
  (vals.sum / vals.size).round(10)
end

#current_topicObject



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

def current_topic
  @topics[@current_topic_id]
end

#decay_all!Object



46
47
48
49
# File 'lib/legion/extensions/agentic/executive/dwell/helpers/dwell_engine.rb', line 46

def decay_all!
  @topics.each_value(&:decay!)
  { topics_decayed: @topics.size }
end

#disengage(topic_id:, force: 0.0) ⇒ Object



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

def disengage(topic_id:, force: 0.0)
  topic = @topics[topic_id]
  return nil unless topic

  topic.disengage!(force: force)
  @current_topic_id = nil if @current_topic_id == topic_id
  topic
end

#dwell_reportObject



89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/legion/extensions/agentic/executive/dwell/helpers/dwell_engine.rb', line 89

def dwell_report
  {
    total_topics:                     @topics.size,
    current_topic:                    current_topic&.to_h,
    sticky_count:                     sticky_topics.size,
    fleeting_count:                   fleeting_topics.size,
    ruminating_count:                 ruminating_topics.size,
    average_dwell:                    average_dwell,
    average_disengagement_difficulty: average_disengagement_difficulty,
    most_engaging:                    most_engaging(limit: 3).map(&:to_h)
  }
end

#fleeting_topicsObject



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

def fleeting_topics
  @topics.values.select(&:fleeting?)
end

#focus_on(topic_id:) ⇒ Object



28
29
30
31
32
33
34
35
# File 'lib/legion/extensions/agentic/executive/dwell/helpers/dwell_engine.rb', line 28

def focus_on(topic_id:)
  topic = @topics[topic_id]
  return nil unless topic

  topic.engage!
  @current_topic_id = topic_id
  topic
end

#hardest_to_disengage(limit: 5) ⇒ Object



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

def hardest_to_disengage(limit: 5)
  @topics.values.sort_by { |t| -t.disengagement_difficulty }.first(limit)
end

#most_engaging(limit: 5) ⇒ Object



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

def most_engaging(limit: 5)
  @topics.values.sort_by { |t| -t.dwell_level }.first(limit)
end

#ruminating_topicsObject



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

def ruminating_topics
  @topics.values.select(&:ruminating?)
end

#sticky_topicsObject



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

def sticky_topics
  @topics.values.select(&:sticky?)
end

#to_hObject



102
103
104
105
106
107
108
109
110
# File 'lib/legion/extensions/agentic/executive/dwell/helpers/dwell_engine.rb', line 102

def to_h
  {
    total_topics:     @topics.size,
    current_topic_id: @current_topic_id,
    sticky_count:     sticky_topics.size,
    ruminating_count: ruminating_topics.size,
    average_dwell:    average_dwell
  }
end