JiuwenSwarm is an intelligent AI Agent built on openJiuwen. It extends the powerful capabilities of large language models directly to your fingertips through various communication apps you use daily.
Python
feat(prompt): 注入思考纪律,抑制 reasoning 中誊写产物
renquanjiaee985e01a950
diff --git a/jiuwenswarm/agents/harness/common/prompt/prompt_builder.py b/jiuwenswarm/agents/harness/common/prompt/prompt_builder.pyindex 6a3ae456a0..718892297e 100644--- a/jiuwenswarm/agents/harness/common/prompt/prompt_builder.py+++ b/jiuwenswarm/agents/harness/common/prompt/prompt_builder.py@@ -33,6 +33,8 @@ class PromptPriority(IntEnum):A2UI = 61WORKSPACE = 70TODO = 85+ # thinking_discipline 紧挨最终可见回复之前:思考与 tool_calls 职责分工,高于 RESPONSE。+ THINKING_DISCIPLINE = 115# final_visible_reply 放在 system 最末,强调约束工具/todo 结束后必须再发一轮完整纯文本 final;# UI 主要展示「最后一轮无 tool_calls」的正文。FINAL_VISIBLE_REPLY = 120@@ -42,12 +44,51 @@ class LocalSectionName:"""Local section names for optional JiuwenSwarm prompt sections."""A2UI = "a2ui"+ THINKING_DISCIPLINE = "thinking_discipline"FINAL_VISIBLE_REPLY = "final_visible_reply"# ─── response section (shared by both modes via ResponsePromptRail) ───+def _thinking_discipline_prompt(language: str) -> PromptSection:+ if language == "cn":+ content = """# 思考纪律(强制,针对思考过程 reasoning_content)++思考过程与工具调用参数都会完整落盘并计费。思考的职责是**决策**——做什么、选哪个方案、注意哪些约束;产物的职责是**内容**。二者严禁重叠。++**硬规则(违反任何一条即为错误思考):**++1. **严禁誊写产物**:按要写入工具参数的具体内容——正文、JSON 字段与数值、表格逐行内容、bullet 每一条文案、长代码——只允许出现在 tool_calls 参数里。严禁在思考中以任何形式起草这些内容。+2. **严禁复述上下文**:对话历史、工具结果、素材、规格表中已有的内容,不要在思考中重抄或整理一遍。引用时只写编号或关键词(如「素材第2条」「模板第3节」),不抄原文。+3. **大纲简短 = 关键词行**:生成大段产物前,思考中的大纲每节只写一行关键词,不写完整句子。+ - ✅ 正确:[核心摘要:交付项 / 进行中项 / 风险项 / 下周目标]+ - ❌ 错误:[核心摘要:本周完成客户A三期需求评审,确认3个核心模块交付范围……。](这是把产物文案搬进思考)+4. **决策 = 结论 + 一句理由**:方案取舍(如表头设计、列数据选择)、约束核对(模糊词查询、日期排算)仍要思考,但每项一两行给出结论即可,不展开成文。+5. **思考预算**:单轮思考一般不超过 20 行。下一步动作已明确时,压缩到几行直接发起工具调用。+"""+ else:+ content = """# Thinking discipline (mandatory, for reasoning_content)++Both the thinking process and tool-call arguments are fully persisted and billed. Thinking is for **decisions**—what to do, which option to pick, which constraints to watch. Artifacts are for **content**. The two must not overlap.++**Hard rules (breaking any one is incorrect thinking):**++1. **Do not transcribe artifacts**: Concrete content destined for tool arguments—body text, JSON fields and values, table rows, each bullet's wording, long code—may appear only in `tool_calls` arguments. Never draft that content in thinking in any form.+2. **Do not restate context**: Do not recopy or reorganize dialogue history, tool results, source material, or spec tables. Cite by number or keyword only (e.g. "source item 2", "template section 3"); never paste the original.+3. **Outlines = keyword lines**: Before generating a long artifact, each outline section in thinking is one keyword line, not full sentences.+ - Correct: [Core summary: delivered / in progress / risks / next-week goals]+ - Wrong: [Core summary: This week finished the phase-3 review for customer A and confirmed the delivery scope of 3 core modules...] (that moves artifact copy into thinking)+4. **Decision = conclusion + one reason**: Tradeoffs (headers, column choices) and constraint checks (fuzzy-term lookup, date arithmetic) still belong in thinking, but one or two lines per item—do not expand into prose.+5. **Thinking budget**: Keep a single turn of thinking to about 20 lines. When the next action is already clear, compress to a few lines and issue the tool call.+"""+ return PromptSection(+ name=LocalSectionName.THINKING_DISCIPLINE,+ content={language: content},+ priority=PromptPriority.THINKING_DISCIPLINE,+ )++def _final_visible_reply_prompt(language: str) -> PromptSection:if language == "cn":content = """# 最终可见回复(强制)diff --git a/jiuwenswarm/agents/harness/common/rails/response_prompt_rail.py b/jiuwenswarm/agents/harness/common/rails/response_prompt_rail.pyindex fb0c2afc9a..cdb9bccf30 100644--- a/jiuwenswarm/agents/harness/common/rails/response_prompt_rail.py+++ b/jiuwenswarm/agents/harness/common/rails/response_prompt_rail.py@@ -16,6 +16,7 @@ from jiuwenswarm.agents.harness.common.prompt.prompt_builder import (PromptPriority,_final_visible_reply_prompt,_response_prompt,+ _thinking_discipline_prompt,)from jiuwenswarm.server.runtime.a2ui.prompt_instructions import (is_a2ui_browser_workflow_request,@@ -25,11 +26,15 @@ logger = logging.getLogger(__name__)SKIP_A2UI_PROMPT_CONTEXT_KEY = "skip_a2ui"A2UI_BROWSER_WORKFLOW_CONTEXT_KEY = "a2ui_browser_workflow"-_RESPONSE_SECTION_NAMES = ("response", LocalSectionName.FINAL_VISIBLE_REPLY)+_RESPONSE_SECTION_NAMES = (+ "response",+ LocalSectionName.THINKING_DISCIPLINE,+ LocalSectionName.FINAL_VISIBLE_REPLY,+)class ResponsePromptRail(DeepAgentRail):- """Inject response format and final-reply rules as independent prompt sections."""+ """Inject response format, thinking discipline, and final-reply rules."""priority = 5@@ -77,6 +82,7 @@ class ResponsePromptRail(DeepAgentRail):language = self.system_prompt_builder.language or "cn"self.system_prompt_builder.add_section(_response_prompt(language))+ self.system_prompt_builder.add_section(_thinking_discipline_prompt(language))self.system_prompt_builder.add_section(_final_visible_reply_prompt(language))self._sync_a2ui_prompt_section(self._resolve_channel(ctx),diff --git a/tests/unit_tests/agents/harness/common/test_thinking_discipline_prompt.py b/tests/unit_tests/agents/harness/common/test_thinking_discipline_prompt.pynew file mode 100644index 0000000000..ba638df35c--- /dev/null+++ b/tests/unit_tests/agents/harness/common/test_thinking_discipline_prompt.py@@ -0,0 +1,69 @@+# Copyright (c) Huawei Technologies Co., Ltd. 2026. All rights reserved.++"""Thinking-discipline prompt section: content, priority, and rail injection."""++from __future__ import annotations++from types import SimpleNamespace++import pytest+from openjiuwen.harness.prompts import SystemPromptBuilder++from jiuwenswarm.agents.harness.common.prompt.prompt_builder import (+ LocalSectionName,+ PromptPriority,+ _final_visible_reply_prompt,+ _thinking_discipline_prompt,+)+from jiuwenswarm.agents.harness.common.rails.response_prompt_rail import ResponsePromptRail+++def test_thinking_discipline_sits_before_final_visible_reply():+ section = _thinking_discipline_prompt("cn")+ assert section.name == LocalSectionName.THINKING_DISCIPLINE+ assert PromptPriority.RESPONSE < section.priority < PromptPriority.FINAL_VISIBLE_REPLY+ assert section.priority < _final_visible_reply_prompt("cn").priority+++def test_thinking_discipline_cn_covers_hard_rules():+ content = _thinking_discipline_prompt("cn").content["cn"]+ assert "# 思考纪律" in content+ assert "严禁誊写产物" in content+ assert "严禁复述上下文" in content+ assert "思考预算" in content+ assert "tool_calls" in content+++def test_thinking_discipline_en_covers_hard_rules():+ content = _thinking_discipline_prompt("en").content["en"]+ assert "# Thinking discipline" in content+ assert "Do not transcribe artifacts" in content+ assert "Do not restate context" in content+ assert "Thinking budget" in content+ assert "tool_calls" in content+++def test_assembled_prompt_places_discipline_before_final_reply():+ builder = SystemPromptBuilder(language="cn")+ builder.add_section(_thinking_discipline_prompt("cn"))+ builder.add_section(_final_visible_reply_prompt("cn"))+ prompt = builder.build()+ assert prompt.index("思考纪律") < prompt.index("最终可见回复")+++async def test_response_prompt_rail_injects_thinking_discipline():+ rail = ResponsePromptRail()+ builder = SystemPromptBuilder(language="cn")+ rail.init(SimpleNamespace(system_prompt_builder=builder))++ await rail.before_model_call(SimpleNamespace(inputs={"channel": "feishu"}))++ assert builder.get_section(LocalSectionName.THINKING_DISCIPLINE) is not None+ assert builder.get_section(LocalSectionName.FINAL_VISIBLE_REPLY) is not None+ prompt = builder.build()+ assert prompt.index("思考纪律") < prompt.index("最终可见回复")++ rail.uninit(None)+ assert builder.get_section(LocalSectionName.THINKING_DISCIPLINE) is None+ assert builder.get_section(LocalSectionName.FINAL_VISIBLE_REPLY) is None