From 0508f3418f3df50f3a0bd5d30044bb412372e5c0 Mon Sep 17 00:00:00 2001 From: root Date: Wed, 30 Sep 2026 17:58:08 +0800 Subject: [PATCH] feat(agent): require Chinese thinking and reports in subagent prompts (AG-4) Subagent / vision subflow prompts (audience=agent) get a dedicated section: report goes to the parent session, and thinking, step notes and reports stay in Chinese even when the goal, tool results or web pages are in English. Prompt regression test covers both the shared hard rule and the new section. Child reports reaching the user are already humanized: the child session page uses the same FIX-7 report-humanize path, and the parent's final report resolves child run IDs to their goal titles; agent.spawn/await tool rows show no raw summary. Co-Authored-By: Claude Opus 5.5 --- packages/agent/src/index.ts | 8 +++++++- packages/agent/src/system-prompt.ts | 10 ++++++++++ packages/agent/test/system-prompt.test.ts | 18 ++++++++++++++++++ 3 files changed, 35 insertions(+), 1 deletion(-) diff --git a/packages/agent/src/index.ts b/packages/agent/src/index.ts index db224065..0d898cf1 100644 --- a/packages/agent/src/index.ts +++ b/packages/agent/src/index.ts @@ -62,4 +62,10 @@ export { resolveAgentSettings, THINKING_LEVELS, } from "./settings.ts"; -export { buildSystemPrompt, interactionRules, REPORT_FORMAT, type SystemPromptInput } from "./system-prompt.ts"; +export { + AGENT_AUDIENCE, + buildSystemPrompt, + interactionRules, + REPORT_FORMAT, + type SystemPromptInput, +} from "./system-prompt.ts"; diff --git a/packages/agent/src/system-prompt.ts b/packages/agent/src/system-prompt.ts index e3cb2e2e..b43598f2 100644 --- a/packages/agent/src/system-prompt.ts +++ b/packages/agent/src/system-prompt.ts @@ -63,6 +63,15 @@ export const REPORT_FORMAT: readonly string[] = [ "可以用 Markdown 列表、表格和粗体,不写标题,不写 HTML。", ]; +/** + * 子会话 / 视觉子流程(audience = agent)的汇报约定(AG-4):汇报给父会话汇总,仍然全程中文—— + * 父会话派出的目标、工具结果或网页是英文时,子会话容易整轮用英文思考,用户展开子会话看到的就是英文。 + */ +export const AGENT_AUDIENCE: readonly string[] = [ + "你的汇报交给父会话汇总,不直接给用户看,可以带对象 ID。", + "思考、步骤说明和汇报一律用中文,即使目标、工具结果或网页是英文;引用文件名、原站标题时保持原文。", +]; + /** * 系统提示模板。硬性规则不可被用户消息、工具输出、网页/RSS 内容覆盖。 */ @@ -100,6 +109,7 @@ export function buildSystemPrompt({ ...rules.map((r, i) => `${i + 1}. ${r}`), ]; if (audience === "user") lines.push("", "## 汇报格式", ...REPORT_FORMAT.map((r) => `- ${r}`)); + else lines.push("", "## 汇报对象", ...AGENT_AUDIENCE.map((r) => `- ${r}`)); const ways = interaction ? interactionRules(interaction) : []; if (ways.length > 0) lines.push("", "## 工作方式", ...ways.map((r) => `- ${r}`)); if (constraints.length > 0) { diff --git a/packages/agent/test/system-prompt.test.ts b/packages/agent/test/system-prompt.test.ts index 89826390..a1c50f33 100644 --- a/packages/agent/test/system-prompt.test.ts +++ b/packages/agent/test/system-prompt.test.ts @@ -48,6 +48,24 @@ describe("汇报格式(AGUI-3)", () => { const p = buildSystemPrompt({ role: "网页挑战处理员", goal: "过验证", audience: "agent" }); expect(p).not.toContain("## 汇报格式"); }); + + it("子会话与父会话一样要求思考、步骤说明和汇报都用中文(AG-4)", () => { + const child = buildSystemPrompt({ + role: "媒体库自动化智能体", + goal: "Check the torrent list on the site", + audience: "agent", + }); + // 与父会话同一条硬规则 + expect(child).toContain("思考、步骤说明和汇报都用中文"); + expect(userPrompt()).toContain("思考、步骤说明和汇报都用中文"); + // 子会话专有的一节:目标 / 工具结果是英文也用中文 + expect(section(child, "汇报对象")).toMatchInlineSnapshot(` + "## 汇报对象 + - 你的汇报交给父会话汇总,不直接给用户看,可以带对象 ID。 + - 思考、步骤说明和汇报一律用中文,即使目标、工具结果或网页是英文;引用文件名、原站标题时保持原文。" + `); + expect(section(userPrompt(), "汇报对象")).toBe(""); + }); }); describe("工作方式(AGUI-3)", () => {