From b6cdea73293e77c9d473be097fa52c46d496a041 Mon Sep 17 00:00:00 2001 From: AJ Isaacs Date: Mon, 23 Feb 2026 09:59:51 -0500 Subject: [PATCH] Include replied-to message text in LLM context When a user replies to the bot's message, the original bot message text is now included in the context sent to the LLM. This prevents the LLM from misinterpreting follow-up questions like "what does this even mean?" since it can see what message is being referenced. Co-Authored-By: Claude Opus 4.6 --- cogs/chat.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/cogs/chat.py b/cogs/chat.py index 2f03f48..598f82f 100644 --- a/cogs/chat.py +++ b/cogs/chat.py @@ -48,6 +48,7 @@ class ChatCog(commands.Cog): should_reply = False is_proactive = False + reply_context = "" # Text of the message being replied to # Check if bot is @mentioned if self.bot.user in message.mentions: @@ -63,6 +64,8 @@ class ChatCog(commands.Cog): ) if ref_msg.author.id == self.bot.user.id: should_reply = True + if ref_msg.content: + reply_context = f"[Replying to bot's message: {ref_msg.content[:300]}]\n" except discord.HTTPException: pass @@ -143,7 +146,7 @@ class ChatCog(commands.Cog): score_context = f"[Server context: {message.author.display_name} — {', '.join(context_parts)}]" self._chat_history[ch_id].append( - {"role": "user", "content": f"{score_context}\n{message.author.display_name}: {content}"} + {"role": "user", "content": f"{score_context}\n{reply_context}{message.author.display_name}: {content}"} ) active_prompt = self._get_active_prompt()