From 5a9fe871fe3f9e028d5f0c68f04aa80d8050af94 Mon Sep 17 00:00:00 2001 From: "Yuyao Huang (Sam)" Date: Sun, 29 Mar 2026 19:11:56 +0800 Subject: [PATCH] =?UTF-8?q?feat(router):=20=E5=9C=A8=E8=B7=AF=E7=94=B1?= =?UTF-8?q?=E6=A8=A1=E5=BC=8F=E4=B8=8B=E4=BB=85=E5=A4=84=E7=90=86=E7=89=B9?= =?UTF-8?q?=E5=AE=9A=E5=91=BD=E4=BB=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 在路由模式下,本地仅处理路由相关命令(/nodes, /node, /help等),其他会话命令直接转发到节点。同时优化路由代理逻辑,对于会话命令直接转发到活跃节点,减少不必要的LLM调用。 --- bot/commands.py | 6 ++++++ router/routing_agent.py | 9 ++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/bot/commands.py b/bot/commands.py index 9441c33..e48e2d9 100644 --- a/bot/commands.py +++ b/bot/commands.py @@ -67,6 +67,12 @@ async def handle_command(user_id: str, text: str) -> Optional[str]: cmd, args = parsed logger.info("Command: %s args=%r user=...%s", cmd, args[:50], user_id[-8:]) + # In ROUTER_MODE, only handle router-specific commands locally. + # Session commands (/status, /new, /close, etc.) fall through to node forwarding. + from config import ROUTER_MODE + if ROUTER_MODE and cmd not in ("/nodes", "/node", "/help", "/h", "/?"): + return None + set_current_user(user_id) if cmd in ("/new", "/n"): diff --git a/router/routing_agent.py b/router/routing_agent.py index 8fa7314..6ea8241 100644 --- a/router/routing_agent.py +++ b/router/routing_agent.py @@ -77,7 +77,14 @@ async def route(user_id: str, chat_id: str, text: str) -> tuple[Optional[str], s return online_nodes[0].node_id, "Only one node available" if text.strip().startswith("/"): - return "meta", "Meta command" + cmd = text.strip().split()[0].lower() + if cmd in ("/nodes", "/node", "/help", "/h", "/?"): + return "meta", "Meta command" + # Session commands: forward to active node directly (no LLM call needed) + active = registry.get_active_node(user_id) + if active: + return active.node_id, "Forwarding command to active node" + return online_nodes[0].node_id, "Forwarding command to first available node" active_node = registry.get_active_node(user_id) active_node_id = active_node.node_id if active_node else None