From bb3b033b57af1a0685dfd1b355b499391559ecee Mon Sep 17 00:00:00 2001 From: m3taversal Date: Tue, 24 Mar 2026 14:54:36 +0000 Subject: [PATCH] =?UTF-8?q?fix:=20separate=20history=20caps=20=E2=80=94=20?= =?UTF-8?q?chat-level=2010,=20per-user=205=20(Ganymede=20review)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Group chats with 3 users contributing 2 messages each = 6 exchanges, exceeding the old shared cap of 5. Chat-level now holds 10 exchanges (~2K extra tokens, within prompt budget). Pentagon-Agent: Epimetheus <3D35839A-7722-4740-B93D-51157F7D5E70> --- telegram/bot.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/telegram/bot.py b/telegram/bot.py index 67f2e75..a7483b5 100644 --- a/telegram/bot.py +++ b/telegram/bot.py @@ -100,7 +100,8 @@ CONVERSATION_WINDOW = 5 # expire after 5 unanswered messages unanswered_count: dict[tuple[int, int], int] = {} # (chat_id, user_id) → unanswered count # Conversation history — last N exchanges for prompt context (Ganymede: high-value change) -MAX_HISTORY = 5 +MAX_HISTORY_USER = 5 +MAX_HISTORY_CHAT = 10 # Ganymede: group chats need more context (multiple users) conversation_history: dict[tuple[int, int], list[dict]] = {} # (chat_id, user_id) → [{user, bot}] @@ -694,13 +695,13 @@ IMPORTANT: Two special tags you can append at the end of your response (after yo # Per-user history history = conversation_history.setdefault(key, []) history.append(entry) - if len(history) > MAX_HISTORY: + if len(history) > MAX_HISTORY_USER: history.pop(0) # Chat-level history (group context — all users visible) chat_key = (msg.chat_id, 0) chat_history = conversation_history.setdefault(chat_key, []) chat_history.append(entry) - if len(chat_history) > MAX_HISTORY: + if len(chat_history) > MAX_HISTORY_CHAT: chat_history.pop(0) # Record rate limit