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
fix: 回合,加强最终回复提示词
xiaowenzihwl4218ce59f6a7
diff --git a/jiuwenswarm/agents/harness/common/prompt/prompt_builder.py b/jiuwenswarm/agents/harness/common/prompt/prompt_builder.pyindex 6a44d08664..7831332cf3 100644--- a/jiuwenswarm/agents/harness/common/prompt/prompt_builder.py+++ b/jiuwenswarm/agents/harness/common/prompt/prompt_builder.py@@ -31,17 +31,63 @@ class PromptPriority(IntEnum):A2UI = 61WORKSPACE = 70TODO = 85+ # final_visible_reply 放在 system 最末,强调约束工具/todo 结束后必须再发一轮完整纯文本 final;+ # UI 主要展示「最后一轮无 tool_calls」的正文。+ FINAL_VISIBLE_REPLY = 120class LocalSectionName:"""Local section names for optional JiuwenSwarm prompt sections."""A2UI = "a2ui"+ FINAL_VISIBLE_REPLY = "final_visible_reply"# ─── response section (shared by both modes via ResponsePromptRail) ───+def _final_visible_reply_prompt(language: str) -> PromptSection:+ if language == "cn":+ content = """# 最终可见回复(强制)++**哪一条算「最终可见」**:用户界面主要展示的是你**最后一轮** assistant 回复——即不再附带任何 `tool_calls`、以纯文本结束的那一轮。中间轮次(含工具调用的轮次)在 UI 中可能被折叠、分到另一条气泡,**但不影响你在这些轮次正常输出思考与进展**。++**轮次纪律(硬约束)**:+- 所有工具执行完毕后,**必须**再发一轮纯文本最终回复,写入完整、可独立理解的结果。+- 最终纯文本轮**不得**仅用「任务已完成」「以上已整理完毕」等收尾句代替正文;若前面某轮已写过说明,最终轮仍须**完整复述或等价概括**全部实质性结论,使用户只读这一条也能看懂。++**内容要求**(写在最后一轮纯文本中):+- 复述或概括用户需要的每一项实质性结果:重要命令输出、检查过的文件路径、变更的文件、发现、结论、错误、未解决风险,以及相关的后续步骤。+- 若用户要求你运行命令、检查数据、审查代码、比较方案、诊断故障或解释某事,须在最终回复中传达重要细节或概括关键行,使用户无需依赖折叠的工具输出也能理解结果。+- 若用户提出多部分问题,确保每一部分都有回答,或明确标注为未解决。+- 若创建或修改了文件,写出具体文件路径及变更内容。+- 若任务产出了可查看的交付物,仍须在回复中简要说明交付物包含什么或得出什么结论。+- 勿让回复超过 50–70 行而淹没用户;提供最高信号密度的上下文,而非穷举一切细节。+"""+ else:+ content = """## Final visible reply (mandatory)++**What counts as "final visible"**: The UI mainly shows your **last** assistant turn—the one that ends as plain text with **no** `tool_calls`. Earlier turns (including any that invoke tools) may be collapsed or split into a separate bubble, **but you should still write thinking and progress normally in those turns**.++**Turn discipline (hard rules)**:+- After all tools finish, you **must** send one more plain-text final turn with the full, self-contained result.+- The final plain-text turn **must not** be only a closing line such as "All tasks completed" or "Summarized above." If you already wrote the answer in an earlier turn, the final turn must still **fully restate or equivalently summarize** every substantive conclusion so the user understands by reading that turn alone.++**Content requirements** (in the last plain-text turn):+- Restate or summarize every substantive result the user needs: important command output, inspected file paths, changed files, findings, conclusions, errors, unresolved risks, and next steps when they matter.+- If the user asked you to run a command, inspect data, review code, compare options, diagnose a failure, or explain something, relay the important details or summarize the key lines in the final reply so the user understands the result without relying on collapsed tool output.+- If the user asked a multi-part question, make sure each part is answered or explicitly marked as unresolved.+- If files were created or modified, name the concrete files and what changed.+- If a task produced a viewable deliverable and present_files was used, still include a concise textual summary of what the deliverable contains or concludes.+- Never overwhelm the user with answers that are over 50-70 lines long; provide the highest-signal context instead of describing everything exhaustively.+"""+ return PromptSection(+ name=LocalSectionName.FINAL_VISIBLE_REPLY,+ content={language: content},+ priority=PromptPriority.FINAL_VISIBLE_REPLY,+ )++def _response_prompt(language: str) -> PromptSection:if language == "cn":content = """# 消息说明@@ -77,13 +123,6 @@ def _response_prompt(language: str) -> PromptSection:- **heartbeat**:心跳任务,如「检查待办」「同步状态」。系统任务完成后,以回复形式通知用户。--## 最终回复--- 用户最终看到的,只有你**最后一条不带任何工具调用的消息**;带工具调用的那一轮里写的正文不会作为最终结果呈现给用户。-- 因此,**完整的交付物(如完整方案、完整文档、完整结果)必须放在最后一条不带工具调用的消息里**。-- 不要把交付物正文和工具调用(包括 `todo` 状态更新等)写在同一条消息里——如果这样做,正文会丢失。正确做法是:先用一条消息完成必要的工具调用,再用最后一条不带工具调用的消息输出完整交付物。-- 不要只用“已完成”“全部完成”“以上方案已完成”“详见上文”等状态确认或指代来代替最终交付物;即使相关内容此前已经产出过,**也要在这最后一条消息里完整重述用户需要看到的内容**。"""else:content = """# Message Format@@ -119,17 +158,6 @@ You receive user messages and system messages; handle each by source and type.- **heartbeat**: Heartbeat tasks, e.g. "check todos", "sync status".After completing a system task, notify the user via a reply.--## Final Response--- The user only sees your **last message that contains no tool calls**.-- Body text written in a turn that also makes tool calls is NOT presented as the final result.-- Therefore, **the complete deliverable MUST be placed in your last message with no tool calls**.-- Do not put the deliverable body and a tool call in the same message; that body is lost.-- Correct pattern: first make the necessary tool calls, then output the complete deliverable- in a final message with no tool calls.-- Do not replace the final deliverable with "done", "all completed", "see above", or similar text.-- Even if the content appeared earlier, **restate everything the user needs to see in full**."""return PromptSection(name="response",diff --git a/jiuwenswarm/agents/harness/common/rails/response_prompt_rail.py b/jiuwenswarm/agents/harness/common/rails/response_prompt_rail.pyindex df3f746a21..fb0c2afc9a 100644--- a/jiuwenswarm/agents/harness/common/rails/response_prompt_rail.py+++ b/jiuwenswarm/agents/harness/common/rails/response_prompt_rail.py@@ -14,6 +14,7 @@ from jiuwenswarm.common.context_keys import JIUWENSWARM_CHANNEL_CONTEXT_KEYfrom jiuwenswarm.agents.harness.common.prompt.prompt_builder import (LocalSectionName,PromptPriority,+ _final_visible_reply_prompt,_response_prompt,)from jiuwenswarm.server.runtime.a2ui.prompt_instructions import (@@ -24,10 +25,11 @@ 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)class ResponsePromptRail(DeepAgentRail):- """Inject the response section as an independent prompt section."""+ """Inject response format and final-reply rules as independent prompt sections."""priority = 5@@ -41,7 +43,8 @@ class ResponsePromptRail(DeepAgentRail):def uninit(self, agent) -> None:if self.system_prompt_builder is not None:- self.system_prompt_builder.remove_section("response")+ for name in _RESPONSE_SECTION_NAMES:+ self.system_prompt_builder.remove_section(name)self.system_prompt_builder.remove_section(LocalSectionName.A2UI)self.system_prompt_builder = Noneself._runtime_channel = None@@ -74,6 +77,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(_final_visible_reply_prompt(language))self._sync_a2ui_prompt_section(self._resolve_channel(ctx),skip_a2ui=self._should_skip_a2ui(ctx),diff --git a/jiuwenswarm/agents/harness/common/rails/runtime_prompt_rail.py b/jiuwenswarm/agents/harness/common/rails/runtime_prompt_rail.pyindex 1fd4106cb8..4fedba56a3 100644--- a/jiuwenswarm/agents/harness/common/rails/runtime_prompt_rail.py+++ b/jiuwenswarm/agents/harness/common/rails/runtime_prompt_rail.py@@ -741,7 +741,7 @@ class RuntimePromptRail(DeepAgentRail):self.system_prompt_builder.add_section(PromptSection(name="request_system_prompt",content={"cn": self._request_system_prompt, "en": self._request_system_prompt},- priority=10_000,+ priority=110,))async def _upsert_prompt_attachment(