fix: Truncate AI reply to 200 chars in memory extraction to prevent doc pollution

The AI reply often contains full document content (passport details, etc.)
which the memory extraction LLM incorrectly stores as user facts. Limiting
to 200 chars avoids including document content while keeping the gist.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Christian Gick
2026-03-05 15:47:23 +02:00
parent f1529013ca
commit 6fb8c33057

3
bot.py
View File

@@ -1396,7 +1396,8 @@ class Bot:
{"role": "user", "content": ( {"role": "user", "content": (
f"Existing memories:\n{existing_text}\n\n" f"Existing memories:\n{existing_text}\n\n"
f"User message: {user_message[:500]}\n" f"User message: {user_message[:500]}\n"
f"AI reply: {ai_reply[:500]}\n\n" # Only include first 200 chars of AI reply to avoid document content pollution
f"AI reply (summary only): {ai_reply[:200]}\n\n"
"New facts to remember (JSON array of strings):" "New facts to remember (JSON array of strings):"
)}, )},
], ],