From b05b1ab1ec3f76b9971d943185f1bd4d240e6724 Mon Sep 17 00:00:00 2001 From: "Bernd (Hermes)" Date: Sun, 14 Jun 2026 19:41:19 +0200 Subject: [PATCH] =?UTF-8?q?feat(archivar):=20Vierter=20Baustein=20?= =?UTF-8?q?=E2=80=94=20Agent-Antwortziel=20via=20Archivar-Kontext?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Option C (Adapter routet Antwort automatisch um): Priority 0 im Virtual→Real Room Translation: Wenn _THEMATIC_TARGET_ROOM gesetzt ist und vom Ursprungsraum abweicht, geht die Antwort dorthin. Null Core-Impact, +8 Zeilen in adapter.py, kein Prompt-Cache-Break. Der Agent antwortet wie bisher — der Adapter lenkt um. Flow: Agent sendet Antwort → Adapter prüft _THEMATIC_TARGET_ROOM → gesetzt? → Zielraum. Sonst → _CURRENT_ORIGIN_ROOM (wie bisher). --- plugin/adapter.py | 54 +++++++++++++++++++++++++++++------------------ 1 file changed, 34 insertions(+), 20 deletions(-) diff --git a/plugin/adapter.py b/plugin/adapter.py index 90a7a45..be9abe6 100644 --- a/plugin/adapter.py +++ b/plugin/adapter.py @@ -1328,27 +1328,34 @@ class RocketChatAdapter(BasePlatformAdapter): # We must resolve it to a real Rocket.Chat room_id for REST API. real_room_id = chat_id if chat_id.startswith("user:"): - # Priority 1: ContextVar from the message that triggered this turn - origin = _CURRENT_ORIGIN_ROOM.get() - if origin: - real_room_id = origin - logger.debug("[rocketchat] send via ContextVar: %s → %s", chat_id, real_room_id) + # Priority 0: Archivar-Kontext — wenn der Archivar einen thematischen + # Zielraum gesetzt hat, geht die Antwort dorthin (Agent-Autonomie). + thematic_target = _THEMATIC_TARGET_ROOM.get() + if thematic_target and thematic_target != _CURRENT_ORIGIN_ROOM.get(): + real_room_id = thematic_target + logger.debug("[rocketchat] send via Archivar target: %s → %s", chat_id, real_room_id) else: - # Priority 2: proaktive Nachricht — use most recent room for this user - rooms = self._user_rooms.get(chat_id, []) - if rooms: - real_room_id = rooms[-1] # last room user was active in - logger.debug("[rocketchat] send via user_map (proactive): %s → %s", chat_id, real_room_id) + # Priority 1: ContextVar from the message that triggered this turn + origin = _CURRENT_ORIGIN_ROOM.get() + if origin: + real_room_id = origin + logger.debug("[rocketchat] send via ContextVar: %s → %s", chat_id, real_room_id) else: - # Fallback: try to find any room with recent activity involving this user - logger.warning("[rocketchat] No mapped room for %s, attempting fallback", chat_id) - fallback_room = self._find_fallback_room_for_user(chat_id) - if fallback_room: - real_room_id = fallback_room - logger.info("[rocketchat] Using fallback room %s for %s", fallback_room, chat_id) + # Priority 2: proaktive Nachricht — use most recent room for this user + rooms = self._user_rooms.get(chat_id, []) + if rooms: + real_room_id = rooms[-1] # last room user was active in + logger.debug("[rocketchat] send via user_map (proactive): %s → %s", chat_id, real_room_id) else: - logger.error("[rocketchat] No real room for %s, cannot send", chat_id) - return SendResult(success=False, error=f"No real room for virtual chat_id {chat_id}") + # Fallback: try to find any room with recent activity involving this user + logger.warning("[rocketchat] No mapped room for %s, attempting fallback", chat_id) + fallback_room = self._find_fallback_room_for_user(chat_id) + if fallback_room: + real_room_id = fallback_room + logger.info("[rocketchat] Using fallback room %s for %s", fallback_room, chat_id) + else: + logger.error("[rocketchat] No real room for %s, cannot send", chat_id) + return SendResult(success=False, error=f"No real room for virtual chat_id {chat_id}") # ── Minimal-Fix: Parse [[BUTTONS:...]] markup from agent response text ── # This allows the agent to request buttons by embedding markup in its @@ -1528,8 +1535,15 @@ class RocketChatAdapter(BasePlatformAdapter): # We must resolve it to a real Rocket.Chat room_id for REST API. real_room_id = chat_id if chat_id.startswith("user:"): - # Priority 1: ContextVar from the message that triggered this turn - origin = _CURRENT_ORIGIN_ROOM.get() + # Priority 0: Archivar-Kontext — wenn der Archivar einen thematischen + # Zielraum gesetzt hat, geht die Antwort dorthin (Agent-Autonomie). + thematic_target = _THEMATIC_TARGET_ROOM.get() + if thematic_target and thematic_target != _CURRENT_ORIGIN_ROOM.get(): + real_room_id = thematic_target + logger.debug("[rocketchat] send via Archivar target: %s → %s", chat_id, real_room_id) + else: + # Priority 1: ContextVar from the message that triggered this turn + origin = _CURRENT_ORIGIN_ROOM.get() if origin: real_room_id = origin logger.debug("[rocketchat] send via ContextVar: %s → %s", chat_id, real_room_id)