aws-samples / aws-samples/sample-agent-greenhouse
Remove or reactivate deprecated CompactionHook (dead code still wired into lifecycle)
- Dominant language
- Python
- Stars
- 21
- Forks
- 5
- PR merge metrics
- No merged PRs in 30d
Description
## Problem
`src/platform_agent/foundation/hooks/compaction_hook.py` contains a detailed 9-section compaction prompt template, but the `on_before_invocation` method **only logs a warning and does nothing**. The hook is marked as "retained for backward compatibility" yet it is still registered in the agent's hook chain during construction.
This creates several issues:
1. **False sense of security** — users may believe conversation compaction is active
2. **Dead code in the critical path** — the hook runs on every invocation but does nothing useful
3. **Confusion for contributors** — the 9-section prompt template suggests active functionality
## Proposed Solution
**Option A (Preferred): Remove from default hook chain**
- Remove `CompactionHook` from the default hooks loaded in `FoundationAgent`
- Keep the module as a reference implementation with clear documentation
- Add a note in ARCHITECTURE.md explaining that compaction is now handled by [mechanism X]
**Option B: Reactivate**
- If Strands SDK doesn't handle compaction natively, re-enable the `on_before_invocation` logic
- The existing 9-section format (system context, skill state, task description, decisions, file modifications, user messages, recent actions, blockers, next steps) is well-designed and worth preserving
## Context
The 9-section structured compaction format includes an "IRON RULE" to preserve verbatim user input, which is a good practice. If reactivated, the compaction threshold constants should be configurable via the harness:
- `_DEFAULT_TOKEN_THRESHOLD = 80000`
- `MAX_COMPACTION_TOKENS = 20000`
- `SYSTEM_PROMPT_TOKEN_RESERVE = 15000`
## Acceptance Criteria
- [ ] CompactionHook is either removed from the default hook chain or reactivated
- [ ] If removed: ARCHITECTURE.md documents what handles compaction instead
- [ ] If reactivated: thresholds are configurable via `DomainHarness`
- [ ] No dead code remains in the active hook chain
Contributor guide
Research direction
Start with src/platform_agent/foundation/hooks/compaction_hook.py and the FoundationAgent construction path to trace how CompactionHook enters the default hook chain. Read ARCHITECTURE.md and the DomainHarness context before choosing removal or reactivation; done means the hook is no longer dead in the active chain and the relevant documentation or configurable thresholds are addressed.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- ai, backend
- Issue type
- Refactor
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100