Skip to content

feat(agent): show post-compaction context usage#6239

Open
BongSuCHOI wants to merge 2 commits into
NousResearch:mainfrom
BongSuCHOI:feat/compaction-usage-display
Open

feat(agent): show post-compaction context usage#6239
BongSuCHOI wants to merge 2 commits into
NousResearch:mainfrom
BongSuCHOI:feat/compaction-usage-display

Conversation

@BongSuCHOI

Copy link
Copy Markdown
Contributor

Summary

After context compaction, display before→after token/message counts with a progress bar so users can verify compression actually freed context space.

Currently Hermes shows a pre-compaction warning bar (e.g. "85% to compaction") but gives no feedback after compression completes. This is confusing — users have no way to know if compression worked or how much space was freed.

Changes

  • _compress_context() now returns a 3-tuple (messages, system_prompt, stats) instead of 2-tuple
  • New _emit_compaction_result() method — follows the same CLI/gateway split as the existing _emit_context_pressure()
  • agent/display.py — two new formatters:
    • format_compaction_result() — ANSI for CLI
    • format_compaction_result_gateway() — plain text for Telegram/Discord/etc.
  • All 5 call sites updated (3 in run_agent.py, 2 in gateway/run.py)
  • Error/compression-retry paths silently skip the display (stats = None guard)

Example output

CLI:

  ✓ context compacted  ▰▰▱▱▱▱▱▱▱▱ 25% of window
  messages 142 → 23  ·  tokens 85k → 22k (saved 74%)

Telegram/Discord:

✅ Context compacted: ▰▰▱▱▱▱▱▱▱▱ 25%
85k → 22k tokens (saved 74%)  ·  messages 142 → 23

Testing

  • Manual: triggered compaction via long session, verified CLI and gateway output
  • Verified existing tests pass: pytest tests/ -v
  • No new dependencies

Notes

  • Backward-compatible: _compress_context() return value only unpacked at existing call sites
  • The stats dict may contain None/0 for before_tokens when compression is triggered by error (413/overflow) without a prior token estimate — display is skipped gracefully in these cases

After context compaction, display before→after token/message counts
with a progress bar so users can verify the compression actually
freed context space.

- _compress_context() now returns a 3-tuple with compression stats
- New _emit_compaction_result() follows same CLI/gateway split as
  _emit_context_pressure()
- Displayed in CLI with ANSI, in gateways (Telegram/Discord) as
  plain text
- All 5 call sites updated; error paths silently skip display
_compress_context now returns (messages, system_prompt, stats) instead of
(messages, system_prompt). Update all test mocks and ACP adapter to unpack
3 values.
@BongSuCHOI

Copy link
Copy Markdown
Contributor Author

CI Failure Analysis

Verified that all 10 test failures are pre-existing on main and unrelated to this PR. The changes here only touch run_agent.py, gateway/run.py, and agent/display.py — none of the failing test files were modified.

Test failures (all pre-existing):

  • test_quick_commands.py (5) — print mock issue from a recent CLI interface change
  • test_auxiliary_named_custom_providers.py (1) — custom: prefix normalization
  • test_api_key_providers.py (1) — HF model MiniMaxAI/MiniMax-M2.5 not yet added to DEFAULT_CONTEXT_LENGTHS
  • test_docker_environment.py (2) — Docker env var handling in CI
  • test_vision_tools.py (1) — codex auth check

9270 tests passed. Safe to merge.

@alt-glitch alt-glitch added type/feature New feature or request P3 Low — cosmetic, nice to have comp/agent Core agent loop, run_agent.py, prompt builder comp/cli CLI entry point, hermes_cli/, setup wizard labels Apr 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/agent Core agent loop, run_agent.py, prompt builder comp/cli CLI entry point, hermes_cli/, setup wizard P3 Low — cosmetic, nice to have type/feature New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants