Jason Woltje
d51b1bd749
feat(#151): Implement context compaction (TDD - GREEN phase)
Implement context compaction to free memory when agents reach 80% context usage.
Features:
- ContextCompactor class for handling compaction operations
- Generates summary prompt asking agent to summarize completed work
- Replaces conversation history with concise summary
- Measures context reduction before/after compaction
- Logs compaction metrics (tokens freed, reduction percentage)
- Integration with ContextMonitor via trigger_compaction() method
Implementation details:
- CompactionResult dataclass tracks before/after metrics
- Target: 40-50% context reduction when triggered at 80%
- Error handling for API failures
- Type-safe with mypy strict mode
- 100% test coverage for new code
Quality gates passed:
✅ Build (mypy): No type errors
✅ Lint (ruff): All checks passed
✅ Tests: 41/41 tests passing
✅ Coverage: 100% for context_compaction.py, 97% for context_monitor.py
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>