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:
@@ -147,7 +147,10 @@ LLM_CONFIG = {
|
||||
"enabled": os.getenv("ARCHIVAR_ENABLE_LLM", "").strip().lower() in ("1", "true", "yes"),
|
||||
"model": "qwen2.5:7b",
|
||||
"timeout": 30.0, # Iterative Optimierung: Start 30s (19.06.2026)
|
||||
"base_url": os.getenv("OLLAMA_BASE_URL", "http://localhost:11434"),
|
||||
"base_url": os.getenv(
|
||||
"ARCHIVAR_LLM_BASE_URL",
|
||||
os.getenv("OLLAMA_BASE_URL", "http://localhost:11434")
|
||||
),
|
||||
"temperature": 0.0,
|
||||
"max_tokens": 30, # Raum-ID = 24 chars + Puffer
|
||||
}
|
||||
@@ -209,8 +212,9 @@ ARCHIVAR_STUFE_LOG = (
|
||||
MOVE_REQUEST_TEMPLATE: dict = {
|
||||
"text": "Soll ich diese Nachricht nach {target_name} kopieren?",
|
||||
"actions": [
|
||||
{"text": "✅Ja", "type": "confirm_move"},
|
||||
{"text": "📍Hier", "type": "stay_here"},
|
||||
{"text": "1️⃣ Rüber", "type": "confirm_move"},
|
||||
{"text": "2️⃣ Generell hier", "type": "stay_here"},
|
||||
{"text": "3️⃣ Nur diesmal", "type": "stay_once"},
|
||||
],
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,149 @@
|
||||
"""
|
||||
MultiRoomContextRing — raum-übergreifender Konversations-Kontext (V8.1 P4).
|
||||
|
||||
Speichert die letzten N Themenbeiträge aus allen Räumen als Ring-Buffer.
|
||||
Wird in den System-Prompt injiziert, damit der Agent raum-übergreifenden
|
||||
Kontext hat (z.B. "In #Dev wurde gerade über Deployment gesprochen").
|
||||
|
||||
Thread-safe via asyncio.Lock. In-Memory, nicht persistent.
|
||||
|
||||
Usage::
|
||||
|
||||
ring = MultiRoomContextRing(max_entries=10)
|
||||
ring.add("room-123", "#Dev", "Deployment-Status prüfen")
|
||||
ring.add("room-456", "#Support", "Login-Fehler bei User X")
|
||||
summary = ring.get_summary()
|
||||
# → "Raum-übergreifender Kontext:\n #Dev: Deployment-Status prüfen\n #Support: Login-Fehler bei User X"
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import asyncio
|
||||
import logging
|
||||
from collections import deque
|
||||
from dataclasses import dataclass, field
|
||||
from datetime import datetime, timezone
|
||||
from typing import Any, Dict, List, Optional
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
@dataclass
|
||||
class CrossRoomEntry:
|
||||
"""Ein einzelner Eintrag im MultiRoomContextRing."""
|
||||
|
||||
room_id: str
|
||||
"""Rocket.Chat Raum-ID."""
|
||||
|
||||
room_name: str
|
||||
"""Menschenlesbarer Raum-Name (z.B. '#Dev')."""
|
||||
|
||||
topic: str
|
||||
"""Thema / Zusammenfassung des letzten Beitrags."""
|
||||
|
||||
timestamp: datetime = field(default_factory=lambda: datetime.now(timezone.utc))
|
||||
"""Zeitstempel (UTC)."""
|
||||
|
||||
def to_summary_line(self) -> str:
|
||||
"""Formatiere als eine Zeile für den System-Prompt."""
|
||||
return f" {self.room_name}: {self.topic}"
|
||||
|
||||
|
||||
class MultiRoomContextRing:
|
||||
"""Ring-Buffer für raum-übergreifenden Konversations-Kontext.
|
||||
|
||||
Speichert die letzten N Themenbeiträge aus allen Räumen.
|
||||
Thread-safe via asyncio.Lock.
|
||||
"""
|
||||
|
||||
def __init__(self, max_entries: int = 10) -> None:
|
||||
"""Initialisiere den Ring-Buffer.
|
||||
|
||||
Args:
|
||||
max_entries: Maximale Anzahl Einträge im Ring (default: 10).
|
||||
"""
|
||||
if max_entries < 1:
|
||||
raise ValueError(f"max_entries must be >= 1, got {max_entries}")
|
||||
self._max_entries = max_entries
|
||||
self._lock = asyncio.Lock()
|
||||
self._entries: deque[CrossRoomEntry] = deque(maxlen=max_entries)
|
||||
|
||||
async def add(
|
||||
self,
|
||||
room_id: str,
|
||||
room_name: str,
|
||||
topic: str,
|
||||
timestamp: Optional[datetime] = None,
|
||||
) -> None:
|
||||
"""Füge einen Themenbeitrag zum Ring hinzu.
|
||||
|
||||
Überschreibt einen vorherigen Eintrag für denselben Raum,
|
||||
sodass pro Raum nur der LETZTE Beitrag im Ring ist.
|
||||
|
||||
Args:
|
||||
room_id: Rocket.Chat Raum-ID.
|
||||
room_name: Menschenlesbarer Raum-Name.
|
||||
topic: Thema / Zusammenfassung.
|
||||
timestamp: Optionaler Zeitstempel (default: jetzt UTC).
|
||||
"""
|
||||
if not room_id or not topic:
|
||||
return
|
||||
|
||||
entry = CrossRoomEntry(
|
||||
room_id=room_id,
|
||||
room_name=room_name,
|
||||
topic=topic.strip(),
|
||||
timestamp=timestamp or datetime.now(timezone.utc),
|
||||
)
|
||||
|
||||
async with self._lock:
|
||||
# Entferne vorherigen Eintrag für denselben Raum
|
||||
self._entries = deque(
|
||||
(e for e in self._entries if e.room_id != room_id),
|
||||
maxlen=self._max_entries,
|
||||
)
|
||||
self._entries.append(entry)
|
||||
|
||||
async def get_summary(self, exclude_room_id: str = "") -> str:
|
||||
"""Liefere eine menschenlesbare Zusammenfassung für den System-Prompt.
|
||||
|
||||
Args:
|
||||
exclude_room_id: Optional — schließe diesen Raum aus der
|
||||
Zusammenfassung aus (z.B. den aktuellen Raum).
|
||||
|
||||
Returns:
|
||||
Formatierter String mit allen Einträgen, oder leerer String.
|
||||
"""
|
||||
async with self._lock:
|
||||
entries = list(self._entries)
|
||||
if exclude_room_id:
|
||||
entries = [e for e in entries if e.room_id != exclude_room_id]
|
||||
if not entries:
|
||||
return ""
|
||||
lines = ["Raum-übergreifender Kontext (letzte Themen):"]
|
||||
for entry in entries:
|
||||
lines.append(entry.to_summary_line())
|
||||
return "\n".join(lines)
|
||||
|
||||
async def get_entries(self) -> List[Dict[str, Any]]:
|
||||
"""Liefere alle Einträge als Dict-Liste (für Debug/Logging)."""
|
||||
async with self._lock:
|
||||
return [
|
||||
{
|
||||
"room_id": e.room_id,
|
||||
"room_name": e.room_name,
|
||||
"topic": e.topic,
|
||||
"timestamp": e.timestamp.isoformat(),
|
||||
}
|
||||
for e in self._entries
|
||||
]
|
||||
|
||||
async def clear(self) -> None:
|
||||
"""Lösche alle Einträge."""
|
||||
async with self._lock:
|
||||
self._entries.clear()
|
||||
|
||||
@property
|
||||
def size(self) -> int:
|
||||
"""Anzahl der Einträge (nicht thread-safe, für Debug)."""
|
||||
return len(self._entries)
|
||||
@@ -538,7 +538,7 @@ class RoomIndexManager:
|
||||
return True
|
||||
|
||||
def is_stale(self, room_map_version: Optional[int] = None) -> bool:
|
||||
"""Prüft ob der Index veraltet ist (RoomMap-Version neuer).
|
||||
"""Prüft ob der Index veraltet ist (RoomMap-Version neuer ODER Member-Set abweichend).
|
||||
|
||||
Args:
|
||||
room_map_version: Aktuelle Version der RoomMap. Default:
|
||||
@@ -550,11 +550,45 @@ class RoomIndexManager:
|
||||
if not self.is_built:
|
||||
return True
|
||||
|
||||
# Check 1: Version mismatch
|
||||
current_version = (
|
||||
room_map_version if room_map_version is not None
|
||||
else self._room_map.version
|
||||
)
|
||||
return current_version > self._version
|
||||
if current_version > self._version:
|
||||
logger.info(
|
||||
"RoomIndex stale: version mismatch (index=%d, map=%d)",
|
||||
self._version, current_version,
|
||||
)
|
||||
return True
|
||||
|
||||
# Check 2: Member-Set mismatch (rooms added/removed without version bump)
|
||||
map_room_ids = set(
|
||||
rid for rid, entry in self._room_map.rooms.items()
|
||||
if not entry.catch_all
|
||||
)
|
||||
index_room_ids = set(self._room_ids)
|
||||
if map_room_ids != index_room_ids:
|
||||
missing_from_index = map_room_ids - index_room_ids
|
||||
extra_in_index = index_room_ids - map_room_ids
|
||||
logger.info(
|
||||
"RoomIndex stale: member-set mismatch — "
|
||||
"missing_from_index=%d, extra_in_index=%d",
|
||||
len(missing_from_index), len(extra_in_index),
|
||||
)
|
||||
if missing_from_index:
|
||||
logger.info(
|
||||
" Rooms NOT in index: %s",
|
||||
", ".join(f"{rid[:12]}…" for rid in sorted(missing_from_index)[:5]),
|
||||
)
|
||||
if extra_in_index:
|
||||
logger.info(
|
||||
" Rooms NOT in map (stale): %s",
|
||||
", ".join(f"{rid[:12]}…" for rid in sorted(extra_in_index)[:5]),
|
||||
)
|
||||
return True
|
||||
|
||||
return False
|
||||
|
||||
# ── Internal Helpers ────────────────────────────────────────────────
|
||||
|
||||
|
||||
Reference in New Issue
Block a user