fix: block leaked tool output and thinking text

This commit is contained in:
2026-03-06 21:58:50 +08:00
parent 07053ce1ad
commit 3c52061861
2 changed files with 61 additions and 15 deletions

View File

@@ -27,6 +27,16 @@ _TRANSFER_CALM_REPLIES = [
"在催了在催了,马上哈",
]
_OUTBOUND_BLOCK_MARKERS = (
"【历史记录摘要】",
"【详细记录】",
"【订单摘要】",
"【订单详情】",
"<think",
"think_never_used",
'[{"name":',
)
class SystemOrchestrator:
"""
全系统总编排:具备转接冷却、防抖合并、多消息去重、以及精准日志。
@@ -64,6 +74,18 @@ class SystemOrchestrator:
self._user_locks[user_id] = asyncio.Lock()
return self._user_locks[user_id]
@staticmethod
def _sanitize_outbound_text(text: str) -> str:
if not text:
return ""
cleaned = str(text).strip()
if "[转移会话]" in cleaned:
return cleaned
if any(marker in cleaned for marker in _OUTBOUND_BLOCK_MARKERS):
logger.warning("[Orchestrator] 拦截到内部内容外发,替换为安全兜底回复")
return "我在帮你看记录,稍等哈"
return cleaned
async def on_raw_message_received(self, platform: str, raw_data: dict):
"""链路入口"""
try:
@@ -286,6 +308,7 @@ class SystemOrchestrator:
# E. 发送并记录时间
if std_res.should_reply:
std_res.reply_content = self._sanitize_outbound_text(std_res.reply_content)
std_res.metadata = {"acc_id": acc_id, "acc_type": acc_type}
# 转接场景:先发一句安抚话,再发转接指令