Module: Legion::TaskOutcomeObserver

Defined in:
lib/legion/task_outcome_observer.rb

Class Method Summary collapse

Class Method Details

.enabled?Boolean

Returns:

  • (Boolean)


23
24
25
26
27
28
29
30
31
32
# File 'lib/legion/task_outcome_observer.rb', line 23

def enabled?
  settings = begin
    Legion::Settings[:task_outcome_observer]
  rescue StandardError
    nil
  end
  return true unless settings.is_a?(Hash)

  settings.fetch(:enabled, true)
end

.setupObject



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/legion/task_outcome_observer.rb', line 6

def setup
  return unless enabled?

  Legion::Events.on('task.completed') do |payload|
    handle_outcome(payload, success: true)
  end

  Legion::Events.on('task.failed') do |payload|
    handle_outcome(payload, success: false)
  end

  setup_llm_reflection_hook
  Legion::Logging.info '[TaskOutcomeObserver] wired to task.completed and task.failed'
rescue StandardError => e
  Legion::Logging.warn "[TaskOutcomeObserver] setup failed: #{e.message}" if defined?(Legion::Logging)
end