Module: Legion::Extensions::Agentic::Affect::Motivation::Runners::Motivation

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

Instance Method Summary collapse

Instance Method Details

#commit_to_goal(goal_id:, drives:) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/legion/extensions/agentic/affect/motivation/runners/motivation.rb', line 44

def commit_to_goal(goal_id:, drives:, **)
  drive_syms = Array(drives).map(&:to_sym)
  result = motivation_store.commit_goal(goal_id, drive_syms)

  if result
    energy = motivation_store.goal_energy(goal_id)
    log.info("[motivation] committed goal=#{goal_id} energy=#{energy.round(3)}")
    { success: true, goal_id: goal_id, energy: energy.round(4) }
  else
    log.warn("[motivation] commit_goal rejected: no valid drives for #{goal_id}")
    { success: false, error: 'no valid drives provided' }
  end
end

#drive_statusObject



76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/legion/extensions/agentic/affect/motivation/runners/motivation.rb', line 76

def drive_status(**)
  drives = motivation_store.drive_state.drives.transform_values do |d|
    { level: d[:level].round(4), satisfied: d[:satisfied] }
  end

  log.debug('[motivation] drive_status')
  {
    drives:  drives,
    mode:    motivation_store.drive_state.current_mode,
    overall: motivation_store.drive_state.overall_level.round(4)
  }
end

#most_motivated_goalObject



70
71
72
73
74
# File 'lib/legion/extensions/agentic/affect/motivation/runners/motivation.rb', line 70

def most_motivated_goal(**)
  result = motivation_store.most_motivated_goal
  log.debug("[motivation] most_motivated_goal=#{result&.fetch(:goal_id, nil)}")
  result || { goal_id: nil, energy: 0.0, drives: [] }
end

#motivation_for(goal_id:) ⇒ Object



64
65
66
67
68
# File 'lib/legion/extensions/agentic/affect/motivation/runners/motivation.rb', line 64

def motivation_for(goal_id:, **)
  energy = motivation_store.goal_energy(goal_id)
  log.debug("[motivation] motivation_for goal=#{goal_id} energy=#{energy.round(3)}")
  { goal_id: goal_id, energy: energy.round(4) }
end

#motivation_statsObject



89
90
91
92
# File 'lib/legion/extensions/agentic/affect/motivation/runners/motivation.rb', line 89

def motivation_stats(**)
  log.debug('[motivation] stats')
  motivation_store.stats
end

#release_goal(goal_id:) ⇒ Object



58
59
60
61
62
# File 'lib/legion/extensions/agentic/affect/motivation/runners/motivation.rb', line 58

def release_goal(goal_id:, **)
  motivation_store.release_goal(goal_id)
  log.debug("[motivation] released goal=#{goal_id}")
  { success: true, goal_id: goal_id }
end

#signal_drive(drive:, signal:) ⇒ Object



33
34
35
36
37
38
39
40
41
42
# File 'lib/legion/extensions/agentic/affect/motivation/runners/motivation.rb', line 33

def signal_drive(drive:, signal:, **)
  drive_sym = drive.to_sym
  return { success: false, error: "unknown drive: #{drive}" } unless Helpers::Constants::DRIVE_TYPES.include?(drive_sym)

  motivation_store.drive_state.update_drive(drive_sym, signal.to_f)
  level = motivation_store.drive_state.drive_level(drive_sym)

  log.debug("[motivation] drive signal: #{drive_sym}=#{level.round(3)}")
  { success: true, drive: drive_sym, level: level.round(4) }
end

#update_motivation(tick_results: {}) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/legion/extensions/agentic/affect/motivation/runners/motivation.rb', line 13

def update_motivation(tick_results: {}, **)
  extract_drive_signals(tick_results)
  motivation_store.drive_state.decay_all
  burnout = motivation_store.burnout_check
  mode    = motivation_store.drive_state.current_mode

  log.debug("[motivation] mode=#{mode} " \
            "overall=#{motivation_store.drive_state.overall_level.round(3)} " \
            "amotivated=#{motivation_store.drive_state.amotivated?}")

  {
    mode:              mode,
    overall_level:     motivation_store.drive_state.overall_level.round(4),
    intrinsic_average: motivation_store.drive_state.intrinsic_average.round(4),
    extrinsic_average: motivation_store.drive_state.extrinsic_average.round(4),
    amotivated:        motivation_store.drive_state.amotivated?,
    burnout:           burnout[:burnout]
  }
end