diff --git a/homelab-ai-bot/llm.py b/homelab-ai-bot/llm.py index d3a86e09..4f51676f 100644 --- a/homelab-ai-bot/llm.py +++ b/homelab-ai-bot/llm.py @@ -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