fix: V8.1 Routing-Engine — 7 Root Causes (Auto-Route, Sticky, Echo, Kontext-Ring, LLM-URL, FAISS, Buttons)
P1: 100%-Keyword-Route sendet Antwort in Zielraum (echtes Routing)
- adapter.py:1603-1645: Auto-Route-Block vor _CURRENT_ORIGIN_ROOM
- Bei move_request_sent=False + target_room != room_id → dispatch in Zielraum
- Nachricht wird in Zielraum kopiert, Agent antwortet dort
P2: Temporäres Sticky (30 Min) bei confirm_move
- adapter.py:625: _session_room_preferences Dict
- adapter.py:1414-1428: Sticky bei confirm_move gesetzt
- adapter.py:1557-1597: Session-Sticky-Check vor Archivar (Auto-Route)
- adapter.py:1638-1645: Sticky auch bei Auto-Route gesetzt
P3: Echtes Move (Original löschen) statt Copy+Breadcrumb
- adapter.py:1414-1420: Kein Copy mehr bei confirm_move
- Nur Breadcrumb "Wir sind rübergewechselt → #Zielraum" im Ursprungsraum
P4: MultiRoomContext-Ring — raum-übergreifender Konversations-Kontext
- Neu: archivar/multiroom_context.py (Ring-Buffer, 10 Einträge)
- adapter.py:1293-1299: Ring-Update bei jeder User-Nachricht
- adapter.py:1752-1767: Ring-Summary in System-Prompt injiziert
P5: LLM-Router URL — ARCHIVAR_LLM_BASE_URL statt OLLAMA_BASE_URL
- config.py:150-153: Neue Env-Var ARCHIVAR_LLM_BASE_URL
- OLLAMA_BASE_URL als Legacy-Fallback
P6: FAISS is_stale() — Member-Set-Check zusätzlich zu Version
- room_index.py:540-590: Prüft set(map_rooms) == set(index_rooms)
- Bei Mismatch → rebuild mit Logging
P7: Move-Request-Template auf 3 Buttons
- config.py:209-215: 1️⃣ Rüber, 2️⃣ Generell hier, 3️⃣ Nur diesmal
- stay_once fällt in else-Branch (adapter.py:1447)
Verifikation: 345/346 archivar tests passed (1 pre-existing env fail)
This commit is contained in:
+111
-9
@@ -42,6 +42,7 @@ def _MULTIROOM() -> bool:
|
||||
if _MULTIROOM():
|
||||
from archivar.adapter_integration import ArchivarMessageHandler
|
||||
from archivar.conversation_history import ConversationHistory
|
||||
from archivar.multiroom_context import MultiRoomContextRing
|
||||
from archivar.router import room_name_to_topic
|
||||
|
||||
# Routing-Counter: immer importieren (keine schweren Abhängigkeiten)
|
||||
@@ -613,6 +614,7 @@ class RocketChatAdapter(BasePlatformAdapter):
|
||||
# Archivar: Embedding-basierte Nachrichten-Klassifikation
|
||||
if _MULTIROOM():
|
||||
self._conversation_history = ConversationHistory(max_size=10)
|
||||
self._multiroom_context = MultiRoomContextRing(max_entries=10)
|
||||
self.archivar = ArchivarMessageHandler(
|
||||
send_callback=self._send_via_archivar,
|
||||
button_send_callback=self._send_archivar_buttons,
|
||||
@@ -621,8 +623,12 @@ class RocketChatAdapter(BasePlatformAdapter):
|
||||
else:
|
||||
self.archivar = None
|
||||
self._conversation_history = None
|
||||
self._multiroom_context = None
|
||||
# User-Flow C: Move-Requests
|
||||
self._pending_move_requests: Dict[str, dict] = {}
|
||||
# V8.1 P2: Temporäre Session-Raum-Präferenzen (30 Min TTL)
|
||||
# Wird bei confirm_move gesetzt und vor Archivar-Klassifikation geprüft.
|
||||
self._session_room_preferences: Dict[str, Dict[str, Any]] = {}
|
||||
# V7-2: _sticky_rooms removed — thematic never_route replaces spatial bypass.
|
||||
# The router's _check_never_route_topic handles per-topic blocking now.
|
||||
# Clarify state: maps clarify_id → session_key for gateway resolution
|
||||
@@ -1285,6 +1291,13 @@ class RocketChatAdapter(BasePlatformAdapter):
|
||||
if _MULTIROOM() and self._conversation_history is not None:
|
||||
await self._conversation_history.add(room_id, "user", text)
|
||||
|
||||
# V8.1 P4: MultiRoomContext-Ring — Thema aus Nachricht extrahieren
|
||||
if _MULTIROOM() and self._multiroom_context is not None:
|
||||
# Extrahiere ein kurzes Topic aus der Nachricht (erste 80 Zeichen)
|
||||
topic = text[:80].replace("\n", " ").strip()
|
||||
if topic:
|
||||
await self._multiroom_context.add(room_id, room_name, topic)
|
||||
|
||||
# ── Kontext-Reset: _THEMATIC_TARGET_ROOM pro Nachricht zurücksetzen ──
|
||||
# Verhindert dass der Zielraum der VORHERIGEN Nachricht an der
|
||||
# aktuellen klebt (z.B. DM nach Projektraum-Turn → Antwort im Projektraum).
|
||||
@@ -1412,14 +1425,22 @@ class RocketChatAdapter(BasePlatformAdapter):
|
||||
feedback_type = "stay" # Default
|
||||
forwarded = False
|
||||
if choice in ("1", "1️⃣", "Rüber", "rüber", "rüberkopieren", "kopieren", "confirm_move", "✅ja"):
|
||||
# 1️⃣ Rüberkopieren → Antwort im Zielraum
|
||||
target_txt = f"*(Auftrag von @{move_req['username']}, hierher kopiert)*\n{move_req['text']}"
|
||||
if move_req.get("username"):
|
||||
await self._post_message_with_retry(move_req["target_room"], target_txt)
|
||||
# 1️⃣ Rüber → Antwort im Zielraum (V8.1 P3: echtes Move, kein Copy)
|
||||
_CURRENT_ORIGIN_ROOM.set(move_req["target_room"])
|
||||
_THEMATIC_TARGET_ROOM.set(move_req["target_room"])
|
||||
forwarded = True
|
||||
feedback_type = "confirm"
|
||||
# V8.1 P2: Temporäres Sticky für aktive Session (30 Min TTL)
|
||||
self._session_room_preferences[room_id] = {
|
||||
"target_room": move_req["target_room"],
|
||||
"target_name": move_req.get("target_name", "Zielraum"),
|
||||
"expires_at": time.time() + 1800, # 30 Minuten
|
||||
}
|
||||
logger.info(
|
||||
"[rocketchat] V8.1 P2: Session-Sticky gesetzt — "
|
||||
"room=%s → target=%s (30 Min)",
|
||||
room_id[:8], move_req.get("target_name", "?")[:20],
|
||||
)
|
||||
elif choice in ("2", "2️⃣", "generell", "generell hier bleiben", "stay_here"):
|
||||
# 2️⃣ Generell hier bleiben → Antwort im Ursprungsraum + Sticky-Eintrag
|
||||
# P0-B: Thematischer Sticky (v7) — Thema aus Match-Ergebnis extrahieren
|
||||
@@ -1546,6 +1567,47 @@ class RocketChatAdapter(BasePlatformAdapter):
|
||||
logger.debug("[rocketchat] ARCHIVAR-DEBUG: Archivar bypassed — DM (no multiroom)")
|
||||
routing_counter.increment('dm_routing_skipped')
|
||||
logger.info("ROUTING BYPASS: reason=dm_routing_skipped, origin_room=%s", room_id)
|
||||
elif room_id in self._session_room_preferences:
|
||||
# V8.1 P2: Temporäres Session-Sticky — Auto-Route ohne Archivar
|
||||
pref = self._session_room_preferences[room_id]
|
||||
if time.time() < pref["expires_at"]:
|
||||
target_room_id = pref["target_room"]
|
||||
target_name = pref.get("target_name", "Zielraum")
|
||||
# Kopiere Nachricht in den Zielraum
|
||||
target_txt = f"*(Auftrag von @{username}, Session-Sticky)*\n{text}"
|
||||
await self._post_message_with_retry(target_room_id, target_txt)
|
||||
_CURRENT_ORIGIN_ROOM.set(target_room_id)
|
||||
_THEMATIC_TARGET_ROOM.set(target_room_id)
|
||||
routing_counter.increment('session_sticky_auto_route')
|
||||
logger.info(
|
||||
"[rocketchat] V8.1 P2: Session-Sticky active — "
|
||||
"auto-routing '%s' → %s (%.0fs remaining)",
|
||||
text[:80], target_name,
|
||||
pref["expires_at"] - time.time(),
|
||||
)
|
||||
# Dispatch direkt — kein Archivar
|
||||
target_room_info = self._room_info.get(target_room_id, {})
|
||||
target_room_name = target_room_info.get("name", target_name)
|
||||
target_room_type = target_room_info.get("type", "c")
|
||||
await self._dispatch_agent(
|
||||
text=text,
|
||||
room_id=target_room_id,
|
||||
room_name=target_room_name,
|
||||
room_type=target_room_type,
|
||||
username=username,
|
||||
msg_id=msg_id,
|
||||
msg_obj=msg_obj,
|
||||
is_button_response=is_button_response,
|
||||
category="work_order",
|
||||
)
|
||||
return
|
||||
else:
|
||||
# Abgelaufen → aufräumen
|
||||
del self._session_room_preferences[room_id]
|
||||
logger.debug(
|
||||
"[rocketchat] V8.1 P2: Session-Sticky expired for room %s",
|
||||
room_id[:8],
|
||||
)
|
||||
else:
|
||||
logger.debug("[rocketchat] ARCHIVAR-DEBUG: Calling classify_and_route for room=%s", room_id[:12])
|
||||
decision = await self.archivar.classify_and_route(text, origin_room_id=room_id)
|
||||
@@ -1614,13 +1676,45 @@ class RocketChatAdapter(BasePlatformAdapter):
|
||||
logger.info("ROUTING BYPASS: reason=move_request_pending_guard, origin_room=%s", room_id)
|
||||
return
|
||||
|
||||
# _CURRENT_ORIGIN_ROOM wird NIE auf den Zielraum gesetzt.
|
||||
# Die Agent-Antwort bleibt im Ursprungsraum. Nur die Nachricht
|
||||
# wird kopiert — mit User-Entscheidung bei Aufträgen.
|
||||
# V8.1 P1: 100%-Keyword-Route / FAISS-Auto-Route → echtes Routing
|
||||
# Wenn move_request_sent=False ABER target_room gesetzt (nicht self-match):
|
||||
# Antwort WIRKLICH in den Zielraum senden, Nachricht rüberkopieren.
|
||||
forwarded = False
|
||||
if (decision and hasattr(decision, 'target_room') and decision.target_room
|
||||
and not getattr(decision, 'move_request_sent', False)
|
||||
and decision.target_room != room_id):
|
||||
target_room_id = decision.target_room
|
||||
target_name = getattr(decision, 'move_request_target_name', 'Zielraum')
|
||||
# Kopiere Nachricht in den Zielraum
|
||||
target_txt = f"*(Auftrag von @{username}, automatisch geroutet)*\n{text}"
|
||||
await self._post_message_with_retry(target_room_id, target_txt)
|
||||
# Setze _CURRENT_ORIGIN_ROOM auf Zielraum → Agent antwortet dort
|
||||
_CURRENT_ORIGIN_ROOM.set(target_room_id)
|
||||
_THEMATIC_TARGET_ROOM.set(target_room_id)
|
||||
forwarded = True
|
||||
routing_counter.increment('auto_route_dispatched')
|
||||
logger.info(
|
||||
"[rocketchat] V8.1 P1: Auto-Route '%s' → %s — "
|
||||
"Agent dispatched in target room",
|
||||
text[:80], target_name,
|
||||
)
|
||||
# V8.1 P2: Temporäres Sticky für aktive Session (30 Min TTL)
|
||||
self._session_room_preferences[room_id] = {
|
||||
"target_room": target_room_id,
|
||||
"target_name": target_name,
|
||||
"expires_at": time.time() + 1800,
|
||||
}
|
||||
logger.info(
|
||||
"[rocketchat] V8.1 P2: Session-Sticky gesetzt — "
|
||||
"room=%s → target=%s (30 Min, Auto-Route)",
|
||||
room_id[:8], target_name[:20],
|
||||
)
|
||||
|
||||
# _CURRENT_ORIGIN_ROOM wird NUR gesetzt wenn nicht forwarded.
|
||||
# Bei forwarded (Auto-Route) wurde es bereits auf Zielraum gesetzt.
|
||||
# P0-2: Der alte Silent-Copy-Pfad (decision.target_room ohne move_request_sent)
|
||||
# ist im v6-Flow tot — alle Routing-Entscheidungen haben move_request_sent=True.
|
||||
# Move-Request-Handling erfolgt bereits oben (vor Archivar, Zeile 1186-1273).
|
||||
forwarded = False
|
||||
|
||||
# Move-Request-Handling ist bereits oben (vor Archivar) — hier nur Silent Copy
|
||||
|
||||
@@ -1662,6 +1756,14 @@ class RocketChatAdapter(BasePlatformAdapter):
|
||||
with _question_counter_lock:
|
||||
archivar_suffix = f" [Frage {_question_counter}, Timeout — Räume: {rooms_str}]"
|
||||
# ── Ende Kontext-Weitergabe ──────────────────────────────────────
|
||||
# V8.1 P4: MultiRoomContext-Ring in System-Prompt injizieren
|
||||
chat_topic = self._room_map_summary
|
||||
if self._multiroom_context is not None:
|
||||
ring_summary = await self._multiroom_context.get_summary(
|
||||
exclude_room_id=room_id
|
||||
)
|
||||
if ring_summary:
|
||||
chat_topic = f"{chat_topic}\n\n{ring_summary}" if chat_topic else ring_summary
|
||||
source = SessionSource(
|
||||
platform=Platform("rocketchat"),
|
||||
chat_id=virtual_chat_id, # ← user-based instead of room-based
|
||||
@@ -1669,7 +1771,7 @@ class RocketChatAdapter(BasePlatformAdapter):
|
||||
user_id=username,
|
||||
user_name=username,
|
||||
chat_type="dm", # ← force DM to bypass group isolation in Core
|
||||
chat_topic=self._room_map_summary, # FIX E: Raum-Map in System-Prompt
|
||||
chat_topic=chat_topic, # FIX E + V8.1 P4: Raum-Map + MultiRoom-Kontext
|
||||
)
|
||||
# ── FIX A: Text-Prefix in User-Nachricht injizieren ──────────
|
||||
# Der Agent muss wissen, in welchem Raum er angesprochen wird.
|
||||
|
||||
Reference in New Issue
Block a user