feat(P1): Auto-Route-Widerspruch-Flow — detect_routing_contradiction + Clarify
- feedback_detector.py: HIER_HER-Muster ergänzt (positive Formulierung
'Nein, es passt hier her' → routing_rejection)
- router.py: RoutingDecision um is_contradiction/contradiction_result
erweitert; should_route() blockt bei Widerspruch
- adapter_integration.py: detect_routing_contradiction als Pre-Check in
classify_and_route() eingebunden (Clarify statt Auto-Route)
- adapter.py: _send_widerspruch_clarify() mit 2 Buttons
('generell hier her' → set_never_route, 'nur jetzt hier her' → stay_once),
WIDERSPRUCH:-Button-Handler, _widerspruch_state; alte V8.3-3
Auto-Retrieve-Routine durch Clarify-Flow ersetzt
- tests: test_auto_route_contradiction_persists.py (14 Tests, 4 Szenarien)
Pitfalls beachtet: P-028, P-040, P-056, P-057, P-066, P-067
This commit is contained in:
@@ -396,6 +396,32 @@ class ArchivarMessageHandler:
|
||||
|
||||
decision = await self._router.route(text, origin_room_id, is_dm=is_dm)
|
||||
|
||||
# ── V8.5: Routing-Widerspruch als Pre-Check ─────────────────────
|
||||
# detect_routing_contradiction() wird NACH dem Router aufgerufen,
|
||||
# aber VOR der Stats-/Move-Request-Verarbeitung. Bei einem Treffer
|
||||
# wird die Entscheidung auf stay_in_room + is_contradiction gesetzt,
|
||||
# damit der Adapter einen Clarify (2 Buttons) auslöst statt zu routen.
|
||||
# Der Router selbst kennt den Widerspruch nicht — er hat bereits
|
||||
# eine normale RoutingDecision produziert. Wir überschreiben sie.
|
||||
contradiction = self.detect_routing_contradiction(text, origin_room_id)
|
||||
if contradiction is not None:
|
||||
logger.info(
|
||||
"V8.5: Routing-Widerspruch in classify_and_route — "
|
||||
"type=%s pattern=%s → Clarify statt Auto-Route",
|
||||
contradiction.contradiction_type,
|
||||
contradiction.matched_pattern,
|
||||
)
|
||||
decision.is_contradiction = True
|
||||
decision.contradiction_result = contradiction
|
||||
decision.stay_in_room = True
|
||||
decision.move_request_sent = False
|
||||
decision.needs_clarification = False
|
||||
decision.target_room = ""
|
||||
decision.category = "contradiction"
|
||||
self._stats["contradiction"] = self._stats.get("contradiction", 0) + 1
|
||||
routing_telemetry.flush()
|
||||
return decision
|
||||
|
||||
# Update stats
|
||||
self._stats["total"] += 1
|
||||
if decision.is_meta:
|
||||
|
||||
@@ -128,6 +128,17 @@ class RoutingWiderspruchDetector:
|
||||
re.IGNORECASE,
|
||||
)
|
||||
|
||||
# e) Hier-her-Bestätigung: positive Formulierung „passt hier her"
|
||||
# „Nein, es passt hier her", „Das gehört hier her", „Bleib hier"
|
||||
# → routing_rejection ohne Raumnennung (User will im aktuellen Raum bleiben).
|
||||
HIER_HER: re.Pattern = re.compile(
|
||||
r"(?:passt|gehört|gehoert|bleibt|bleib|soll|landet)\s+"
|
||||
r"(?:hier\s+her|hierher|hier\s+hin|hierhin|hier)"
|
||||
r"|"
|
||||
r"(?:bleib|bleibe|lass\s+es)\s+hier",
|
||||
re.IGNORECASE,
|
||||
)
|
||||
|
||||
# ── Confidence-Werte pro Mustertyp ──────────────────────────────────
|
||||
|
||||
CONFIDENCE_MAP = {
|
||||
@@ -136,6 +147,7 @@ class RoutingWiderspruchDetector:
|
||||
"nicht_in_x_sondern_in_y": 0.92,
|
||||
"verneinung": 0.85,
|
||||
"befehle": 0.82,
|
||||
"hier_her": 0.86,
|
||||
}
|
||||
|
||||
# ── Public API ──────────────────────────────────────────────────────
|
||||
@@ -228,5 +240,19 @@ class RoutingWiderspruchDetector:
|
||||
matched_pattern="befehle",
|
||||
)
|
||||
|
||||
# ── e) Hier-her-Bestätigung ──────────────────────────────────────
|
||||
# Positive Formulierung „passt hier her" — User will im aktuellen
|
||||
# Raum bleiben. Wird NACH den spezifischeren Mustern geprüft, damit
|
||||
# „nicht in X, sondern hier" korrekt als reroute_request erkannt wird.
|
||||
m_hier = self.HIER_HER.search(text)
|
||||
if m_hier:
|
||||
logger.debug("Widerspruch (hier_her): matched")
|
||||
return ContradictionResult(
|
||||
has_contradiction=True,
|
||||
contradiction_type="routing_rejection",
|
||||
confidence=self.CONFIDENCE_MAP["hier_her"],
|
||||
matched_pattern="hier_her",
|
||||
)
|
||||
|
||||
# Kein Widerspruch erkannt
|
||||
return None
|
||||
|
||||
@@ -314,6 +314,17 @@ class RoutingDecision:
|
||||
"""Strukturierter Prompt für den Agenten: 'Router unsicher. Räume: ...'
|
||||
Leer wenn kein Red Flag."""
|
||||
|
||||
# ── V8.5: Routing-Widerspruch (Auto-Route-Widerspruch-Flow) ─────────
|
||||
|
||||
is_contradiction: bool = False
|
||||
"""True wenn die Nachricht einen Routing-Widerspruch enthält
|
||||
(detect_routing_contradiction hat getroffen). Der Adapter soll dann
|
||||
einen Clarify mit zwei Buttons auslösen statt zu routen."""
|
||||
|
||||
contradiction_result: Optional[Any] = None
|
||||
"""Das ContradictionResult-Objekt (feedback_detector) bei Treffer,
|
||||
sonst None. Enthält contradiction_type, rejected_room, target_room etc."""
|
||||
|
||||
def should_route(self) -> bool:
|
||||
"""True wenn die Nachricht geroutet werden sollte.
|
||||
|
||||
@@ -329,6 +340,7 @@ class RoutingDecision:
|
||||
not self.is_catch_all and
|
||||
not self.is_unrouteable and
|
||||
not self.move_request_sent and
|
||||
not self.is_contradiction and
|
||||
bool(self.target_room)
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user