@ai-setting/roy-agent-core 1.5.80 → 1.5.83

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (32) hide show
  1. package/dist/env/agent/index.js +2 -2
  2. package/dist/env/event-source/index.js +2 -2
  3. package/dist/env/index.js +14 -14
  4. package/dist/env/prompt/index.js +1 -1
  5. package/dist/env/task/delegate/index.js +2 -2
  6. package/dist/env/task/index.js +5 -5
  7. package/dist/env/task/plugins/index.js +1 -1
  8. package/dist/env/task/storage/index.js +1 -1
  9. package/dist/env/task/tools/index.js +1 -1
  10. package/dist/env/workflow/engine/index.js +3 -3
  11. package/dist/env/workflow/index.js +5 -5
  12. package/dist/env/workflow/nodes/index.js +1 -1
  13. package/dist/env/workflow/tools/index.js +26 -142
  14. package/dist/env/workflow/utils/index.js +1 -1
  15. package/dist/index.js +15 -15
  16. package/dist/shared/@ai-setting/{roy-agent-core-4ws3w7cx.js → roy-agent-core-015vw11k.js} +32 -3
  17. package/dist/shared/@ai-setting/{roy-agent-core-7mw366pc.js → roy-agent-core-67yzhmg2.js} +1 -1
  18. package/dist/shared/@ai-setting/{roy-agent-core-8x1gmqcv.js → roy-agent-core-68sef3es.js} +4 -6
  19. package/dist/shared/@ai-setting/{roy-agent-core-jazhr292.js → roy-agent-core-6b0r2e7j.js} +2 -2
  20. package/dist/shared/@ai-setting/{roy-agent-core-n9tw52zb.js → roy-agent-core-78yzt2bq.js} +40 -128
  21. package/dist/shared/@ai-setting/{roy-agent-core-7t0jen73.js → roy-agent-core-7nh5h9fn.js} +37 -4
  22. package/dist/shared/@ai-setting/roy-agent-core-a6j7g1qe.js +428 -0
  23. package/dist/shared/@ai-setting/{roy-agent-core-0tgnq4nz.js → roy-agent-core-f6p7wwpd.js} +64 -5
  24. package/dist/shared/@ai-setting/{roy-agent-core-99j4w3fx.js → roy-agent-core-gb9gbkc3.js} +2 -0
  25. package/dist/shared/@ai-setting/{roy-agent-core-ajx32wzj.js → roy-agent-core-j754zgb4.js} +13 -0
  26. package/dist/shared/@ai-setting/{roy-agent-core-zf62vkc4.js → roy-agent-core-mbre4fxg.js} +32 -1
  27. package/dist/shared/@ai-setting/{roy-agent-core-r9y8ct0w.js → roy-agent-core-pcdzfwdv.js} +4 -0
  28. package/dist/shared/@ai-setting/{roy-agent-core-11dnsfwp.js → roy-agent-core-qjv8537d.js} +3 -3
  29. package/dist/shared/@ai-setting/{roy-agent-core-s83ararq.js → roy-agent-core-v3t28k5n.js} +35 -3
  30. package/dist/shared/@ai-setting/{roy-agent-core-d32ecc9z.js → roy-agent-core-vcvgq9hy.js} +150 -1
  31. package/package.json +1 -1
  32. package/dist/shared/@ai-setting/roy-agent-core-0vbdz0x7.js +0 -36
@@ -6,13 +6,18 @@ import {
6
6
  WorkflowEngine,
7
7
  exports_engine,
8
8
  init_engine
9
- } from "./roy-agent-core-jazhr292.js";
9
+ } from "./roy-agent-core-6b0r2e7j.js";
10
10
  import {
11
11
  WorkflowService
12
12
  } from "./roy-agent-core-4t40mkpv.js";
13
13
  import {
14
- askUserTool
15
- } from "./roy-agent-core-0vbdz0x7.js";
14
+ askUserTool,
15
+ createRunWorkflowTool,
16
+ createWorkflowGetTool,
17
+ createWorkflowListTool,
18
+ createWorkflowRunStatusTool,
19
+ createWorkflowRunStopTool
20
+ } from "./roy-agent-core-a6j7g1qe.js";
16
21
  import {
17
22
  BaseComponent
18
23
  } from "./roy-agent-core-rgckng3p.js";
@@ -173,6 +178,7 @@ class WorkflowComponent extends BaseComponent {
173
178
  await super.start();
174
179
  await this.initSqliteService();
175
180
  await this.registerAskUserTool();
181
+ await this.registerWorkflowTools();
176
182
  }
177
183
  async registerAskUserTool() {
178
184
  try {
@@ -194,6 +200,32 @@ class WorkflowComponent extends BaseComponent {
194
200
  componentLogger.warn("Failed to register ask_user tool:", error);
195
201
  }
196
202
  }
203
+ async registerWorkflowTools() {
204
+ if (!this.workflowService) {
205
+ componentLogger.warn("WorkflowService not initialized, cannot register workflow tools");
206
+ return;
207
+ }
208
+ try {
209
+ const toolComponent = this.toolComponent || this._workflowEnv?.getComponent("tool");
210
+ if (!toolComponent) {
211
+ componentLogger.warn("ToolComponent not available, cannot register workflow tools");
212
+ return;
213
+ }
214
+ const tools = [
215
+ createWorkflowGetTool(this.workflowService),
216
+ createWorkflowListTool(this.workflowService),
217
+ createRunWorkflowTool(this.workflowService),
218
+ createWorkflowRunStatusTool(this.workflowService),
219
+ createWorkflowRunStopTool(this.workflowService)
220
+ ];
221
+ for (const tool of tools) {
222
+ toolComponent.register(tool);
223
+ componentLogger.info(`[WorkflowComponent] Registered workflow tool: ${tool.name}`);
224
+ }
225
+ } catch (error) {
226
+ componentLogger.warn("Failed to register workflow tools:", error);
227
+ }
228
+ }
197
229
  async initSqliteService() {
198
230
  try {
199
231
  const { getDatabase, initializeTables } = await import("./roy-agent-core-74cp3zp1.js");
@@ -828,7 +828,156 @@ When reusing an existing task, you MUST follow these rules:
828
828
 
829
829
  # 输出要求
830
830
  直接调用 record_memory 工具,写入新的全局记忆。
831
- 输出格式为 Markdown,保持结构清晰。`
831
+ 输出格式为 Markdown,保持结构清晰。`,
832
+ "workflow-agent": `# Workflow 调度中介(Workflow Dispatch Mediator)
833
+
834
+ ## 你的身份
835
+
836
+ 你是 Roy 系统的 workflow 调度中介(entry-agent)。当 \`delegate_task\` 收到一个 workflow 类型的子智能体请求时,你被自动调用,负责将请求转交给合适的 workflow 执行。
837
+
838
+ - **类型**: primary(不是 subagent,不是 workflow,避免无限递归)
839
+ - **职责**: 仅做 workflow 调度,不做其他任何工作
840
+ - **边界**: 不要执行除 workflow 调度以外的任何任务
841
+
842
+ ## 工作目录
843
+
844
+ **workspace_dir**: {{workspace_dir}}
845
+
846
+ ## 可用工具
847
+
848
+ 你只有以下 5 个 workflow 相关工具可用:
849
+
850
+ 1. **\`workflow_list\`** — 列出所有已注册的 workflow
851
+ - 参数:tag(可选),search(可选),limit,offset
852
+ - 返回值:workflow 列表(名称、版本、描述、标签)
853
+
854
+ 2. **\`workflow_get\`** — 获取 workflow 定义详情
855
+ - 参数:\`name\`(workflow 名称)或 \`run_id\`(run ID)
856
+ - 返回值:workflow 定义(名称、版本、描述、入参 inputs schema、节点列表),或 run 的状态
857
+
858
+ 3. **\`workflow_run\`** — 运行 workflow
859
+ - 参数:\`workflow_name\`(必填),\`input\`(可选 JSON),\`sync\`(是否等待完成,默认 true),\`timeout\`(可选)
860
+ - 返回值:run_id, status, output, error, duration_ms
861
+
862
+ 4. **\`workflow_run_status\`** — 查询 run 状态
863
+ - 参数:\`run_id\`(必填)
864
+ - 返回值:run_id, status, output, error
865
+
866
+ 5. **\`workflow_run_stop\`** — 停止 run
867
+ - 参数:\`run_id\`(必填),\`reason\`(可选)
868
+ - 返回值:success 状态
869
+
870
+ ## 核心使命
871
+
872
+ 当被调用时,你会收到:
873
+
874
+ 1. **workflow 名称** — 来自 \`subagent_type\`(例如 \`strict-task-agent\` 对应 workflow \`strict-task-agent\`)
875
+ 2. **用户原始 prompt** — 上游 agent 传给 delegate_task 的请求内容
876
+ 3. **任务上下文** — session_id、trace_id 等元数据
877
+
878
+ 你的工作流程:
879
+
880
+ ### 步骤 1: 查询 workflow 详情
881
+
882
+ 调用 \`workflow_get\` 工具,传入 workflow 名称,读取其入参 schema。
883
+
884
+ ### 步骤 2: 提取用户输入
885
+
886
+ 从用户原始 prompt 中,**仅**提取符合 schema 的字段,组装为 JSON。
887
+ 如果 schema 要求必填字段但用户 prompt 中没有,**不要猜测**——直接 \`workflow_run\` 让 workflow 自己处理默认值或报错。
888
+
889
+ ### 步骤 3: 触发 workflow run
890
+
891
+ 调用 \`workflow_run\` 工具,传入 workflow 名称和 input JSON。
892
+
893
+ ### 步骤 4: 查询状态(如需)
894
+
895
+ 调用 \`workflow_run_status\` 查询执行结果。
896
+
897
+ ### 步骤 5: 返回结果
898
+
899
+ 把 workflow run 的输出原样返回给上游 caller。
900
+
901
+ ## 工作流程示例
902
+
903
+ \`\`\`
904
+ # 步骤 1: 查看 workflow 入参
905
+ workflow_get(name="strict-task-agent")
906
+ # → 返回 inputs 中包含 task_description (required), priority (optional)
907
+
908
+ # 步骤 2: 从 prompt 提取 input
909
+ # prompt: "修复登录bug,优先级高"
910
+ # → {"task_description": "修复登录bug", "priority": "high"}
911
+
912
+ # 步骤 3: 执行 workflow
913
+ workflow_run(workflow_name="strict-task-agent", input={"task_description": "修复登录bug", "priority": "high"})
914
+ # → 返回 run_id, status, output
915
+ \`\`\`
916
+
917
+ ## 严格约束
918
+
919
+ - ✅ **只**通过 \`workflow_run\` 工具执行 workflow
920
+ - ✅ 先调用 \`workflow_get\` 获取 schema,再调用 \`workflow_run\`
921
+ - ❌ 不要直接读 workflow YAML 文件并尝试自己解释
922
+ - ❌ 不要执行 workflow 调度以外的任何工作(写代码、查文件、做调研、改 bug 都不做)
923
+ - ❌ 不要修改 workflow 定义
924
+ - ❌ 不要使用 \`delegate_task\` 再次委托——你已经是最末端的执行者
925
+ - ❌ 不要使用 \`bash\` 或其他非 workflow 工具——你的工具列表只有 5 个 workflow 工具
926
+
927
+ ## 为什么需要这个中介
928
+
929
+ > 历史背景:在本次重构之前,\`delegate_task("strict-task-agent")\` 会被当作普通 subagent 直接执行,导致 subagent session 被创建但 workflow 引擎从未启动,session 内容是默认 subagent prompt 而不是 workflow run。本中介模式修复了这个 bug——所有 workflow 类型 subagent 的 delegate_task 都先经过本 agent,再走标准 \`workflow_run\` 路径。
930
+ >
931
+ > 设计文档:.roy/design/2026-06-29-workflow-subagent-entry-agent-design.md
932
+
933
+ 记住:你是 workflow 的"调度员",不是 workflow 本身。`,
934
+ "task-agent": `# Task Agent — 任务优先智能体
935
+
936
+ ## 你的身份
937
+ 当主 agent(default)在 ReAct 循环中达到迭代阈值时,你被调用。你的职责:
938
+ 1. 分析对话历史,理解用户需求
939
+ 2. task_create 创建任务
940
+ 3. task_search 搜索相似任务
941
+ 4. delegate_task 委托给 roy
942
+
943
+ ## 工作目录
944
+
945
+ **workspace_dir**: {{workspace_dir}}
946
+
947
+ ## 可用工具(全部 task 工具 + delegate_task + bash)
948
+
949
+ ### 任务查询工具
950
+ - task_search(keywords=[...]) — 搜索相关任务(返回任务 ID 列表,用于 similar_task_ids)
951
+ - task_get(task_id=123) — 查看任务详情
952
+ - task_list(status="active") — 列出任务
953
+ - task_operation_list(task_id=123) — 查看操作记录
954
+
955
+ ### 任务生命周期工具
956
+ - task_create(title=..., description=..., progress=0, status="active") — 创建新任务
957
+ - task_update(task_id=..., ...) — 更新任务状态
958
+ - task_operation_create(task_id=..., ...) — 记录操作记录
959
+ - task_complete(task_id=...) — 完成任务
960
+
961
+ ### 执行工具
962
+ - delegate_task(description=..., prompt=..., subagent_type="roy", similar_task_ids=[...]) — 委托给子 agent
963
+ - bash(command=...) — 执行 shell 命令
964
+
965
+ ## 工作流程(严格执行)
966
+ 1. **分析对话** → 理解用户到底需要做什么
967
+ 2. **task_create** → 创建任务(title 简短 3-8 字,description 详细,progress=0, status="active")
968
+ 3. **task_operation_create** → 记录"任务已创建,开始搜索相似任务"里程碑
969
+ 4. **task_search** → 搜索相似任务获取 similar_task_ids
970
+ 5. **task_get** → 获取相似任务详情(可选,最多 3 个)
971
+ 6. **delegate_task** → 委托给 roy:
972
+ - description: 简短标题(3-8 字)
973
+ - prompt: 详细的委托指令,包含用户原始需求
974
+ - subagent_type: "roy"
975
+ - similar_task_ids: 真实搜索到的 ID 列表(最多 3 个)
976
+
977
+ ## 重要规则
978
+ - delegate_task 是后台模式,调用后立即返回 bgProcessId
979
+ - 调用 delegate_task 后立即停止,不要再做其他操作
980
+ - 通过 task_operation_create 记录里程碑`
832
981
  };
833
982
  function getBuiltInPromptNames() {
834
983
  return Object.keys(builtInPrompts);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ai-setting/roy-agent-core",
3
- "version": "1.5.80",
3
+ "version": "1.5.83",
4
4
  "type": "module",
5
5
  "description": "Core SDK for roy-agent - Environment, Components, Tools, Sessions, Tasks",
6
6
  "main": "./dist/index.js",
@@ -1,36 +0,0 @@
1
- import {
2
- AskUserError,
3
- init_workflow_hil
4
- } from "./roy-agent-core-e25xkv53.js";
5
-
6
- // src/env/workflow/tools/ask-user-tool.ts
7
- init_workflow_hil();
8
- import { z } from "zod";
9
- var AskUserInputSchema = z.object({
10
- query: z.string().describe("The question or request to ask the user"),
11
- options: z.array(z.string()).optional().describe("Optional choices for the user"),
12
- required_confirm: z.boolean().optional().describe("If true, user must explicitly confirm")
13
- });
14
- var askUserTool = {
15
- name: "ask_user",
16
- description: "Ask user for input or confirmation. Use this tool when you need user input or validation to continue the workflow.",
17
- parameters: AskUserInputSchema,
18
- async execute(args, context) {
19
- const runId = context.metadata?.runId || "unknown";
20
- const sessionId = context.metadata?.sessionId || `workflow_${runId}`;
21
- const nodeId = context.metadata?.nodeId || "unknown";
22
- let fullQuery = args.query;
23
- if (args.options && args.options.length > 0) {
24
- fullQuery = `${args.query} (选项: ${args.options.join(", ")})`;
25
- }
26
- throw new AskUserError(runId, sessionId, nodeId, "agent", fullQuery);
27
- },
28
- metadata: {
29
- category: "workflow",
30
- tags: ["human-in-loop", "user-input"],
31
- version: "1.0.0"
32
- }
33
- };
34
- var askUserToolInstance = askUserTool;
35
-
36
- export { AskUserInputSchema, askUserTool, askUserToolInstance };