feat: MULTIROOM_AGENT env switch for single-room mode

This commit is contained in:
Bernd (Hermes)
2026-06-22 10:12:07 +02:00
parent 4d6fae6bf7
commit a442e42b4e
2 changed files with 75 additions and 66 deletions
+2
View File
@@ -102,6 +102,8 @@ def is_connected(config) -> bool:
def register(ctx):
"""Plugin entry point — called by the Hermes plugin system at startup."""
_MULTIROOM = os.getenv("MULTIROOM_AGENT", "true").strip().lower() not in ("false", "0", "no", "off")
from .adapter import RocketChatAdapter # lazy import avoids circular deps
from .tools import register_tools
+10 -3
View File
@@ -35,6 +35,9 @@ class RocketChatRateLimitError(Exception):
_room_context: Dict[str, Dict[str, str]] = {} # chat_id → {thematic_target, origin_room}
_room_context_lock = threading.Lock()
_MULTIROOM = os.getenv("MULTIROOM_AGENT", "true").strip().lower() not in ("false", "0", "no", "off")
if _MULTIROOM:
from archivar.adapter_integration import ArchivarMessageHandler
# ── Access __init__ symbols (plugin loaded as flat module, no relative imports) ──
@@ -478,10 +481,13 @@ class RocketChatAdapter(BasePlatformAdapter):
self._last_ddp_ping_ok = False
self._running = False
# Archivar: Embedding-basierte Nachrichten-Klassifikation
if _MULTIROOM:
self.archivar = ArchivarMessageHandler(
send_callback=self._send_via_archivar,
button_send_callback=self._send_archivar_buttons,
)
else:
self.archivar = None
# User-Flow C: Move-Requests + Sticky Rooms
self._pending_move_requests: Dict[str, dict] = {}
self._sticky_rooms: Dict[str, float] = {} # room_id → timestamp
@@ -592,6 +598,7 @@ class RocketChatAdapter(BasePlatformAdapter):
len(self._user_rooms),
{k: f"{len(v)} rooms" for k, v in self._user_rooms.items()})
# Archivar initialisieren (Embedding-basierte Klassifikation)
if _MULTIROOM and self.archivar is not None:
try:
await self.archivar.initialize()
# Feed the actual subscribed room IDs to the router so it can
@@ -782,7 +789,7 @@ class RocketChatAdapter(BasePlatformAdapter):
logger.debug("[rocketchat] Error processing CLARIFY response: %s", e)
# Auto-Onboarding: Wenn onboarding_active, fange alle relevanten Antworten ab
if self.archivar._stats.get("onboarding_active", False):
if _MULTIROOM and self.archivar is not None and self.archivar._stats.get("onboarding_active", False):
stripped = text.strip()
# Nur Nachrichten aus dem Operator-DM-Raum als Onboarding behandeln
operator_room = self._onboarding_state.get("operator_room_id", "")
@@ -851,7 +858,7 @@ class RocketChatAdapter(BasePlatformAdapter):
feedback_type = "stay"
# Lernsystem: Keyword-Gewichte aus User-Entscheidung lernen
if move_req.get("message_id"):
if _MULTIROOM and self.archivar is not None and move_req.get("message_id"):
user_id = user_info.get("_id", "")
await self.archivar.handle_feedback_response(
message_id=move_req["message_id"],
@@ -871,6 +878,7 @@ class RocketChatAdapter(BasePlatformAdapter):
is_auftrag = _is_auftrag(text)
try:
if _MULTIROOM and self.archivar is not None:
if is_button_response or room_id in self._rooms_with_pending_questions:
if not is_button_response:
logger.debug("[rocketchat] Room %s had pending question — Archivar bypassed", room_id)
@@ -916,7 +924,6 @@ class RocketChatAdapter(BasePlatformAdapter):
logger.warning("[rocketchat] Archivar classify_and_route() timed out")
with _question_counter_lock:
_question_counter += 1
# _THEMATIC_TARGET_ROOM bleibt leer → Prompt sagt "Timeout"
except Exception as e:
logger.debug("[rocketchat] Archivar classification skipped: %s", e)