Files
hermes-agent/tests
teknium1 885c5dc5e6 feat: context window usage warnings at 80% and 95%
Adds one-time warnings when context usage crosses critical thresholds:
- 80%: suggests /compress or /new if responses degrade
- 95%: warns of imminent errors/truncation, suggests /new

Each threshold fires at most once per session to avoid spam.
Warnings show actual token counts and percentage. Suppressed for
subagents (delegate_depth > 0) where the user can't act on them.
Always shown in CLI mode regardless of quiet_mode setting.

Inspired by OpenCode PR #152 (context window warning).

Bug fix found during live testing:
- Anthropic prompt caching reports input tokens across three fields
  (input_tokens, cache_read_input_tokens, cache_creation_input_tokens).
  The existing code only counted input_tokens, causing the context
  compressor to see ~0 tokens when caching was active. Fixed by summing
  all three fields. This also fixes context % display in the status bar
  for Anthropic users.

Changes:
- agent/context_compressor.py: add check_context_warning() with
  _warned_80/_warned_95 state tracking
- run_agent.py: call check_context_warning() after each API response,
  fix Anthropic cached token counting
- tests/test_context_warning.py: 8 tests covering thresholds,
  one-shot behavior, escalation, edge cases

Live tested with:
- Nous Portal (chat_completions mode) ✔
- Anthropic direct (anthropic_messages mode) ✔
- Interactive CLI session ✔
2026-03-16 06:30:04 -07:00
..