feat(命令): 添加直接模式和智能模式切换功能

- 在 OrchestrationAgent 中添加 passthrough 状态管理
- 新增 /direct 和 /smart 命令用于切换模式
- 修改 /list 命令为 /status 并显示当前模式状态
- 更新帮助信息包含新模式命令
This commit is contained in:
Yuyao Huang (Sam)
2026-03-28 12:33:41 +08:00
parent 5d55d01f40
commit de6205d2fd
2 changed files with 42 additions and 9 deletions
+10 -2
View File
@@ -74,6 +74,8 @@ class OrchestrationAgent:
self._active_conv: Dict[str, Optional[str]] = defaultdict(lambda: None)
# user_id -> asyncio.Lock (prevents concurrent processing per user)
self._user_locks: Dict[str, asyncio.Lock] = defaultdict(asyncio.Lock)
# user_id -> passthrough mode enabled
self._passthrough: Dict[str, bool] = defaultdict(lambda: False)
def _build_system_prompt(self, user_id: str) -> str:
conv_id = self._active_conv[user_id]
@@ -89,6 +91,12 @@ class OrchestrationAgent:
def get_active_conv(self, user_id: str) -> Optional[str]:
return self._active_conv.get(user_id)
def get_passthrough(self, user_id: str) -> bool:
return self._passthrough.get(user_id, False)
def set_passthrough(self, user_id: str, enabled: bool) -> None:
self._passthrough[user_id] = enabled
async def run(self, user_id: str, text: str) -> str:
"""Process a user message and return the agent's reply."""
async with self._user_locks[user_id]:
@@ -102,8 +110,8 @@ class OrchestrationAgent:
logger.info(">>> user=...%s conv=%s msg=%r", short_uid, active_conv, text[:80])
logger.debug(" history_len=%d", len(self._history[user_id]))
# Passthrough mode: if active session, bypass LLM (bot commands handled earlier)
if active_conv:
# Passthrough mode: if enabled and active session, bypass LLM
if self._passthrough[user_id] and active_conv:
try:
reply = await manager.send(active_conv, text, user_id=user_id)
logger.info("<<< [passthrough] reply: %r", reply[:120])