feat(inbound): tell user when chat has no binding — routing never silent

First message on an unbound chat now shows which default agent will
handle it (+ /agents, /switch hints) before the turn runs.
This commit is contained in:
openbot committed 2026-10-13 17:50:24 +08:00
1 parent 69ea08ad44
commit 42b9b0ae8a
2 files changed
+13 -3

No files matched your search

+3 -2
View File
@@ -133,8 +133,9 @@ class WecomAibotChannel:
continue continue
msg = json.loads(raw) msg = json.loads(raw)
cmd = msg.get("cmd", "") cmd = msg.get("cmd", "")
if cmd: # skip ack/pong frames (no cmd? actually acks have no cmd) keys = sorted(msg.keys())
self._logger.info(f"[wecom] recv cmd={cmd} chatid={(msg.get('body') or {}).get('chatid')} msgtype={(msg.get('body') or {}).get('msgtype')}") if "aibot_msg_callback" in raw or "chatid" in raw:
self._logger.info(f"[wecom] recv keys={keys} cmd={cmd} chatid={(msg.get('body') or msg).get('chatid')} msgtype={(msg.get('body') or msg).get('msgtype')} text={str((msg.get('body') or msg).get('text'))[:60]}")
try: try:
self._dispatch(msg, ws) self._dispatch(msg, ws)
except Exception as e: # noqa: BLE001 except Exception as e: # noqa: BLE001
+10 -1
View File
@@ -124,7 +124,16 @@ def _safe_inbound(mgr: SessionManager, ch, m) -> None:
if res is not None: if res is not None:
_safe_event(ch, f"{ch.name}:{m.chat_id}", "command_result", res) _safe_event(ch, f"{ch.name}:{m.chat_id}", "command_result", res)
return return
# 3) normal prompt # 3) binding visibility: no binding yet -> tell the user which
# agent WILL handle this chat (auto-bound on first turn), so
# routing is never silent/mysterious
if mgr.get_binding(ch.name, m.chat_id) is None:
default = mgr._default_agent()
mgr._emit(f"{ch.name}:{m.chat_id}", "status", {
"text": f"当前会话尚未绑定 agent,将由默认 agent「{default}」处理"
"(如需指定其他 agent,回复 /agents 查看、/switch <名> 切换)。",
})
# 4) normal prompt
mgr.prompt(ch.name, m.chat_id, m.text, images=m.images) mgr.prompt(ch.name, m.chat_id, m.text, images=m.images)
except Exception as e: # noqa: BLE001 except Exception as e: # noqa: BLE001
import logging import logging