浏览代码

feat: let agents create interactive books

Ma 7 月之前
父节点
当前提交
b23f5bf46c
共有 2 个文件被更改,包括 26 次插入 和 2 次删除
  1. 22 0
      packages/core/src/__tests__/pipeline-agent.test.ts
  2. 4 2
      packages/core/src/pipeline/agent.ts

+ 22 - 0
packages/core/src/__tests__/pipeline-agent.test.ts

@@ -296,6 +296,28 @@ describe("agent pipeline tools", () => {
     });
     });
   });
   });
 
 
+  it("passes narrativeMode through create_book so agents can create interactive books", async () => {
+    const initBook = vi.spyOn(pipeline, "initBook").mockResolvedValue();
+
+    await executeAgentTool(
+      pipeline,
+      state,
+      config,
+      "create_book",
+      {
+        title: "Branch Agent Book",
+        genre: "other",
+        platform: "tomato",
+        narrativeMode: "interactive-tree",
+      },
+    );
+
+    expect(initBook).toHaveBeenCalledWith(expect.objectContaining({
+      title: "Branch Agent Book",
+      narrativeMode: "interactive-tree",
+    }));
+  });
+
   it("plans and composes chapters through the agent tool surface", async () => {
   it("plans and composes chapters through the agent tool surface", async () => {
     const planResult = JSON.parse(await executeAgentTool(
     const planResult = JSON.parse(await executeAgentTool(
       pipeline,
       pipeline,

+ 4 - 2
packages/core/src/pipeline/agent.ts

@@ -76,7 +76,7 @@ const TOOLS: ReadonlyArray<ToolDefinition> = [
   },
   },
   {
   {
     name: "create_book",
     name: "create_book",
-    description: "创建一本新书。生成世界观、卷纲、文风指南等基础设定。",
+    description: "创建一本新书。生成世界观、卷纲、文风指南等基础设定。可选 narrativeMode=interactive-tree 来创建互动分支书。",
     parameters: {
     parameters: {
       type: "object",
       type: "object",
       properties: {
       properties: {
@@ -84,6 +84,7 @@ const TOOLS: ReadonlyArray<ToolDefinition> = [
         genre: { type: "string", enum: ["xuanhuan", "xianxia", "urban", "horror", "other"], description: "题材" },
         genre: { type: "string", enum: ["xuanhuan", "xianxia", "urban", "horror", "other"], description: "题材" },
         platform: { type: "string", enum: ["tomato", "feilu", "qidian", "other"], description: "目标平台" },
         platform: { type: "string", enum: ["tomato", "feilu", "qidian", "other"], description: "目标平台" },
         brief: { type: "string", description: "创作简述/需求(自然语言)" },
         brief: { type: "string", description: "创作简述/需求(自然语言)" },
+        narrativeMode: { type: "string", enum: ["linear", "interactive-tree"], description: "叙事模式(默认 linear)" },
       },
       },
       required: ["title", "genre", "platform"],
       required: ["title", "genre", "platform"],
     },
     },
@@ -292,7 +293,7 @@ export async function runAgentLoop(
 | list_books | 列出所有书 |
 | list_books | 列出所有书 |
 | get_book_status | 查看书的章数、字数、审计状态 |
 | get_book_status | 查看书的章数、字数、审计状态 |
 | read_truth_files | 读取长期记忆(状态卡、资源账本、伏笔池)和设定(世界观、卷纲、本书规则) |
 | read_truth_files | 读取长期记忆(状态卡、资源账本、伏笔池)和设定(世界观、卷纲、本书规则) |
-| create_book | 建书,生成世界观、卷纲、本书规则(自动加载题材 genre profile) |
+| create_book | 建书,生成世界观、卷纲、本书规则(支持 linear / interactive-tree) |
 | get_branch_tree | 读取互动小说的分支树 |
 | get_branch_tree | 读取互动小说的分支树 |
 | get_branch_choices | 读取当前 active branch 的待读者选项 |
 | get_branch_choices | 读取当前 active branch 的待读者选项 |
 | choose_branch | 选中一个互动分支选项 |
 | choose_branch | 选中一个互动分支选项 |
@@ -482,6 +483,7 @@ export async function executeAgentTool(
         title,
         title,
         platform: ((args.platform as string) ?? "tomato") as Platform,
         platform: ((args.platform as string) ?? "tomato") as Platform,
         genre: ((args.genre as string) ?? "xuanhuan") as Genre,
         genre: ((args.genre as string) ?? "xuanhuan") as Genre,
+        narrativeMode: ((args.narrativeMode as string) ?? "linear") as "linear" | "interactive-tree",
         status: "outlining" as const,
         status: "outlining" as const,
         targetChapters: 200,
         targetChapters: 200,
         chapterWordCount: 3000,
         chapterWordCount: 3000,