From 1b05c8311e6f77e8f905b6e63436334921afbce1 Mon Sep 17 00:00:00 2001 From: AllfatherHatt Date: Fri, 21 Feb 2025 01:36:38 +0100 Subject: [PATCH] Add 10 message min --- reginaldCog/reginald.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/reginaldCog/reginald.py b/reginaldCog/reginald.py index 1adde44..add452f 100644 --- a/reginaldCog/reginald.py +++ b/reginaldCog/reginald.py @@ -101,6 +101,9 @@ class ReginaldCog(commands.Cog): memory.append({"user": user_name, "content": prompt}) memory.append({"user": "Reginald", "content": response_text}) + # ✅ Ensure a minimum of 10 short-term messages are always retained + MINIMUM_SHORT_TERM_MESSAGES = 10 + # ✅ Check if pruning is needed if len(memory) > self.short_term_memory_limit: @@ -121,10 +124,11 @@ class ReginaldCog(commands.Cog): if len(mid_memory[channel_id]) > 10: mid_memory[channel_id].pop(0) - # ✅ Only prune short-term memory if a new summary was made - retention_ratio = 0.25 # Keep 25% of messages for immediate continuity - keep_count = max(1, int(len(memory) * retention_ratio)) # Keep at least 1 message - memory = memory[-keep_count:] # Remove oldest 75%, keep recent + # ✅ Ensure at least 10 short-term messages remain after pruning + retention_ratio = 0.25 # Default: Keep 25% of messages for continuity + keep_count = max(MINIMUM_SHORT_TERM_MESSAGES, int(len(memory) * retention_ratio)) + + memory = memory[-keep_count:] # Remove oldest messages but keep at least 10 # ✅ Store updated short-term memory back short_memory[channel_id] = memory