Class: Legion::Extensions::Agentic::Executive::Triage::Helpers::TriageEngine
- Inherits:
-
Object
- Object
- Legion::Extensions::Agentic::Executive::Triage::Helpers::TriageEngine
show all
- Includes:
- Constants
- Defined in:
- lib/legion/extensions/agentic/executive/triage/helpers/triage_engine.rb
Constant Summary
Constants included
from Constants
Constants::CAPACITY_DEFAULT, Constants::CAPACITY_DRAIN, Constants::CAPACITY_LABELS, Constants::CAPACITY_RESTORE, Constants::MAX_DEMANDS, Constants::MAX_QUEUE_SIZE, Constants::OVERLOAD_THRESHOLD, Constants::QUEUE_LABELS, Constants::SEVERITY_LEVELS, Constants::SEVERITY_WEIGHTS, Constants::TRIAGE_LABELS, Constants::URGENCY_LEVELS, Constants::URGENCY_WEIGHTS
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods included from Constants
label_for
Constructor Details
Returns a new instance of TriageEngine.
14
15
16
17
|
# File 'lib/legion/extensions/agentic/executive/triage/helpers/triage_engine.rb', line 14
def initialize
@demands = {}
@capacity = CAPACITY_DEFAULT
end
|
Instance Attribute Details
#capacity ⇒ Object
Returns the value of attribute capacity.
12
13
14
|
# File 'lib/legion/extensions/agentic/executive/triage/helpers/triage_engine.rb', line 12
def capacity
@capacity
end
|
Instance Method Details
#active_demands ⇒ Object
69
|
# File 'lib/legion/extensions/agentic/executive/triage/helpers/triage_engine.rb', line 69
def active_demands = @demands.values.select(&:active?)
|
#add_demand(description:, domain: :general, severity: :moderate, urgency: :soon) ⇒ Object
19
20
21
22
23
24
25
26
27
28
|
# File 'lib/legion/extensions/agentic/executive/triage/helpers/triage_engine.rb', line 19
def add_demand(description:, domain: :general, severity: :moderate, urgency: :soon)
prune_if_needed
demand = Demand.new(
description: description, domain: domain, severity: severity, urgency: urgency
)
@demands[demand.id] = demand
drain_capacity!(demand.triage_score * CAPACITY_DRAIN)
demand.triage!
demand
end
|
#complete_demand(demand_id:) ⇒ Object
38
39
40
41
42
43
44
45
|
# File 'lib/legion/extensions/agentic/executive/triage/helpers/triage_engine.rb', line 38
def complete_demand(demand_id:)
demand = @demands[demand_id]
return nil unless demand
demand.complete!
restore_capacity!(CAPACITY_RESTORE)
demand
end
|
#completed_demands ⇒ Object
71
|
# File 'lib/legion/extensions/agentic/executive/triage/helpers/triage_engine.rb', line 71
def completed_demands = @demands.values.select { |d| d.status == :completed }
|
#defer_demand(demand_id:) ⇒ Object
47
48
49
50
51
52
53
54
|
# File 'lib/legion/extensions/agentic/executive/triage/helpers/triage_engine.rb', line 47
def defer_demand(demand_id:)
demand = @demands[demand_id]
return nil unless demand&.active?
demand.defer!
restore_capacity!(CAPACITY_RESTORE * 0.5)
demand
end
|
#deferred_demands ⇒ Object
73
|
# File 'lib/legion/extensions/agentic/executive/triage/helpers/triage_engine.rb', line 73
def deferred_demands = @demands.values.select { |d| d.status == :deferred }
|
#demands_by_domain(domain:) ⇒ Object
79
80
81
|
# File 'lib/legion/extensions/agentic/executive/triage/helpers/triage_engine.rb', line 79
def demands_by_domain(domain:)
@demands.values.select { |d| d.domain == domain.to_sym }
end
|
#demands_by_severity(severity:) ⇒ Object
75
76
77
|
# File 'lib/legion/extensions/agentic/executive/triage/helpers/triage_engine.rb', line 75
def demands_by_severity(severity:)
@demands.values.select { |d| d.severity == severity.to_sym }
end
|
#drop_demand(demand_id:) ⇒ Object
56
57
58
59
60
61
62
63
|
# File 'lib/legion/extensions/agentic/executive/triage/helpers/triage_engine.rb', line 56
def drop_demand(demand_id:)
demand = @demands[demand_id]
return nil unless demand&.active?
demand.drop!
restore_capacity!(CAPACITY_RESTORE)
demand
end
|
#dropped_demands ⇒ Object
72
|
# File 'lib/legion/extensions/agentic/executive/triage/helpers/triage_engine.rb', line 72
def dropped_demands = @demands.values.select { |d| d.status == :dropped }
|
#next_demand ⇒ Object
65
66
67
|
# File 'lib/legion/extensions/agentic/executive/triage/helpers/triage_engine.rb', line 65
def next_demand
active_demands.max_by(&:triage_score)
end
|
#overloaded? ⇒ Boolean
83
84
85
|
# File 'lib/legion/extensions/agentic/executive/triage/helpers/triage_engine.rb', line 83
def overloaded?
@capacity <= OVERLOAD_THRESHOLD
end
|
#process_demand(demand_id:) ⇒ Object
30
31
32
33
34
35
36
|
# File 'lib/legion/extensions/agentic/executive/triage/helpers/triage_engine.rb', line 30
def process_demand(demand_id:)
demand = @demands[demand_id]
return nil unless demand&.active?
demand.process!
demand
end
|
#queue_label ⇒ Object
94
|
# File 'lib/legion/extensions/agentic/executive/triage/helpers/triage_engine.rb', line 94
def queue_label = Constants.label_for(QUEUE_LABELS, queue_pressure)
|
#queue_pressure ⇒ Object
87
88
89
90
91
|
# File 'lib/legion/extensions/agentic/executive/triage/helpers/triage_engine.rb', line 87
def queue_pressure
return 0.0 if @demands.empty?
(active_demands.size.to_f / MAX_QUEUE_SIZE).clamp(0.0, 1.0).round(10)
end
|
#red_demands ⇒ Object
70
|
# File 'lib/legion/extensions/agentic/executive/triage/helpers/triage_engine.rb', line 70
def red_demands = @demands.values.select(&:red?)
|
#restore_capacity!(amount = CAPACITY_RESTORE) ⇒ Object
96
97
98
99
|
# File 'lib/legion/extensions/agentic/executive/triage/helpers/triage_engine.rb', line 96
def restore_capacity!(amount = CAPACITY_RESTORE)
@capacity = (@capacity + amount).clamp(0.0, 1.0).round(10)
self
end
|
#to_h ⇒ Object
118
119
120
121
122
123
124
125
|
# File 'lib/legion/extensions/agentic/executive/triage/helpers/triage_engine.rb', line 118
def to_h
{
total_demands: @demands.size,
active: active_demands.size,
capacity: @capacity,
overloaded: overloaded?
}
end
|
#triage_report ⇒ Object
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
|
# File 'lib/legion/extensions/agentic/executive/triage/helpers/triage_engine.rb', line 101
def triage_report
{
total_demands: @demands.size,
active_count: active_demands.size,
red_count: red_demands.size,
completed: completed_demands.size,
dropped: dropped_demands.size,
deferred: deferred_demands.size,
capacity: @capacity,
capacity_label: capacity_label,
overloaded: overloaded?,
queue_pressure: queue_pressure,
queue_label: queue_label,
next_demand: next_demand&.to_h
}
end
|