Hausmeister: Filter Recap-Meta-Fragen aus LLM-History (Anti-Poisoning)

This commit is contained in:
root 2026-03-15 12:44:39 +07:00
parent 7a30793d44
commit ef33d23158

View file

@ -392,13 +392,32 @@ def ask_with_tools(question: str, tool_handlers: dict, session_id: str = None) -
{"role": "system", "content": SYSTEM_PROMPT + memory_block},
]
_RECAP_MARKERS = ["was haben wir", "worüber haben wir", "worüber hatten wir",
"worueber haben wir", "was hatten wir besprochen", "was war heute thema"]
def _is_recap(text):
t = text.lower()
return any(m in t for m in _RECAP_MARKERS)
if session_id:
try:
import memory_client
history = memory_client.get_session_messages(session_id, limit=10)
skip_next_assistant = False
for msg in history:
if msg.get("role") in ("user", "assistant") and msg.get("content"):
messages.append({"role": msg["role"], "content": msg["content"]})
role = msg.get("role", "")
content = msg.get("content", "")
if not content:
continue
if role == "user" and _is_recap(content):
skip_next_assistant = True
continue
if role == "assistant" and skip_next_assistant:
skip_next_assistant = False
continue
skip_next_assistant = False
if role in ("user", "assistant"):
messages.append({"role": role, "content": content})
except Exception:
pass