[claude] feat: Agent Energy Budget Monitoring (#1009) #1267
Reference in New Issue
Block a user
Delete Branch "claude/issue-1009"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Fixes #1009
Summary
infrastructure/energy/monitor.py—EnergyBudgetMonitorsingleton that estimates power draw via three strategies (battery discharge viaioreg, CPU utilisation proxy viatop, model-size heuristic), tracks per-inference efficiency scored 0–10, and auto-engages Low Power Mode when watts exceed the configurable thresholddashboard/routes/energy.py— REST API:GET /energy/status,GET /energy/report,POST /energy/low-power,POST /energy/recordenergy_budget_enabled,energy_budget_watts_threshold(default 15W),energy_low_power_model(defaultqwen3:1b)Design
Power estimation tries three strategies in order:
ioreg -r -c AppleSmartBattery) — accurate, works on macOS without sudo, only when on batterytop) — scales against M3 Max 40W TDPAll subprocess calls are wrapped in
asyncio.to_thread()and results cached for 10s.- Add `infrastructure/energy/monitor.py` with `EnergyBudgetMonitor`: - Estimates power draw via three strategies: battery discharge (ioreg), CPU utilisation proxy (top), or model-size heuristic - Tracks per-inference efficiency (tok/s per watt), scored 0–10 - Rolling window of 60 inference samples - Auto-engages Low Power Mode when watts exceed threshold - Low Power Mode advises routing to a compact model (energy_low_power_model) - Add `dashboard/routes/energy.py` with REST endpoints: - GET /energy/status — current power, efficiency score, samples - GET /energy/report — full sample history - POST /energy/low-power — toggle low power mode - POST /energy/record — record an inference event - Add config settings: energy_budget_enabled, energy_budget_watts_threshold, energy_low_power_model - Add 26 unit tests covering all estimation strategies and edge cases Fixes #1009 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>