feat(agent): show post-compaction context usage - #6239
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.
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. |
teknium1
left a comment
There was a problem hiding this comment.
Thanks for targeting a real usability gap: current main still prints only compacting context… in the normal automatic path (agent/conversation_loop.py:4769-4777).
Problems
- The PR's
_before_tokens = approx_tokens or 0(run_agent.py:5844on PR head) produces a truthy stats payload even when the input estimate is unknown. The formatter then displays an invalid0 → Nresult rather than skipping it. - The active loop was extracted by
053025238intoagent/conversation_loop.py; the PR'srun_agent.pycall-site changes no longer cover current automatic compaction paths. Current preflight compaction is also inagent/turn_context.py:436.
Suggested changes
- Salvage the feature onto the current loop/turn-context call sites and preserve unknown token counts instead of coercing them to zero.
- Reuse the existing manual-feedback semantics in
agent/manual_compression_feedback.py, and distinguish approximate post-compression estimates from provider-reported usage (agent/conversation_compression.py:952-963). - Add focused tests for automatic success, no-op/unknown estimates, and gateway status delivery.
Automated hermes-sweeper review.
| before_messages, after_messages (or None if compression didn't run). | ||
| """ | ||
| _pre_msg_count = len(messages) | ||
| _before_tokens = approx_tokens or 0 |
There was a problem hiding this comment.
approx_tokens can be absent/zero when compaction was triggered from a rough fallback, but this turns it into a displayed 0 while _stats remains truthy. Preserve an unknown value and skip the token-result display, or compute a real before estimate before emitting feedback.
- chat_completion_helpers.py: add provider-level retry for silent failures - module-level constants: HERMES_PROVIDER_RETRY_* (max_attempts=3, base_delay=1s, max_delay=30s, backoff=2.0, jitter=0.2) - _is_silent_provider_failure() detects empty responses (no content, tool_calls, reasoning) - _provider_retry_backoff() exponential backoff with ±20% jitter - interruptible_api_call() wrapped in while True with per-attempt state isolation - silent failure check BEFORE error raise with interrupt-safe 100ms backoff wait - continues retry on silent failure, returns on success, raises on exhausted retries - agent_init.py: snapshot primary model/provider before first fallback swap enables UI to show 'Fallback: X (primary: Y)' Follows PR NousResearch#6239 architecture: provider-call level retry (not whole-turn), emission guard, cancellation-safe, no double-emit, NousResearch#4729 flush preserved. All 38 streaming tests pass including new silent retry tests.
|
The visibility this PR targeted has landed via PR #70457: with This branch predates the run_agent.py modularization and the status-template system (#69550), so the mechanism couldn't be cherry-picked — the completion notice now rides the existing COMPACTION_DONE_STATUS lifecycle edge instead of new emit sites. Closing with credit. |
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