Browse Source

fix(core): force book-mode agent to use deterministic writing tools

Ma 6 months ago
parent
commit
7ab07a6fa3

+ 2 - 3
packages/core/src/__tests__/agent-system-prompt.test.ts

@@ -42,7 +42,7 @@ describe("buildAgentSystemPrompt", () => {
   });
 
   describe("with book (writing flow)", () => {
-    it("Chinese prompt includes all tools except architect", () => {
+    it("Chinese prompt includes deterministic writing tools except architect", () => {
       const prompt = buildAgentSystemPrompt("my-book", "zh");
       expect(prompt).toContain("my-book");
       expect(prompt).toContain("sub_agent");
@@ -54,7 +54,6 @@ describe("buildAgentSystemPrompt", () => {
       expect(prompt).toContain("write_truth_file");
       expect(prompt).toContain("rename_entity");
       expect(prompt).toContain("patch_chapter_text");
-      expect(prompt).toContain("edit");
       expect(prompt).toContain("grep");
       expect(prompt).toContain("ls");
     });
@@ -65,7 +64,7 @@ describe("buildAgentSystemPrompt", () => {
       expect(prompt).toContain("write_truth_file");
       expect(prompt).toContain("用户要求重写/精修已有章节");
       expect(prompt).toContain("revise_chapter");
-      expect(prompt).toContain("不要再用 edit 处理真相文件或章节重写");
+      expect(prompt).not.toContain("edit");
     });
 
     it("Chinese prompt warns NOT to call architect", () => {

+ 0 - 1
packages/core/src/agent/agent-session.ts

@@ -240,7 +240,6 @@ export async function runAgentSession(
           createWriteTruthFileTool(pipeline, projectRoot, bookId),
           createRenameEntityTool(pipeline, projectRoot, bookId),
           createPatchChapterTextTool(pipeline, projectRoot, bookId),
-          createEditTool(projectRoot),
           createGrepTool(projectRoot),
           createLsTool(projectRoot),
         ],

+ 1 - 5
packages/core/src/agent/agent-system-prompt.ts

@@ -78,7 +78,6 @@ export function buildAgentSystemPrompt(bookId: string | null, language: string):
 - **write_truth_file** — 整文件覆盖真相文件(story_bible、volume_outline、book_rules、current_focus 等)
 - **rename_entity** — 统一改角色/实体名
 - **patch_chapter_text** — 对已有章节做局部定点修补
-- **edit** — 通用精确字符串替换,仅作为兜底;不要用它处理真相文件或章节重写
 - **grep** — 搜索内容(如"哪一章提到了某个角色")
 - **ls** — 列出文件或章节
 
@@ -86,11 +85,10 @@ export function buildAgentSystemPrompt(bookId: string | null, language: string):
 
 - 写章节、修订、审计等重操作 → 使用 sub_agent 委托对应子智能体
 - 用户问设定相关问题 → 先用 read 读取对应文件再回答
-- 用户想改设定/改真相文件 → 优先用 write_truth_file,不要再用 edit 处理真相文件或章节重写
+- 用户想改设定/改真相文件 → 优先用 write_truth_file
 - 用户要求重写/精修已有章节 → 用 revise_chapter
 - 用户要求角色或实体改名 → 用 rename_entity
 - 用户要求对某一章做局部小修 → 用 patch_chapter_text
-- edit 只留给非 canonical 文件的小范围精确替换
 - 其他情况 → 直接对话回答
 - **注意:不要调用 architect,当前已有书籍,不需要建书**
 - **不要在回复中添加表情符号**
@@ -126,7 +124,6 @@ export function buildAgentSystemPrompt(bookId: string | null, language: string):
 - **write_truth_file** — Replace a canonical truth file in story/
 - **rename_entity** — Rename a character or entity across the book
 - **patch_chapter_text** — Apply a local deterministic patch to a chapter
-- **edit** — Exact string replacement fallback only; do not use it for truth files or chapter rewrites
 - **grep** — Search content across chapters
 - **ls** — List files or chapters
 
@@ -138,7 +135,6 @@ export function buildAgentSystemPrompt(bookId: string | null, language: string):
 - Use revise_chapter for rewrite/polish/rework of existing chapters
 - Use rename_entity for character/entity renames
 - Use patch_chapter_text for local chapter fixes
-- Keep edit as a last-resort fallback for non-canonical files
 - Chat directly for other questions
 - **Do NOT call architect — a book already exists**
 - **Do NOT use emoji in your responses**