Class: Legion::CLI::Chat::Tools::EscalationStatus
- Inherits:
-
Tools::Base
- Object
- Tools::Base
- Legion::CLI::Chat::Tools::EscalationStatus
show all
- Defined in:
- lib/legion/cli/chat/tools/escalation_status.rb
Class Method Summary
collapse
Methods inherited from Tools::Base
deferred, deferred?, description, error_response, extension, handle_exception, input_schema, log, mcp_category, mcp_tier, runner, sticky, tags, text_response, tool_name, trigger_words
Class Method Details
.call(action: 'summary') ⇒ Object
18
19
20
21
22
23
24
25
|
# File 'lib/legion/cli/chat/tools/escalation_status.rb', line 18
def self.call(action: 'summary')
return 'Escalation tracker not available.' unless tracker_available?
case action.to_s
when 'rate' then format_rate
else format_summary
end
end
|
69
70
71
72
73
|
# File 'lib/legion/cli/chat/tools/escalation_status.rb', line 69
def self.format_rate
rate = Legion::LLM::EscalationTracker.escalation_rate
format('Escalation Rate: %<c>d escalations in the last %<m>d minutes',
c: rate[:count], m: rate[:window_seconds] / 60)
end
|
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
# File 'lib/legion/cli/chat/tools/escalation_status.rb', line 31
def self.format_summary
s = Legion::LLM::EscalationTracker.summary
lines = ["Model Escalation Summary:\n"]
lines << format(' Total Escalations: %<v>d', v: s[:total_escalations])
if s[:total_escalations].zero?
lines << ' No escalations recorded.'
return lines.join("\n")
end
unless s[:by_reason].empty?
lines << ''
lines << ' By Reason:'
s[:by_reason].sort_by { |_, c| -c }.each do |reason, count|
lines << format(' %<r>-20s %<c>d', r: reason, c: count)
end
end
unless s[:by_target_model].empty?
lines << ''
lines << ' Escalated To:'
s[:by_target_model].sort_by { |_, c| -c }.each do |model, count|
lines << format(' %<m>-25s %<c>d', m: model, c: count)
end
end
unless s[:recent].empty?
lines << ''
lines << ' Recent:'
s[:recent].first(5).each do |entry|
lines << format(' %<from>s -> %<to>s (%<reason>s)',
from: entry[:from_model], to: entry[:to_model], reason: entry[:reason])
end
end
lines.join("\n")
end
|
.tracker_available? ⇒ Boolean
27
28
29
|
# File 'lib/legion/cli/chat/tools/escalation_status.rb', line 27
def self.tracker_available?
defined?(Legion::LLM::EscalationTracker)
end
|