feat(agent): show post-compaction context usage#6239
Open
BongSuCHOI wants to merge 2 commits into
Open
Conversation
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.
Contributor
Author
CI Failure AnalysisVerified 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):
9270 tests passed. Safe to merge. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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_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 CLIformat_compaction_result_gateway()— plain text for Telegram/Discord/etc.run_agent.py, 2 ingateway/run.py)Example output
CLI:
Telegram/Discord:
Testing
pytest tests/ -vNotes
_compress_context()return value only unpacked at existing call sitesstatsdict may containNone/0forbefore_tokenswhen compression is triggered by error (413/overflow) without a prior token estimate — display is skipped gracefully in these cases