# 🚀 DOING: Report Agent — Deep Hermes Core Integration

## 📁 Files Involved
```
backend/agent/report_agent/hermes_bridge.py       ← 🆕 NEW — Adapter layer to Hermes core
backend/agent/report_agent/insights_adapter.py     ← 🆕 NEW — InsightsEngine adapted for Canifa
backend/agent/report_agent/error_recovery.py       ← 🆕 NEW — ErrorClassifier-based self-healing
backend/agent/report_agent/context_manager.py      ← 🆕 NEW — ContextCompressor-based token mgmt
backend/agent/report_agent/session_tracker.py      ← 🆕 NEW — SessionDB-based report lifecycle
backend/agent/report_agent/autonomous_loop.py      ← 🆕 NEW — Curator-pattern background loop
backend/agent/report_agent/scheduler.py            ← MODIFY — Multi-job cron registration
backend/agent/report_agent/main_graph.py           ← MODIFY — Wire error_recovery + context_manager
backend/agent/report_agent/core.py                 ← MODIFY — Add self-healing LLM calls
verify_agents.py                                   ← MODIFY — Add new test suites 8-13
```

## 📌 Context
- **Status:** ✅ COMPLETE | **Priority:** P0
- **Worktree:** `worktrees/epic-22-agent-vision`
- **Hermes Source:** `hermes-agent-repo/` (reference, copy + adapt)

## 📋 Execution Checklist

### Phase 1: Hermes Bridge Layer (~15m)
- [x] Task 1.1: Create `hermes_bridge.py` — FailoverReason enum, ClassifiedError, classify_error, ReportSessionDB

### Phase 2: InsightsEngine Adapter (~15m)
- [x] Task 2.1: Create `insights_adapter.py` — Session analytics with generate(), format_summary()

### Phase 3: Error Recovery Pipeline (~10m)
- [x] Task 3.1: Create `error_recovery.py` — with_recovery() async retry with backoff/compression

### Phase 4: Context Manager (~10m)
- [x] Task 4.1: Create `context_manager.py` — Token-aware compression for SQL/tool results

### Phase 5: Session Tracker (~10m)
- [x] Task 5.1: Create `session_tracker.py` — Full lifecycle tracking with metrics

### Phase 6: Autonomous Loop (~15m)
- [x] Task 6.1: Create `autonomous_loop.py` — Curator-pattern with cron suggestions

### Phase 7: Upgrade Scheduler (~10m)
- [x] Task 7.1: Enhanced scheduler with 4 jobs (sales, insights, trends, watchdog)

### Phase 8: Wire Into Main Graph (~10m)
- [x] Task 8.1: Integrated session_tracker, error_recovery, context_manager into main_graph.py

### Phase 9: Verification (~10m)
- [x] Task 9.1: Added test suites 8-13 to verify_agents.py
- [x] Task 9.2: Run full verify_agents.py — 52 PASS, 0 FAIL, 1 SKIP
- [x] Task 9.3: Import chain — all 14 modules clean (0 circular imports)

## ✅ Completion Gate
- [x] All [x] — 9 phases complete
- [x] `verify_agents.py` — 0 FAIL, 52 PASS
- [x] Import chain — no circular imports
- [x] All 6 new files created and functional
- [x] Scheduler registers 4 cron jobs (sales, insights, trends, watchdog)
- [x] Error recovery handles 12 FailoverReason types
---
_Started: 2025-05-10 | Completed: 2025-05-10_
