fix: summary提取与fold_turns防误切,强化thinking模型summary输出

This commit is contained in:
Liang Jiaqing
2026-04-26 00:01:42 +08:00
parent 69f66997fd
commit cd0ce4d9b0
4 changed files with 9 additions and 5 deletions

View File

@@ -1,6 +1,6 @@
# Role: 物理级全能执行者 # Role: 物理级全能执行者
你拥有文件读写、脚本执行、用户浏览器JS注入、系统级干预的物理操作权限。禁止推诿"无法操作"——不空想,用工具探测。 你拥有文件读写、脚本执行、用户浏览器JS注入、系统级干预的物理操作权限。禁止推诿"无法操作"——不空想,用工具探测。
## 行动原则 ## 行动原则
调用工具前在<thinking>内推演:当前阶段、上步结果是否符合预期、下步策略;<summary>输出极简总结。 调用工具前推演:当前阶段、上步结果是否符合预期、下步策略;回复文本中用<summary>输出极简总结。
- 探测优先:失败时先充分获取信息(日志/状态/上下文),关键信息存入工作记忆,再决定重试或换方案。不可逆操作先询问用户。 - 探测优先:失败时先充分获取信息(日志/状态/上下文),关键信息存入工作记忆,再决定重试或换方案。不可逆操作先询问用户。
- 失败升级1次→读错误理解原因2次→探测环境状态3次→深度分析后换方案或问用户。禁止无新信息的重复操作。 - 失败升级1次→读错误理解原因2次→探测环境状态3次→深度分析后换方案或问用户。禁止无新信息的重复操作。

View File

@@ -2,6 +2,6 @@
You have full physical access: file I/O, script execution, browser JS injection, and system-level intervention. Never deflect with "can't do it" — don't speculate, use tools to probe. You have full physical access: file I/O, script execution, browser JS injection, and system-level intervention. Never deflect with "can't do it" — don't speculate, use tools to probe.
Summarize and reply in user's language or follow user's prompt. Summarize and reply in user's language or follow user's prompt.
## Action Principles ## Action Principles
Before each tool call, reason inside <thinking>: current phase, whether the last result met expectations, and next strategy. Before each tool call, reason: current phase, whether the last result met expectations, and next strategy and <summary> in reply text of each turn.
- Probe first: on failure, gather sufficient info (logs/status/context), store key findings in working memory, then decide to retry or pivot. Ask the user before irreversible operations. - Probe first: on failure, gather sufficient info (logs/status/context), store key findings in working memory, then decide to retry or pivot. Ask the user before irreversible operations.
- Failure escalation: 1st fail → read error and understand cause; 2nd → probe environment state; 3rd → deep analysis then switch approach or ask user. Never repeat an action without new information. - Failure escalation: 1st fail → read error and understand cause; 2nd → probe environment state; 3rd → deep analysis then switch approach or ask user. Never repeat an action without new information.

View File

@@ -92,7 +92,11 @@ with st.sidebar: render_sidebar()
def fold_turns(text): def fold_turns(text):
"""Return list of segments: [{'type':'text','content':...}, {'type':'fold','title':...,'content':...}]""" """Return list of segments: [{'type':'text','content':...}, {'type':'fold','title':...,'content':...}]"""
parts = re.split(r'(\**LLM Running \(Turn \d+\) \.\.\.\*\**)', text) # 先把4+反引号块替换为占位符避免误切子agent嵌套的 LLM Running
_ph = []
safe = re.sub(r'`{4,}.*?`{4,}', lambda m: (_ph.append(m.group(0)), f'\x00PH{len(_ph)-1}\x00')[1], text, flags=re.DOTALL)
parts = re.split(r'(\**LLM Running \(Turn \d+\) \.\.\.\*\**)', safe)
parts = [re.sub(r'\x00PH(\d+)\x00', lambda m: _ph[int(m.group(1))], p) for p in parts]
if len(parts) < 4: return [{'type': 'text', 'content': text}] if len(parts) < 4: return [{'type': 'text', 'content': text}]
segments = [] segments = []
if parts[0].strip(): segments.append({'type': 'text', 'content': parts[0]}) if parts[0].strip(): segments.append({'type': 'text', 'content': parts[0]})
@@ -103,7 +107,7 @@ def fold_turns(text):
turns.append((marker, content)) turns.append((marker, content))
for idx, (marker, content) in enumerate(turns): for idx, (marker, content) in enumerate(turns):
if idx < len(turns) - 1: if idx < len(turns) - 1:
_c = re.sub(r'```.*?```|<thinking>.*?</thinking>', '', content, flags=re.DOTALL) _c = re.sub(r'`{3,}.*?`{3,}|<thinking>.*?</thinking>', '', content, flags=re.DOTALL)
matches = re.findall(r'<summary>\s*((?:(?!<summary>).)*?)\s*</summary>', _c, re.DOTALL) matches = re.findall(r'<summary>\s*((?:(?!<summary>).)*?)\s*</summary>', _c, re.DOTALL)
if matches: if matches:
title = matches[0].strip() title = matches[0].strip()

View File

@@ -944,7 +944,7 @@ class MixinSession:
THINKING_PROMPT_ZH = """ THINKING_PROMPT_ZH = """
### 行动规范(持续有效) ### 行动规范(持续有效)
每次回复先在回复文字中包含一个<summary></summary> 中输出极简单行(<30字物理快照上次结果新信息+本次意图。此内容进入长期工作记忆。 每次回复(含工具调用轮)都先在回复文字中包含一个<summary></summary> 中输出极简单行(<30字物理快照上次结果新信息+本次意图。此内容进入长期工作记忆。
\n**若用户需求未完成,必须进行工具调用!** \n**若用户需求未完成,必须进行工具调用!**
""".strip() """.strip()
THINKING_PROMPT_EN = """ THINKING_PROMPT_EN = """