P0-B: Schema-Migration never_route[room_id] → never_route[room_id][topic] (v7)
- archivar_state.py: _never_route von Set zu Dict[room_id][topic] migriert
- Neue Methoden: set_never_route, is_never_route, remove_never_route,
get_never_route_topics, expire_stale_entries (Stub)
- Migrations-Logik: Altes Listen-Format → leeren + loggen
- GC: cleanup_orphaned_rooms bereinigt jetzt auch _never_route
- Persistenz: _to_dict/save/load für neues JSON-Format
- router.py: Raum-Level never_route-Bypass entfernt
- _room_name_to_topic: Raum-Name → Topic-Slug
- _check_never_route_topic: Prüft Thema in allen 3 Match-Pfaden
(Keyword, FAISS, LLM)
- Kein Thema erkennbar → Fallback: Butler darf fragen
- adapter.py: 'Generell hier bleiben' + Auto-Promotion thematisch
- set_never_route(room_id, topic) statt set_room_state(never_route)
- Topic aus move_req['target_name'] extrahiert
- should_stay_in_room nur noch für 'always' als Bypass
Tests: 18/18 archivar_state + 2/2 router — alle grün
Syntax: python3 -m py_compile auf allen 3 Dateien — OK
This commit is contained in:
+72
-10
@@ -12,7 +12,7 @@ import asyncio
|
||||
import logging
|
||||
import re
|
||||
from dataclasses import dataclass, field
|
||||
from typing import Dict, List, Optional, Tuple
|
||||
from typing import Any, Dict, List, Optional, Tuple
|
||||
|
||||
from .classifier import ClassificationResult, IntentClassifier
|
||||
from .config import (
|
||||
@@ -196,6 +196,7 @@ class BidirectionalRouter:
|
||||
state: ArchivarState,
|
||||
room_index: Optional[RoomIndexManager] = None,
|
||||
booster: Optional[KeywordBooster] = None,
|
||||
conversation_history: Optional[Any] = None,
|
||||
) -> None:
|
||||
"""
|
||||
Args:
|
||||
@@ -206,12 +207,15 @@ class BidirectionalRouter:
|
||||
Wenn None, wird Phase-1 übersprungen (bestehendes Verhalten).
|
||||
booster: Optional ``KeywordBooster`` für FAISS-Score-Verfeinerung.
|
||||
Wenn None, wird Phase-1 übersprungen (bestehendes Verhalten).
|
||||
conversation_history: Optional ``ConversationHistory`` (B5v6.5).
|
||||
Für Konversationskontext bei Themenwechsel- und rekursiver Erkennung.
|
||||
"""
|
||||
self._room_map = room_map
|
||||
self._classifier = classifier
|
||||
self._state = state
|
||||
self._room_index: Optional[RoomIndexManager] = room_index
|
||||
self._booster: Optional[KeywordBooster] = booster
|
||||
self._conversation_history = conversation_history
|
||||
self._subscribed_room_ids: Optional[set] = None
|
||||
# Semaphore für Ollama-Concurrency: qwen2.5:7b kann nur 1 Request
|
||||
# parallel verarbeiten. Ohne diesen Schutz führen parallele Aufrufe
|
||||
@@ -313,15 +317,9 @@ class BidirectionalRouter:
|
||||
confidence=1.0,
|
||||
stay_in_room=True,
|
||||
)
|
||||
elif room_state_decision == "never_route":
|
||||
# Sticky: User hat 'Generell hier bleiben' gewählt —
|
||||
# KEIN Move-Request, KEIN Archivar-Aufruf, KEIN Routing
|
||||
return RoutingDecision(
|
||||
category="direct_question",
|
||||
target_room="",
|
||||
confidence=1.0,
|
||||
stay_in_room=True,
|
||||
)
|
||||
# P0-B: "never_route" ist jetzt thematisch (v7) — nicht mehr
|
||||
# auf Raum-Ebene prüfbar. Der Check erfolgt nach dem Match
|
||||
# mit is_never_route(room_id, topic).
|
||||
|
||||
# ── Schritt 2: Meta-Fragen-Erkennung ──────────────────────────
|
||||
if self._is_meta_question(text):
|
||||
@@ -361,6 +359,15 @@ class BidirectionalRouter:
|
||||
notification = f"📋 Bearbeite ich in #{room_name} — [Link]"
|
||||
matched_keywords = self._extract_matched_keywords(text, matched_room)
|
||||
|
||||
# ── P0-B: never_route topic check ──────────────────────
|
||||
if self._check_never_route_topic(origin_room_id, matched_room):
|
||||
return RoutingDecision(
|
||||
category="direct_question",
|
||||
target_room="",
|
||||
confidence=1.0,
|
||||
stay_in_room=True,
|
||||
)
|
||||
|
||||
# ── FIX C: 100% Keywords → Auto-Route (kein Butler) ──────
|
||||
# Andreas' Regel: Wenn Kategorie-1-Wörter (100% Keywords)
|
||||
# gefunden werden, ist der Butler nicht notwendig.
|
||||
@@ -446,6 +453,15 @@ class BidirectionalRouter:
|
||||
notification = f"📋 Bearbeite ich in #{room_name} — [Link]"
|
||||
matched_keywords = self._extract_matched_keywords(text, room)
|
||||
|
||||
# ── P0-B: never_route topic check ──────────
|
||||
if self._check_never_route_topic(origin_room_id, room):
|
||||
return RoutingDecision(
|
||||
category="direct_question",
|
||||
target_room="",
|
||||
confidence=1.0,
|
||||
stay_in_room=True,
|
||||
)
|
||||
|
||||
logger.info(
|
||||
"FAISS Phase-1: auto-route '%s' → %s (score=%.3f, booster=%s)",
|
||||
text[:80],
|
||||
@@ -645,6 +661,15 @@ class BidirectionalRouter:
|
||||
)
|
||||
|
||||
# Guard 3: LLM == anderer Raum → Move-Request (Butler-Prinzip)
|
||||
# ── P0-B: never_route topic check ──────────────────────────
|
||||
if self._check_never_route_topic(origin_room_id, llm_room):
|
||||
return RoutingDecision(
|
||||
category="direct_question",
|
||||
target_room="",
|
||||
confidence=1.0,
|
||||
stay_in_room=True,
|
||||
)
|
||||
|
||||
room_name = llm_room.name.replace("#", "") if llm_room.name.startswith("#") else llm_room.name
|
||||
logger.info(
|
||||
"LLM-Raum-Router: '%s' → %s (%s) — Move-Request pending",
|
||||
@@ -913,6 +938,43 @@ class BidirectionalRouter:
|
||||
|
||||
return matched_keywords
|
||||
|
||||
@staticmethod
|
||||
def _room_name_to_topic(room_name: str) -> str:
|
||||
"""Konvertiert einen Raum-Namen in einen Topic-Slug.
|
||||
|
||||
'#LAN-Dokumentation' → 'lan-dokumentation'
|
||||
'#DevOps' → 'devops'
|
||||
|
||||
Args:
|
||||
room_name: Der Raum-Name (mit oder ohne #).
|
||||
|
||||
Returns:
|
||||
Topic-Slug (lowercase, ohne #, Leerzeichen → Bindestrich).
|
||||
"""
|
||||
name = room_name.lstrip("#")
|
||||
return name.lower().replace(" ", "-")
|
||||
|
||||
def _check_never_route_topic(
|
||||
self, origin_room_id: str, matched_room: RoomEntry
|
||||
) -> bool:
|
||||
"""Prüft ob das Thema des gematchten Raums in never_route ist.
|
||||
|
||||
Args:
|
||||
origin_room_id: Der Ursprungsraum.
|
||||
matched_room: Der gematchte Zielraum.
|
||||
|
||||
Returns:
|
||||
True wenn das Thema in never_route ist → stay_in_room.
|
||||
"""
|
||||
topic = self._room_name_to_topic(matched_room.name)
|
||||
if self._state.is_never_route(origin_room_id, topic):
|
||||
logger.info(
|
||||
"P0-B: never_route match — room %s, topic '%s' → stay_in_room",
|
||||
origin_room_id[:8], topic,
|
||||
)
|
||||
return True
|
||||
return False
|
||||
|
||||
# ── Bidirektionales Routing ────────────────────────────────────────
|
||||
|
||||
async def move_message(self, source_room: str, target_room: str, message: str, message_id: str) -> bool:
|
||||
|
||||
Reference in New Issue
Block a user