Module: Legion::Extensions::Agentic::Attention::Economy::Runners::AttentionEconomy

Includes:
Helpers::Lex
Included in:
Client
Defined in:
lib/legion/extensions/agentic/attention/economy/runners/attention_economy.rb

Instance Method Summary collapse

Instance Method Details

#add_demand(label:, demand_type:, priority:, cost:, roi: 0.5) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/legion/extensions/agentic/attention/economy/runners/attention_economy.rb', line 13

def add_demand(label:, demand_type:, priority:, cost:, roi: 0.5, **)
  d = attention_budget.create_demand(
    label:       label,
    demand_type: demand_type,
    priority:    priority,
    cost:        cost,
    roi:         roi
  )
  log.info("[attention] demand added: id=#{d.id} label=#{label} priority=#{priority} cost=#{cost}")
  { created: true, demand: d.to_h }
rescue ArgumentError => e
  log.warn("[attention] add_demand failed: #{e.message}")
  { created: false, reason: e.message }
end

#allocate_demand(demand_id:, amount: nil) ⇒ Object



28
29
30
31
32
33
34
35
36
# File 'lib/legion/extensions/agentic/attention/economy/runners/attention_economy.rb', line 28

def allocate_demand(demand_id:, amount: nil, **)
  result = attention_budget.allocate(demand_id: demand_id, amount: amount)
  if result[:allocated]
    log.info("[attention] allocated: demand_id=#{demand_id} amount=#{result[:amount]} remaining=#{result[:remaining]}")
  else
    log.debug("[attention] allocation failed: demand_id=#{demand_id} reason=#{result[:reason]}")
  end
  result
end

#attention_snapshotObject



75
76
77
# File 'lib/legion/extensions/agentic/attention/economy/runners/attention_economy.rb', line 75

def attention_snapshot(**)
  attention_budget.to_h
end

#attention_statusObject



69
70
71
72
73
# File 'lib/legion/extensions/agentic/attention/economy/runners/attention_economy.rb', line 69

def attention_status(**)
  report = attention_budget.budget_report
  log.debug("[attention] status: utilization=#{report[:utilization]} demands=#{report[:demand_count]}")
  report
end

#best_roi_demands(limit: 5) ⇒ Object



57
58
59
60
61
# File 'lib/legion/extensions/agentic/attention/economy/runners/attention_economy.rb', line 57

def best_roi_demands(limit: 5, **)
  demands = attention_budget.best_roi(limit: limit)
  log.debug("[attention] best_roi: limit=#{limit} count=#{demands.size}")
  { demands: demands.map(&:to_h), count: demands.size }
end

#deallocate_demand(demand_id:) ⇒ Object



38
39
40
41
42
# File 'lib/legion/extensions/agentic/attention/economy/runners/attention_economy.rb', line 38

def deallocate_demand(demand_id:, **)
  result = attention_budget.deallocate(demand_id: demand_id)
  log.debug("[attention] deallocated: demand_id=#{demand_id} freed=#{result[:freed]}")
  result
end

#prioritized_demandsObject



51
52
53
54
55
# File 'lib/legion/extensions/agentic/attention/economy/runners/attention_economy.rb', line 51

def prioritized_demands(**)
  demands = attention_budget.prioritized_demands
  log.debug("[attention] prioritized_demands: count=#{demands.size}")
  { demands: demands.map(&:to_h), count: demands.size }
end

#rebalance_budgetObject



63
64
65
66
67
# File 'lib/legion/extensions/agentic/attention/economy/runners/attention_economy.rb', line 63

def rebalance_budget(**)
  result = attention_budget.rebalance
  log.info("[attention] rebalance: freed=#{result[:rebalanced]} spent=#{result[:spent]}")
  result
end

#recover_budget(amount: nil) ⇒ Object



44
45
46
47
48
49
# File 'lib/legion/extensions/agentic/attention/economy/runners/attention_economy.rb', line 44

def recover_budget(amount: nil, **)
  opts   = amount ? { amount: amount } : {}
  result = attention_budget.recover!(**opts)
  log.debug("[attention] recovery: delta=#{result[:recovered]} spent=#{result[:spent]}")
  result
end