Module: Legion::Extensions::Agentic::Self::DefaultModeNetwork::Runners::DefaultModeNetwork

Includes:
Helpers::Lex
Included in:
Client
Defined in:
lib/legion/extensions/agentic/self/default_mode_network/runners/default_mode_network.rb

Instance Method Summary collapse

Instance Method Details

#dmn_mode_statusObject



70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/legion/extensions/agentic/self/default_mode_network/runners/default_mode_network.rb', line 70

def dmn_mode_status(**)
  log.debug "[dmn] dmn_mode_status: mode=#{dmn_engine.mode}"
  mode        = dmn_engine.mode
  mode_label  = Helpers::Constants::ACTIVITY_LABELS[mode]
  idle_secs   = dmn_engine.idle_duration.round(2)
  {
    success:       true,
    mode:          mode,
    mode_label:    mode_label,
    idle_duration: idle_secs,
    thought_count: dmn_engine.thought_count
  }
end

#dmn_statsObject



106
107
108
109
# File 'lib/legion/extensions/agentic/self/default_mode_network/runners/default_mode_network.rb', line 106

def dmn_stats(**)
  log.debug '[dmn] dmn_stats'
  { success: true, stats: dmn_engine.to_h }
end

#generate_idle_thoughtObject



24
25
26
27
28
29
# File 'lib/legion/extensions/agentic/self/default_mode_network/runners/default_mode_network.rb', line 24

def generate_idle_thought(**)
  log.debug "[dmn] generate_idle_thought: mode=#{dmn_engine.mode}"
  thought = dmn_engine.generate_thought
  log.debug "[dmn] thought_generated: type=#{thought.thought_type} salience=#{thought.salience.round(2)} label=#{thought.label}"
  { success: true, thought: thought.to_h }
end

#register_external_stimulus(source: nil) ⇒ Object



13
14
15
16
17
18
19
20
21
22
# File 'lib/legion/extensions/agentic/self/default_mode_network/runners/default_mode_network.rb', line 13

def register_external_stimulus(source: nil, **)
  log.debug "[dmn] register_stimulus: source=#{source}"
  result = dmn_engine.register_stimulus(source: source)
  {
    success:       true,
    previous_mode: result[:previous_mode],
    current_mode:  result[:current_mode],
    source:        result[:source]
  }
end

#salient_thoughts(count: 5) ⇒ Object



63
64
65
66
67
68
# File 'lib/legion/extensions/agentic/self/default_mode_network/runners/default_mode_network.rb', line 63

def salient_thoughts(count: 5, **)
  count = count.to_i
  log.debug "[dmn] salient_thoughts: count=#{count}"
  thoughts = dmn_engine.salient_thoughts(count: count)
  { success: true, thoughts: thoughts.map(&:to_h), count: thoughts.size }
end

#trigger_self_reflectionObject



31
32
33
34
35
36
37
# File 'lib/legion/extensions/agentic/self/default_mode_network/runners/default_mode_network.rb', line 31

def trigger_self_reflection(**)
  log.debug '[dmn] trigger_self_reflection'
  thought = dmn_engine.self_reflect
  dmn_engine.send(:store_thought, thought)
  log.debug "[dmn] self_reflect: topic=#{thought.seed} salience=#{thought.salience.round(2)}"
  { success: true, thought: thought.to_h }
end

#trigger_social_replay(interaction: nil) ⇒ Object



39
40
41
42
43
44
45
# File 'lib/legion/extensions/agentic/self/default_mode_network/runners/default_mode_network.rb', line 39

def trigger_social_replay(interaction: nil, **)
  log.debug "[dmn] trigger_social_replay: interaction=#{interaction}"
  thought = dmn_engine.social_replay(interaction: interaction)
  dmn_engine.send(:store_thought, thought)
  log.debug "[dmn] social_replay: seed=#{thought.seed} salience=#{thought.salience.round(2)}"
  { success: true, thought: thought.to_h }
end

#trigger_spontaneous_plan(goal: nil) ⇒ Object



47
48
49
50
51
52
53
# File 'lib/legion/extensions/agentic/self/default_mode_network/runners/default_mode_network.rb', line 47

def trigger_spontaneous_plan(goal: nil, **)
  log.debug "[dmn] trigger_spontaneous_plan: goal=#{goal}"
  thought = dmn_engine.plan_spontaneously(goal: goal)
  dmn_engine.send(:store_thought, thought)
  log.debug "[dmn] spontaneous_plan: goal=#{thought.seed} salience=#{thought.salience.round(2)}"
  { success: true, thought: thought.to_h }
end

#trigger_wandering(seed: nil) ⇒ Object



55
56
57
58
59
60
61
# File 'lib/legion/extensions/agentic/self/default_mode_network/runners/default_mode_network.rb', line 55

def trigger_wandering(seed: nil, **)
  log.debug "[dmn] trigger_wandering: seed=#{seed}"
  thought = dmn_engine.wander(seed: seed)
  dmn_engine.send(:store_thought, thought)
  log.debug "[dmn] wandering: seed=#{thought.seed} chain_length=#{thought.association_chain.size}"
  { success: true, thought: thought.to_h }
end

#update_dmnObject



84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/legion/extensions/agentic/self/default_mode_network/runners/default_mode_network.rb', line 84

def update_dmn(**)
  log.debug '[dmn] update_dmn: tick'
  tick_result   = dmn_engine.tick_mode
  faded_count   = dmn_engine.decay_all
  thought       = nil

  if %i[idle deep_idle].include?(dmn_engine.mode)
    thought = dmn_engine.generate_thought
    log.debug "[dmn] idle_thought: type=#{thought.thought_type} salience=#{thought.salience.round(2)}"
  end

  log.debug "[dmn] update_dmn: mode=#{tick_result[:current_mode]} faded=#{faded_count} thoughts=#{dmn_engine.thought_count}"
  {
    success:       true,
    mode:          tick_result[:current_mode],
    previous_mode: tick_result[:previous_mode],
    faded_count:   faded_count,
    thought_count: dmn_engine.thought_count,
    new_thought:   thought&.to_h
  }
end