From 885439f3c4ebf87e0e229d00dee72ad826ff9bd3 Mon Sep 17 00:00:00 2001 From: hmo Date: Sat, 20 Jun 2026 01:31:04 +0800 Subject: [PATCH] refactor(xxm): use [YOU] prefix for TUI context (align with Hermes) --- gateway/scripts/chat_bridge.py | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/gateway/scripts/chat_bridge.py b/gateway/scripts/chat_bridge.py index 978eea3..f16a219 100644 --- a/gateway/scripts/chat_bridge.py +++ b/gateway/scripts/chat_bridge.py @@ -393,6 +393,19 @@ class SessionBridge: except Exception: return "" + def _format_tui_context(self, raw_ctx: str) -> str: + """Mark bot's own TUI messages with [YOU] so LLM recognises itself.""" + lines = [] + for line in raw_ctx.split("\n"): + line = line.strip() + if not line: + continue + if "小小莫" in line: + lines.append(f"[YOU] {line}") + else: + lines.append(line) + return "\n".join(lines) + def _append_to_log(self, role: str, content: str, source: str = "bridge"): try: entry = json.dumps( @@ -693,12 +706,7 @@ class SessionBridge: from session_router import extract_session_context tui_ctx = extract_session_context(tui_sid, limit=50) if tui_ctx: - sys_prompt += ( - "\n\n【你的 TUI 工作台最近对话】" - f"\n(老莫在 TUI 和你讨论这些时,转发了群聊消息," - f"请结合下面的 TUI 对话理解他在群里的意图。" - f"群聊和 TUI 是同一个人,两份上下文关联看)\n{tui_ctx}" - ) + sys_prompt += f"\n\n{self._format_tui_context(tui_ctx)}" except Exception: pass