feat(archivar): RoutingWiderspruchDetector — textbasierte Widerspruch-Erkennung
NEUES MODUL: plugin/archivar/feedback_detector.py - RoutingWiderspruchDetector mit 4 Regex-Gruppen (Hauptmuster, Umrouting, Verneinung, Befehle) - ContradictionResult dataclass: has_contradiction, contradiction_type, confidence, target_room, rejected_room, matched_pattern - Edge Cases: 'nicht in X, sondern in Y' → X negativ, Y als Ziel - Kein LLM-Fallback (nur Regex in v1) EINHAENGUNG adapter_integration.py: - ArchivarMessageHandler.__init__(): self._feedback_detector - detect_routing_contradiction(text, origin_room_id) → ContradictionResult|None - Bei Treffer: update_keyword_weight(feedback_type='never') - _resolve_room_name_to_id() für Raum-Name → room_id Auflösung EINHAENGUNG adapter.py: - _process_incoming(): VOR classify_and_route() → contradiction-Check - Bei Treffer: Decision überschreiben (stay_in_room=True) - [WIDERSPRUCH]-Präfix — Nachricht NICHT schlucken, normal an Agent - NUR wenn KEIN Button-Feedback aktiv (kein pending move-request) Tests: 57/58 passed (1 pre-existing env-var failure unverändert)
This commit is contained in:
+58
-31
@@ -24,6 +24,7 @@ import urllib.request
|
||||
from typing import Any, Dict, List, Optional
|
||||
|
||||
from .archivar.adapter_integration import ArchivarMessageHandler
|
||||
from .archivar.router import RoutingDecision
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
logger.setLevel(logging.INFO)
|
||||
@@ -810,38 +811,64 @@ class RocketChatAdapter(BasePlatformAdapter):
|
||||
elif room_type == "d" and is_auftrag:
|
||||
logger.debug("[rocketchat] DM-Auftrag von %s — kein Routing", username)
|
||||
else:
|
||||
decision = await self.archivar.classify_and_route(text, origin_room_id=room_id)
|
||||
if decision and decision.category:
|
||||
# ── RoutingWiderspruchDetector: VOR classify_and_route() ──
|
||||
# NUR wenn KEIN Button-Feedback aktiv (kein pending move-request).
|
||||
# Button = geregelter Standard, Text = Fall ohne Button.
|
||||
contradiction = self.archivar.detect_routing_contradiction(
|
||||
text, origin_room_id=room_id
|
||||
)
|
||||
if contradiction:
|
||||
logger.info(
|
||||
"[rocketchat] Routing-Widerspruch in %s: type=%s conf=%.2f — "
|
||||
"stay_in_room + [WIDERSPRUCH]-Präfix",
|
||||
room_id[:8],
|
||||
contradiction.contradiction_type,
|
||||
contradiction.confidence,
|
||||
)
|
||||
# Decision überschreiben: stay_in_room
|
||||
decision = RoutingDecision(
|
||||
category="direct_question",
|
||||
target_room="",
|
||||
confidence=contradiction.confidence,
|
||||
stay_in_room=True,
|
||||
)
|
||||
category = decision.category
|
||||
# ── Archivar-Kontext-Weitergabe: Zielraum + Frage-Nr ──────
|
||||
if hasattr(decision, 'target_room') and decision.target_room:
|
||||
_THEMATIC_TARGET_ROOM.set(decision.target_room)
|
||||
global _question_counter
|
||||
with _question_counter_lock:
|
||||
_question_counter += 1
|
||||
# ── Ende Kontext-Weitergabe ──────────────────────────────
|
||||
# Archivar v4 Move-Request: _pending_move_requests befüllen, damit
|
||||
# der Button-Response-Handler (lines 717-764) die Antwort korrekt
|
||||
# verarbeiten und _CURRENT_ORIGIN_ROOM auf den Zielraum setzen kann.
|
||||
if (getattr(decision, 'move_request_sent', False)
|
||||
and hasattr(decision, 'target_room')
|
||||
and decision.target_room):
|
||||
self._pending_move_requests[room_id] = {
|
||||
'text': text,
|
||||
'origin_room': room_id,
|
||||
'target_room': decision.target_room,
|
||||
'target_name': getattr(
|
||||
decision, 'move_request_target_name', 'Zielraum'),
|
||||
'username': username,
|
||||
'message_id': msg_id,
|
||||
}
|
||||
# Lernsystem: Keywords für Feedback-Loop speichern
|
||||
if hasattr(decision, 'matched_keywords') and decision.matched_keywords:
|
||||
self.archivar._routed_messages[msg_id] = {
|
||||
"keywords": decision.matched_keywords,
|
||||
"target_room": decision.target_room,
|
||||
"timestamp": time.time()
|
||||
}
|
||||
# [WIDERSPRUCH]-Präfix setzen — Nachricht NICHT schlucken
|
||||
text = f"[WIDERSPRUCH] {text}"
|
||||
# Kein Routing, keine Move-Requests — direkt zum Agenten
|
||||
else:
|
||||
decision = await self.archivar.classify_and_route(text, origin_room_id=room_id)
|
||||
if decision and decision.category:
|
||||
category = decision.category
|
||||
# ── Archivar-Kontext-Weitergabe: Zielraum + Frage-Nr ──────
|
||||
if hasattr(decision, 'target_room') and decision.target_room:
|
||||
_THEMATIC_TARGET_ROOM.set(decision.target_room)
|
||||
global _question_counter
|
||||
with _question_counter_lock:
|
||||
_question_counter += 1
|
||||
# ── Ende Kontext-Weitergabe ──────────────────────────────
|
||||
# Archivar v4 Move-Request: _pending_move_requests befüllen, damit
|
||||
# der Button-Response-Handler (lines 717-764) die Antwort korrekt
|
||||
# verarbeiten und _CURRENT_ORIGIN_ROOM auf den Zielraum setzen kann.
|
||||
if (getattr(decision, 'move_request_sent', False)
|
||||
and hasattr(decision, 'target_room')
|
||||
and decision.target_room):
|
||||
self._pending_move_requests[room_id] = {
|
||||
'text': text,
|
||||
'origin_room': room_id,
|
||||
'target_room': decision.target_room,
|
||||
'target_name': getattr(
|
||||
decision, 'move_request_target_name', 'Zielraum'),
|
||||
'username': username,
|
||||
'message_id': msg_id,
|
||||
}
|
||||
# Lernsystem: Keywords für Feedback-Loop speichern
|
||||
if hasattr(decision, 'matched_keywords') and decision.matched_keywords:
|
||||
self.archivar._routed_messages[msg_id] = {
|
||||
"keywords": decision.matched_keywords,
|
||||
"target_room": decision.target_room,
|
||||
"timestamp": time.time()
|
||||
}
|
||||
except asyncio.TimeoutError:
|
||||
logger.warning("[rocketchat] Archivar classify_and_route() timed out")
|
||||
with _question_counter_lock:
|
||||
|
||||
Reference in New Issue
Block a user