Ver Fonte

feat(core): add chapterNumber param to sub_agent tool for auditor/reviser

Previously auditor and reviser always operated on the latest chapter.
Now the agent can pass an explicit chapterNumber so "重写第5章" targets
chapter 5 instead of always hitting the latest.

- Added chapterNumber to SubAgentParams schema
- auditor: pipeline.auditDraft(bookId, chapterNumber)
- reviser: pipeline.reviseDraft(bookId, chapterNumber, mode)
- Updated system prompt to document the parameter

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
fanghanjun há 6 meses atrás
pai
commit
17d1f9b967

+ 6 - 4
packages/core/src/agent/agent-system-prompt.ts

@@ -70,9 +70,10 @@ export function buildAgentSystemPrompt(bookId: string | null, language: string):
 
 - **sub_agent** — 委托子智能体执行重操作:
   - agent="writer" 写下一章
-  - agent="auditor" 审计章节质量
-  - agent="reviser" 修订章节
+  - agent="auditor" 审计章节质量(可指定 chapterNumber)
+  - agent="reviser" 修订章节(可指定 chapterNumber 和修订模式)
   - agent="exporter" 导出书籍
+  - **chapterNumber 参数**:auditor 和 reviser 支持指定章节号,不指定则默认最新章节
 - **read** — 读取书籍的设定文件或章节内容
 - **edit** — 编辑设定文件(如修改角色名、调整世界观)
 - **grep** — 搜索内容(如"哪一章提到了某个角色")
@@ -110,9 +111,10 @@ export function buildAgentSystemPrompt(bookId: string | null, language: string):
 
 - **sub_agent** — Delegate to sub-agents:
   - agent="writer" for writing next chapter
-  - agent="auditor" for chapter quality audit
-  - agent="reviser" for chapter revision
+  - agent="auditor" for chapter quality audit (supports chapterNumber)
+  - agent="reviser" for chapter revision (supports chapterNumber + mode via instruction)
   - agent="exporter" for book export
+  - **chapterNumber param**: auditor and reviser accept an explicit chapter number; omit for latest
 - **read** — Read truth files or chapter content
 - **edit** — Edit truth files (rename characters, adjust world settings)
 - **grep** — Search content across chapters

+ 7 - 6
packages/core/src/agent/agent-tools.ts

@@ -39,6 +39,7 @@ const SubAgentParams = Type.Object({
   ]),
   instruction: Type.String({ description: "Natural language instruction from the main Agent" }),
   bookId: Type.Optional(Type.String({ description: "Book ID — required for all agents except architect" })),
+  chapterNumber: Type.Optional(Type.Number({ description: "Target chapter number for auditor/reviser. Omit to use the latest chapter." })),
 });
 
 export function createSubAgentTool(pipeline: PipelineRunner, activeBookId: string | null): AgentTool<typeof SubAgentParams> {
@@ -56,7 +57,7 @@ export function createSubAgentTool(pipeline: PipelineRunner, activeBookId: strin
       _signal?: AbortSignal,
       onUpdate?: AgentToolUpdateCallback,
     ): Promise<AgentToolResult<undefined>> {
-      const { agent, instruction, bookId } = params;
+      const { agent, instruction, bookId, chapterNumber } = params;
 
       const progress = (msg: string) => {
         onUpdate?.(textResult(msg));
@@ -92,8 +93,8 @@ export function createSubAgentTool(pipeline: PipelineRunner, activeBookId: strin
 
           case "auditor": {
             if (!bookId) return textResult("Error: bookId is required for the auditor agent.");
-            progress(`Auditing draft for "${bookId}"...`);
-            const audit = await pipeline.auditDraft(bookId);
+            progress(`Auditing chapter ${chapterNumber ?? "latest"} for "${bookId}"...`);
+            const audit = await pipeline.auditDraft(bookId, chapterNumber);
             progress(`Audit complete for "${bookId}".`);
             const issueCount = audit.issues?.length ?? 0;
             return textResult(
@@ -112,10 +113,10 @@ export function createSubAgentTool(pipeline: PipelineRunner, activeBookId: strin
                 : /rework|返工/.test(instruction)
                   ? "rework"
                   : "spot-fix";
-            progress(`Revising "${bookId}" in ${mode} mode...`);
-            await pipeline.reviseDraft(bookId, undefined, mode);
+            progress(`Revising "${bookId}" chapter ${chapterNumber ?? "latest"} in ${mode} mode...`);
+            await pipeline.reviseDraft(bookId, chapterNumber, mode);
             progress(`Revision complete for "${bookId}".`);
-            return textResult(`Revision (${mode}) complete for "${bookId}".`);
+            return textResult(`Revision (${mode}) complete for "${bookId}" chapter ${chapterNumber ?? "latest"}.`);
           }
 
           case "exporter": {