fix: separate history caps — chat-level 10, per-user 5 (Ganymede review)
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>
This commit is contained in:
parent
60c92d5c19
commit
bb3b033b57
1 changed files with 4 additions and 3 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in a new issue