feat(gateway): notify user when context is auto-compressed - #16469
feat(gateway): notify user when context is auto-compressed#16469Grey0202 wants to merge 1 commit into
Conversation
When the agent's context_compressor cuts a long conversation and returns under a fresh session_id, the user has no signal that this happened — the next reply they receive is in a session whose history has been summarised. This sends an opt-in heads-up message to the originating chat, gated by config.compression.notify (default false), with a customisable config.compression.notify_message. Send is wrapped in try/except so a failed notification never breaks the agent reply. Co-Authored-By: Claude <noreply@anthropic.com>
a143610 to
dc6c8ac
Compare
teknium1
left a comment
There was a problem hiding this comment.
Thanks for addressing the confusing silent-compaction experience. The underlying user-visible gap still exists on current main, but this implementation no longer reaches the default compaction path.
Problems
compression.in_placenow defaults toTrue(hermes_cli/config.py:1463), and in-place compaction keeps the session ID (agent/conversation_compression.py:500-505). The added session-ID-difference guard therefore does not fire for default compactions.- Main already emits
COMPACTION_STATUSbefore compression (agent/conversation_compression.py:516), but the gateway suppresses that exact message in_TELEGRAM_NOISY_STATUS_RE(gateway/run.py:82) before adapter delivery (gateway/run.py:453-454).
Suggested changes
- Repair the status-filter path rather than send a separate post-rotation message. This preserves the active-run, thread-metadata, and adapter status-update behavior in
gateway/run.py:17812-17833. - Update
tests/gateway/test_telegram_noise_filter.py; it currently asserts the compaction status is noisy (:33,:46). The cross-referenced #40378 contains the same focused filter/test direction.
Automated hermes-sweeper review.
| # session_entry so transcript writes below go to the right session. | ||
| if agent_result.get("session_id") and agent_result["session_id"] != session_entry.session_id: | ||
| session_entry.session_id = agent_result["session_id"] | ||
| # Send compression notification if configured |
There was a problem hiding this comment.
This notification is gated on session-ID rotation, but current main defaults compression.in_place to true (hermes_cli/config.py:1463), which compacts without changing the ID. The default path therefore never reaches this block; allow the existing compaction lifecycle status through the gateway status filter instead.
|
The opt-in compression notice this PR pioneered has landed via PR #70457 ( This branch's mechanism couldn't be salvaged directly: it fires on session_id change, which the in-place compaction default (2107b86) no longer produces, and the notification text needs to flow through the status-template system (#69550) rather than a hardcoded string. The landed gate covers the use case. Closing with credit. |
Summary
When the agent's
context_compressorcuts a long conversation and continues under a freshsession_id, the user has no signal that this happened — the next reply they receive is in a session whose history has been summarised, which can be confusing if they reference earlier turns.This adds an opt-in notification: when
GatewayRunnerobserves that an agent result returned a differentsession_idthan the entry it was launched with (the existing trigger for switching the gateway's session pointer), it sends one small message to the originating chat informing the user that the context has been compressed.Behavior
config.compression.notify(defaultfalse).config.compression.notify_messageoverrides the default text. The default included is intentionally short so it works on bandwidth-constrained channels (SMS, telegram).try/except; a failed notification logs at debug level and does not affect the agent reply that follows.Example config
Test plan
python -m py_compile gateway/run.pypassesnotify: true, exercising compression on a real chat sends one notification message before the next agent replynotify: false(default), behavior is identical to todayNotes
The compression event is detected the same way the surrounding code already detects it (the
agent_result["session_id"] != session_entry.session_idcomparison just above). No new state is introduced.