Class: Legion::CLI::Chat::Tools::DetectAnomalies

Inherits:
RubyLLM::Tool
  • Object
show all
Defined in:
lib/legion/cli/chat/tools/detect_anomalies.rb

Constant Summary collapse

DEFAULT_PORT =
4567
DEFAULT_HOST =
'127.0.0.1'

Instance Method Summary collapse

Instance Method Details

#execute(threshold: 2.0) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
# File 'lib/legion/cli/chat/tools/detect_anomalies.rb', line 28

def execute(threshold: 2.0)
  data = api_get("/api/traces/anomalies?threshold=#{threshold.to_f}")
  return "API error: #{data[:error][:message]}" if data[:error]

  format_report(data[:data] || data)
rescue Errno::ECONNREFUSED
  'Legion daemon not running (cannot reach anomaly detection API).'
rescue StandardError => e
  Legion::Logging.warn("DetectAnomalies#execute failed: #{e.message}") if defined?(Legion::Logging)
  "Error detecting anomalies: #{e.message}"
end