Compare commits
2 Commits
1f2c687ccd
...
bc815e67c8
| Author | SHA1 | Date | |
|---|---|---|---|
| bc815e67c8 | |||
| 344043b081 |
+5
-1
@@ -1445,7 +1445,11 @@ class RocketChatAdapter(BasePlatformAdapter):
|
|||||||
decision.stay_in_room = True
|
decision.stay_in_room = True
|
||||||
decision.move_request_sent = False
|
decision.move_request_sent = False
|
||||||
# ── Archivar-Kontext-Weitergabe: Zielraum + Frage-Nr ──────
|
# ── Archivar-Kontext-Weitergabe: Zielraum + Frage-Nr ──────
|
||||||
if hasattr(decision, 'target_room') and decision.target_room:
|
# P0-BUGFIX: Nur setzen wenn NICHT stay_in_room.
|
||||||
|
# Bei stay_in_room=True (Meta-Fragen, Smalltalk, etc.)
|
||||||
|
# bleibt der Agent im Ursprungsraum — kein Zielraum nötig.
|
||||||
|
if (hasattr(decision, 'target_room') and decision.target_room
|
||||||
|
and not getattr(decision, 'stay_in_room', False)):
|
||||||
_THEMATIC_TARGET_ROOM.set(decision.target_room)
|
_THEMATIC_TARGET_ROOM.set(decision.target_room)
|
||||||
global _question_counter
|
global _question_counter
|
||||||
with _question_counter_lock:
|
with _question_counter_lock:
|
||||||
|
|||||||
@@ -122,7 +122,19 @@ _META_PATTERNS: List[re.Pattern] = [
|
|||||||
re.IGNORECASE),
|
re.IGNORECASE),
|
||||||
re.compile(r"warum\s+(?:wurde|ist)\s+(?:meine\s+)?(?:nachricht|frage)",
|
re.compile(r"warum\s+(?:wurde|ist)\s+(?:meine\s+)?(?:nachricht|frage)",
|
||||||
re.IGNORECASE),
|
re.IGNORECASE),
|
||||||
re.compile(r"(?:archivar|klassifi(?:zier|kation)|routing|weiterleitung)",
|
# P0-BUGFIX: Pattern 3 war zu aggressiv — matchte JEDES Vorkommen von
|
||||||
|
# 'archivar', auch in Sachfragen wie "Was hat der Archivar empfohlen?".
|
||||||
|
# Jetzt: 'archivar' nur in Kombination mit System-Operationsverben
|
||||||
|
# (klassifiziert, routet, leitet weiter, arbeitet, funktioniert, macht).
|
||||||
|
# Bidirektional: sowohl "Archivar klassifiziert" als auch
|
||||||
|
# "klassifiziert der Archivar".
|
||||||
|
# System-Begriffe ohne 'archivar' (klassifikation, routing, weiterleitung)
|
||||||
|
# sind weiterhin eigenständige Meta-Signale.
|
||||||
|
re.compile(r"archivar\s+(?:klassifiziert|routet|leitet\s+weiter|arbeitet|funktioniert|macht)",
|
||||||
|
re.IGNORECASE),
|
||||||
|
re.compile(r"(?:klassifiziert|routet|leitet\s+weiter|arbeitet|funktioniert|macht)\s+(?:der\s+)?archivar",
|
||||||
|
re.IGNORECASE),
|
||||||
|
re.compile(r"(?:klassifi(?:zier|kation)|routing|weiterleitung)",
|
||||||
re.IGNORECASE),
|
re.IGNORECASE),
|
||||||
re.compile(r"(?:was|wie)\s+(?:macht|arbeitet|funktioniert)\s+(?:der\s+)?archivar",
|
re.compile(r"(?:was|wie)\s+(?:macht|arbeitet|funktioniert)\s+(?:der\s+)?archivar",
|
||||||
re.IGNORECASE),
|
re.IGNORECASE),
|
||||||
@@ -510,9 +522,12 @@ class BidirectionalRouter:
|
|||||||
# ── Schritt 2: Meta-Fragen-Erkennung ──────────────────────────
|
# ── Schritt 2: Meta-Fragen-Erkennung ──────────────────────────
|
||||||
if self._is_meta_question(text):
|
if self._is_meta_question(text):
|
||||||
logger.info("Meta-question detected: %.80s...", text)
|
logger.info("Meta-question detected: %.80s...", text)
|
||||||
|
# P0-BUGFIX: target_room=origin_room_id statt catch_all_id,
|
||||||
|
# damit _THEMATIC_TARGET_ROOM im Adapter den korrekten Raum
|
||||||
|
# bekommt und der Agent nicht denkt, er sei im DM.
|
||||||
return RoutingDecision(
|
return RoutingDecision(
|
||||||
category="direct_question",
|
category="direct_question",
|
||||||
target_room=self._room_map.catch_all_room.room_id if self._room_map.catch_all_room else "",
|
target_room=origin_room_id,
|
||||||
confidence=1.0,
|
confidence=1.0,
|
||||||
is_meta=True,
|
is_meta=True,
|
||||||
delete_original=True,
|
delete_original=True,
|
||||||
|
|||||||
@@ -9,10 +9,12 @@ Prüft:
|
|||||||
|
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
|
import asyncio
|
||||||
import json
|
import json
|
||||||
import tempfile
|
import tempfile
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import List, Optional
|
from typing import List, Optional
|
||||||
|
from unittest.mock import AsyncMock, MagicMock
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
@@ -255,3 +257,268 @@ class TestNeverRouteThematic:
|
|||||||
assert room_name_to_topic("#DevOps") == "devops"
|
assert room_name_to_topic("#DevOps") == "devops"
|
||||||
# _room_name_to_topic stripped nur '#', nicht Whitespace
|
# _room_name_to_topic stripped nur '#', nicht Whitespace
|
||||||
assert room_name_to_topic("Mein Raum") == "mein-raum"
|
assert room_name_to_topic("Mein Raum") == "mein-raum"
|
||||||
|
|
||||||
|
|
||||||
|
# ── P0-BUGFIX: Meta-Patterns restriktiver ──────────────────────────────────
|
||||||
|
|
||||||
|
|
||||||
|
class TestMetaPatternsP0:
|
||||||
|
"""P0-BUGFIX: _META_PATTERNS dürfen nicht zu breit matchen.
|
||||||
|
|
||||||
|
Bug: Pattern 3 matchte JEDES Vorkommen von 'Archivar', auch in
|
||||||
|
Sachfragen wie 'Was hat der Archivar empfohlen?' → is_meta=True →
|
||||||
|
100%-Keyword-Match wurde nie geprüft.
|
||||||
|
|
||||||
|
Fix: 'archivar' nur in Kombination mit System-Operationsverben
|
||||||
|
(klassifiziert, routet, leitet weiter, arbeitet, funktioniert, macht).
|
||||||
|
"""
|
||||||
|
|
||||||
|
def test_archivar_allein_kein_meta(self):
|
||||||
|
"""'Archivar' als Fachbegriff in Sachfrage → KEIN Meta-Match."""
|
||||||
|
from plugin.archivar.router import BidirectionalRouter
|
||||||
|
|
||||||
|
# Der ursprüngliche Bug-Fall
|
||||||
|
assert not BidirectionalRouter._is_meta_question(
|
||||||
|
"Was hat der Archivar aufgrund des Keywords Rocketchat empfohlen?"
|
||||||
|
)
|
||||||
|
|
||||||
|
def test_archivar_mit_verb_ist_meta(self):
|
||||||
|
"""'Archivar klassifiziert' → Meta-Match."""
|
||||||
|
from plugin.archivar.router import BidirectionalRouter
|
||||||
|
|
||||||
|
assert BidirectionalRouter._is_meta_question(
|
||||||
|
"Wie klassifiziert der Archivar meine Nachricht?"
|
||||||
|
)
|
||||||
|
|
||||||
|
def test_archivar_routet_ist_meta(self):
|
||||||
|
"""'Archivar routet' → Meta-Match."""
|
||||||
|
from plugin.archivar.router import BidirectionalRouter
|
||||||
|
|
||||||
|
assert BidirectionalRouter._is_meta_question(
|
||||||
|
"Wohin routet der Archivar diese Frage?"
|
||||||
|
)
|
||||||
|
|
||||||
|
def test_archivar_funktioniert_ist_meta(self):
|
||||||
|
"""'Archivar funktioniert' → Meta-Match."""
|
||||||
|
from plugin.archivar.router import BidirectionalRouter
|
||||||
|
|
||||||
|
assert BidirectionalRouter._is_meta_question(
|
||||||
|
"Wie funktioniert der Archivar?"
|
||||||
|
)
|
||||||
|
|
||||||
|
def test_archivar_empfohlen_kein_meta(self):
|
||||||
|
"""'Archivar hat empfohlen' → KEIN Meta-Match (Sachfrage)."""
|
||||||
|
from plugin.archivar.router import BidirectionalRouter
|
||||||
|
|
||||||
|
assert not BidirectionalRouter._is_meta_question(
|
||||||
|
"Der Archivar hat empfohlen, das so zu machen"
|
||||||
|
)
|
||||||
|
|
||||||
|
def test_archivar_gesagt_kein_meta(self):
|
||||||
|
"""'Archivar hat gesagt' → KEIN Meta-Match (Sachfrage)."""
|
||||||
|
from plugin.archivar.router import BidirectionalRouter
|
||||||
|
|
||||||
|
assert not BidirectionalRouter._is_meta_question(
|
||||||
|
"Der Archivar hat gesagt, ich soll das hier dokumentieren"
|
||||||
|
)
|
||||||
|
|
||||||
|
def test_klassifikation_allein_ist_meta(self):
|
||||||
|
"""'Klassifikation' ohne 'archivar' → Meta-Match (eigenständiges Signal)."""
|
||||||
|
from plugin.archivar.router import BidirectionalRouter
|
||||||
|
|
||||||
|
assert BidirectionalRouter._is_meta_question(
|
||||||
|
"Warum wurde meine Nachricht so klassifiziert?"
|
||||||
|
)
|
||||||
|
|
||||||
|
def test_routing_allein_ist_meta(self):
|
||||||
|
"""'Routing' ohne 'archivar' → Meta-Match."""
|
||||||
|
from plugin.archivar.router import BidirectionalRouter
|
||||||
|
|
||||||
|
assert BidirectionalRouter._is_meta_question(
|
||||||
|
"Wie funktioniert das Routing hier?"
|
||||||
|
)
|
||||||
|
|
||||||
|
def test_weiterleitung_allein_ist_meta(self):
|
||||||
|
"""'Weiterleitung' ohne 'archivar' → Meta-Match."""
|
||||||
|
from plugin.archivar.router import BidirectionalRouter
|
||||||
|
|
||||||
|
assert BidirectionalRouter._is_meta_question(
|
||||||
|
"Kann ich die Weiterleitung beeinflussen?"
|
||||||
|
)
|
||||||
|
|
||||||
|
def test_wohin_wurde_ist_meta(self):
|
||||||
|
"""'Wohin wurde' → Meta-Match (Pattern 1)."""
|
||||||
|
from plugin.archivar.router import BidirectionalRouter
|
||||||
|
|
||||||
|
assert BidirectionalRouter._is_meta_question(
|
||||||
|
"Wohin wurde meine letzte Nachricht geroutet?"
|
||||||
|
)
|
||||||
|
|
||||||
|
def test_warum_ist_meine_nachricht_ist_meta(self):
|
||||||
|
"""'Warum ist meine Nachricht' → Meta-Match (Pattern 2)."""
|
||||||
|
from plugin.archivar.router import BidirectionalRouter
|
||||||
|
|
||||||
|
assert BidirectionalRouter._is_meta_question(
|
||||||
|
"Warum ist meine Nachricht im falschen Raum gelandet?"
|
||||||
|
)
|
||||||
|
|
||||||
|
def test_normale_frage_kein_meta(self):
|
||||||
|
"""Normale Sachfrage ohne System-Bezug → KEIN Meta-Match."""
|
||||||
|
from plugin.archivar.router import BidirectionalRouter
|
||||||
|
|
||||||
|
assert not BidirectionalRouter._is_meta_question(
|
||||||
|
"Wie konfiguriere ich den NGINX für HTTPS?"
|
||||||
|
)
|
||||||
|
|
||||||
|
def test_keyword_rocketchat_kein_meta(self):
|
||||||
|
"""Frage mit Keyword 'Rocketchat' → KEIN Meta-Match."""
|
||||||
|
from plugin.archivar.router import BidirectionalRouter
|
||||||
|
|
||||||
|
assert not BidirectionalRouter._is_meta_question(
|
||||||
|
"Was hat der Archivar aufgrund des Keywords Rocketchat empfohlen?"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
# ── P0-BUGFIX: target_room bei stay_in_room ─────────────────────────────────
|
||||||
|
|
||||||
|
|
||||||
|
class TestTargetRoomStayInRoomP0:
|
||||||
|
"""P0-BUGFIX: target_room=origin_room_id bei stay_in_room=True.
|
||||||
|
|
||||||
|
Bug: Bei stay_in_room=True wurde target_room=catch_all_id (DM) gesetzt.
|
||||||
|
Das leakt in _THEMATIC_TARGET_ROOM → Agent-Prompt bekommt falschen Raum
|
||||||
|
→ Agent denkt er sei im DM.
|
||||||
|
|
||||||
|
Fix: target_room=origin_room_id bei stay_in_room=True.
|
||||||
|
Adapter-Guard: _THEMATIC_TARGET_ROOM nur setzen wenn NICHT stay_in_room.
|
||||||
|
"""
|
||||||
|
|
||||||
|
def test_meta_question_target_room_is_origin(self):
|
||||||
|
"""Meta-Frage: target_room muss origin_room_id sein, nicht catch_all."""
|
||||||
|
import json
|
||||||
|
import tempfile
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
json_str = _make_map_json(
|
||||||
|
rooms=[
|
||||||
|
{"room_id": "r_plugin", "name": "#Plugin",
|
||||||
|
"theme": "plugin dev", "keywords": ["plugin", "adapter"]},
|
||||||
|
{"room_id": "r_admin", "name": "DM Admin",
|
||||||
|
"theme": "admin", "keywords": [], "catch_all": True},
|
||||||
|
],
|
||||||
|
)
|
||||||
|
path = _tmp_map(json_str)
|
||||||
|
try:
|
||||||
|
from plugin.archivar.room_map import RoomMap
|
||||||
|
from plugin.archivar.archivar_state import ArchivarState
|
||||||
|
|
||||||
|
room_map = RoomMap.load(path)
|
||||||
|
state = ArchivarState()
|
||||||
|
state._loaded = True
|
||||||
|
|
||||||
|
router = BidirectionalRouter(room_map, None, state) # type: ignore
|
||||||
|
|
||||||
|
# Meta-Frage aus dem Plugin-Raum
|
||||||
|
decision = asyncio.run(
|
||||||
|
router.route(
|
||||||
|
"Wie funktioniert der Archivar?",
|
||||||
|
origin_room_id="r_plugin",
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
assert decision.is_meta, "Sollte als Meta-Frage erkannt werden"
|
||||||
|
assert decision.stay_in_room, "Meta-Fragen sollen stay_in_room sein"
|
||||||
|
assert decision.target_room == "r_plugin", (
|
||||||
|
f"target_room sollte origin_room_id='r_plugin' sein, "
|
||||||
|
f"nicht catch_all_id='{decision.target_room}'"
|
||||||
|
)
|
||||||
|
finally:
|
||||||
|
path.unlink(missing_ok=True)
|
||||||
|
|
||||||
|
def test_smalltalk_target_room_empty(self):
|
||||||
|
"""Smalltalk: target_room bleibt '' (kein Routing)."""
|
||||||
|
import json
|
||||||
|
import tempfile
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
json_str = _make_map_json(
|
||||||
|
rooms=[
|
||||||
|
{"room_id": "r_plugin", "name": "#Plugin",
|
||||||
|
"theme": "plugin dev", "keywords": ["plugin"]},
|
||||||
|
{"room_id": "r_admin", "name": "DM Admin",
|
||||||
|
"theme": "admin", "keywords": [], "catch_all": True},
|
||||||
|
],
|
||||||
|
)
|
||||||
|
path = _tmp_map(json_str)
|
||||||
|
try:
|
||||||
|
from plugin.archivar.room_map import RoomMap
|
||||||
|
from plugin.archivar.archivar_state import ArchivarState
|
||||||
|
|
||||||
|
room_map = RoomMap.load(path)
|
||||||
|
state = ArchivarState()
|
||||||
|
state._loaded = True
|
||||||
|
|
||||||
|
# Mock classifier needed — router crashes with None
|
||||||
|
mock_classifier = MagicMock()
|
||||||
|
mock_classifier.is_initialized = True
|
||||||
|
mock_classifier.classify = AsyncMock(return_value=None)
|
||||||
|
mock_classifier._llm_raw = AsyncMock(return_value="STAY")
|
||||||
|
|
||||||
|
router = BidirectionalRouter(room_map, mock_classifier, state)
|
||||||
|
|
||||||
|
# Smalltalk aus dem Plugin-Raum
|
||||||
|
decision = asyncio.run(
|
||||||
|
router.route(
|
||||||
|
"Hallo, wie geht's?",
|
||||||
|
origin_room_id="r_plugin",
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
assert decision.stay_in_room, "Smalltalk soll stay_in_room sein"
|
||||||
|
# target_room ist '' bei Smalltalk (kein Routing-Ziel)
|
||||||
|
assert decision.target_room == "", (
|
||||||
|
f"Smalltalk target_room sollte '' sein, nicht '{decision.target_room}'"
|
||||||
|
)
|
||||||
|
finally:
|
||||||
|
path.unlink(missing_ok=True)
|
||||||
|
|
||||||
|
def test_archivar_sachfrage_nicht_meta(self):
|
||||||
|
"""'Was hat der Archivar empfohlen?' → KEIN Meta, normaler Flow."""
|
||||||
|
import json
|
||||||
|
import tempfile
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
json_str = _make_map_json(
|
||||||
|
rooms=[
|
||||||
|
{"room_id": "r_plugin", "name": "#Plugin",
|
||||||
|
"theme": "plugin dev", "keywords": ["plugin", "adapter", "rocketchat"]},
|
||||||
|
{"room_id": "r_admin", "name": "DM Admin",
|
||||||
|
"theme": "admin", "keywords": [], "catch_all": True},
|
||||||
|
],
|
||||||
|
)
|
||||||
|
path = _tmp_map(json_str)
|
||||||
|
try:
|
||||||
|
from plugin.archivar.room_map import RoomMap
|
||||||
|
from plugin.archivar.archivar_state import ArchivarState
|
||||||
|
|
||||||
|
room_map = RoomMap.load(path)
|
||||||
|
state = ArchivarState()
|
||||||
|
state._loaded = True
|
||||||
|
|
||||||
|
router = BidirectionalRouter(room_map, None, state) # type: ignore
|
||||||
|
|
||||||
|
# Sachfrage mit 'Archivar' als Fachbegriff
|
||||||
|
decision = asyncio.run(
|
||||||
|
router.route(
|
||||||
|
"Was hat der Archivar aufgrund des Keywords Rocketchat empfohlen?",
|
||||||
|
origin_room_id="r_plugin",
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
# Darf NICHT is_meta sein
|
||||||
|
assert not decision.is_meta, (
|
||||||
|
"Sachfrage mit 'Archivar' als Fachbegriff darf NICHT "
|
||||||
|
"als Meta-Frage erkannt werden"
|
||||||
|
)
|
||||||
|
finally:
|
||||||
|
path.unlink(missing_ok=True)
|
||||||
@@ -10,8 +10,8 @@
|
|||||||
"r_proton": {
|
"r_proton": {
|
||||||
"lan-dokumentation": {
|
"lan-dokumentation": {
|
||||||
"state": "AKTIV",
|
"state": "AKTIV",
|
||||||
"timestamp": "2026-07-13T15:47:31.199595",
|
"timestamp": "2026-07-13T20:34:20.149597",
|
||||||
"last_extended": "2026-07-13T15:47:31.199595",
|
"last_extended": "2026-07-13T20:34:20.149597",
|
||||||
"extension_count": 0
|
"extension_count": 0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user