feat(archivar): Vierter Baustein — Agent-Antwortziel via Archivar-Kontext
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).
This commit is contained in:
+34
-20
@@ -1328,27 +1328,34 @@ class RocketChatAdapter(BasePlatformAdapter):
|
|||||||
# We must resolve it to a real Rocket.Chat room_id for REST API.
|
# We must resolve it to a real Rocket.Chat room_id for REST API.
|
||||||
real_room_id = chat_id
|
real_room_id = chat_id
|
||||||
if chat_id.startswith("user:"):
|
if chat_id.startswith("user:"):
|
||||||
# Priority 1: ContextVar from the message that triggered this turn
|
# Priority 0: Archivar-Kontext — wenn der Archivar einen thematischen
|
||||||
origin = _CURRENT_ORIGIN_ROOM.get()
|
# Zielraum gesetzt hat, geht die Antwort dorthin (Agent-Autonomie).
|
||||||
if origin:
|
thematic_target = _THEMATIC_TARGET_ROOM.get()
|
||||||
real_room_id = origin
|
if thematic_target and thematic_target != _CURRENT_ORIGIN_ROOM.get():
|
||||||
logger.debug("[rocketchat] send via ContextVar: %s → %s", chat_id, real_room_id)
|
real_room_id = thematic_target
|
||||||
|
logger.debug("[rocketchat] send via Archivar target: %s → %s", chat_id, real_room_id)
|
||||||
else:
|
else:
|
||||||
# Priority 2: proaktive Nachricht — use most recent room for this user
|
# Priority 1: ContextVar from the message that triggered this turn
|
||||||
rooms = self._user_rooms.get(chat_id, [])
|
origin = _CURRENT_ORIGIN_ROOM.get()
|
||||||
if rooms:
|
if origin:
|
||||||
real_room_id = rooms[-1] # last room user was active in
|
real_room_id = origin
|
||||||
logger.debug("[rocketchat] send via user_map (proactive): %s → %s", chat_id, real_room_id)
|
logger.debug("[rocketchat] send via ContextVar: %s → %s", chat_id, real_room_id)
|
||||||
else:
|
else:
|
||||||
# Fallback: try to find any room with recent activity involving this user
|
# Priority 2: proaktive Nachricht — use most recent room for this user
|
||||||
logger.warning("[rocketchat] No mapped room for %s, attempting fallback", chat_id)
|
rooms = self._user_rooms.get(chat_id, [])
|
||||||
fallback_room = self._find_fallback_room_for_user(chat_id)
|
if rooms:
|
||||||
if fallback_room:
|
real_room_id = rooms[-1] # last room user was active in
|
||||||
real_room_id = fallback_room
|
logger.debug("[rocketchat] send via user_map (proactive): %s → %s", chat_id, real_room_id)
|
||||||
logger.info("[rocketchat] Using fallback room %s for %s", fallback_room, chat_id)
|
|
||||||
else:
|
else:
|
||||||
logger.error("[rocketchat] No real room for %s, cannot send", chat_id)
|
# Fallback: try to find any room with recent activity involving this user
|
||||||
return SendResult(success=False, error=f"No real room for virtual chat_id {chat_id}")
|
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 ──
|
# ── Minimal-Fix: Parse [[BUTTONS:...]] markup from agent response text ──
|
||||||
# This allows the agent to request buttons by embedding markup in its
|
# 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.
|
# We must resolve it to a real Rocket.Chat room_id for REST API.
|
||||||
real_room_id = chat_id
|
real_room_id = chat_id
|
||||||
if chat_id.startswith("user:"):
|
if chat_id.startswith("user:"):
|
||||||
# Priority 1: ContextVar from the message that triggered this turn
|
# Priority 0: Archivar-Kontext — wenn der Archivar einen thematischen
|
||||||
origin = _CURRENT_ORIGIN_ROOM.get()
|
# 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:
|
if origin:
|
||||||
real_room_id = origin
|
real_room_id = origin
|
||||||
logger.debug("[rocketchat] send via ContextVar: %s → %s", chat_id, real_room_id)
|
logger.debug("[rocketchat] send via ContextVar: %s → %s", chat_id, real_room_id)
|
||||||
|
|||||||
Reference in New Issue
Block a user