hermes-agent/gateway
teknium1 c7b6f423c7 feat: auto-compress pathologically large gateway sessions (#628)
Long-lived gateway sessions can accumulate enough history that every new
message rehydrates an oversized transcript, causing repeated truncation
failures (finish_reason=length).

Add a session hygiene check in _handle_message that runs right after
loading the transcript and before invoking the agent:

1. Estimate message count and rough token count of the transcript
2. If above configurable thresholds (default: 200 msgs or 100K tokens),
   auto-compress the transcript proactively
3. Notify the user about the compression with before/after stats
4. If still above warn threshold (default: 200K tokens) after
   compression, suggest /reset
5. If compression fails on a dangerously large session, warn the user
   to use /compress or /reset manually

Thresholds are configurable via config.yaml:

  session_hygiene:
    auto_compress_tokens: 100000
    auto_compress_messages: 200
    warn_tokens: 200000

This complements the agent's existing preflight compression (which
runs inside run_conversation) by catching pathological sessions at
the gateway layer before the agent is even created.

Includes 12 tests for threshold detection and token estimation.
2026-03-07 20:09:48 -08:00
..
platforms fix: strip MarkdownV2 escapes from Telegram plaintext fallback 2026-03-07 01:23:18 -08:00
__init__.py Enhance CLI with multi-platform messaging integration and configuration management 2026-02-02 19:01:51 -08:00
channel_directory.py feat: implement channel directory and message mirroring for cross-platform communication 2026-02-22 20:44:15 -08:00
config.py feat: add Home Assistant integration (REST tools + WebSocket gateway) 2026-02-28 13:32:48 +03:00
delivery.py Hermes Agent UX Improvements 2026-02-22 02:16:11 -08:00
hooks.py Add messaging platform enhancements: STT, stickers, Discord UX, Slack, pairing, hooks 2026-02-15 21:38:59 -08:00
mirror.py feat: implement channel directory and message mirroring for cross-platform communication 2026-02-22 20:44:15 -08:00
pairing.py Add messaging platform enhancements: STT, stickers, Discord UX, Slack, pairing, hooks 2026-02-15 21:38:59 -08:00
run.py feat: auto-compress pathologically large gateway sessions (#628) 2026-03-07 20:09:48 -08:00
session.py feat(gateway): proactive async memory flush on session expiry 2026-03-07 11:27:50 -08:00
status.py fix: prevent duplicate gateway instances from running simultaneously 2026-03-05 20:35:33 -08:00
sticker_cache.py Add messaging platform enhancements: STT, stickers, Discord UX, Slack, pairing, hooks 2026-02-15 21:38:59 -08:00