From 947bb1e6d04e927a06b0a4dd9bb14bfbf22007db Mon Sep 17 00:00:00 2001 From: mohe Date: Sat, 20 Jun 2026 01:48:37 +0800 Subject: [PATCH] intercept __SILENT__/__REPLY__ misuse in LLM response body --- xmpp_agent_core.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/xmpp_agent_core.py b/xmpp_agent_core.py index 764a1a0..12d95ad 100644 --- a/xmpp_agent_core.py +++ b/xmpp_agent_core.py @@ -190,9 +190,18 @@ class AgentBot(ClientXMPP): data = json.loads(result.read()) reply = data.get("choices", [{}])[0].get("message", {}).get("content", "") reply_stripped = reply.strip() + # 检查 __SILENT__ 标记 if reply_stripped.startswith('__SILENT__') or reply_stripped.startswith('`__SILENT__`'): logging.info(f"⏭️ {AGENT_NAME} 决定沉默,不发送") return + # 如果回复里任意位置出现了 __SILENT__,说明 LLM 没理解协议,整条作废 + if '__SILENT__' in reply: + logging.info(f"⏭️ {AGENT_NAME} 回复中误用 __SILENT__,拦截") + return + # 如果回复里出现了 __REPLY__,也是协议混淆,拦截 + if '__REPLY__' in reply: + logging.info(f"⏭️ {AGENT_NAME} 回复中误用 __REPLY__,拦截") + return # 额外拦截:LLM 说"我沉默""我不说了"等宣布沉默的话→当 SILENT 处理 _silent_phrases = ['我沉默', '我不说', '不说了', '不回复', '不插嘴', '我闭嘴', '闭嘴上', '沉默是', '彻底沉默', '我会沉默', '将保持沉默']