@blocklet/pages-kit-agents 0.5.56 → 0.6.1

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blocklet/pages-kit-agents",
3
- "version": "0.5.56",
3
+ "version": "0.6.1",
4
4
  "description": "AIGNE based agents for pages kit",
5
5
  "author": "Arcblock <blocklet@arcblock.io> https://github.com/blocklet",
6
6
  "homepage": "https://github.com/blocklet/pages-kit#readme",
@@ -23,13 +23,13 @@
23
23
  },
24
24
  "keywords": [],
25
25
  "dependencies": {
26
- "@aigne/agent-library": "^1.13.2",
27
- "@aigne/anthropic": "^0.2.7",
28
- "@aigne/core": "^1.20.1",
29
- "@aigne/deepseek": "^0.2.7",
30
- "@aigne/gemini": "^0.2.7",
31
- "@aigne/openai": "^0.2.7",
32
- "@aigne/xai": "^0.2.7",
26
+ "@aigne/agent-library": "^1.17.2",
27
+ "@aigne/anthropic": "^0.3.9",
28
+ "@aigne/core": "^1.25.0",
29
+ "@aigne/deepseek": "^0.3.9",
30
+ "@aigne/gemini": "^0.3.9",
31
+ "@aigne/openai": "^0.4.2",
32
+ "@aigne/xai": "^0.3.9",
33
33
  "@types/js-yaml": "^4.0.9",
34
34
  "@types/yargs": "^17.0.33",
35
35
  "fastq": "^1.19.1",
@@ -38,7 +38,7 @@
38
38
  "open": "^10.1.2",
39
39
  "yargs": "^17.7.2",
40
40
  "zod": "^3.24.2",
41
- "@blocklet/pages-kit-block-studio": "0.5.56"
41
+ "@blocklet/pages-kit-block-studio": "0.6.1"
42
42
  },
43
43
  "devDependencies": {
44
44
  "copyfiles": "^2.4.1"
package/workflow-cli.ts CHANGED
@@ -5,7 +5,6 @@ import fs from 'node:fs/promises';
5
5
  import path from 'node:path';
6
6
  import { z } from 'zod';
7
7
 
8
- // import { OrchestratorAgent } from './agents/orchestrator/index.js';
9
8
  import { getModel } from './utils/index.js';
10
9
  import { logger } from './utils/logger.js';
11
10
  // import { siteHtmlBatchGeneratorAgent } from './workflow-agents/site-html-batch-generator-agent.js';
@@ -62,35 +61,6 @@ async function runWorkflow({
62
61
  model,
63
62
  });
64
63
 
65
- // const agent = OrchestratorAgent.from({
66
- // skills: [siteMapGeneratorAgent, siteHtmlBatchGeneratorAgent],
67
- // maxIterations: 3,
68
- // tasksConcurrency: 1,
69
- // chainStepResults: true,
70
- // });
71
-
72
- // const result = await engine.invoke(
73
- // agent,
74
- // `请根据用户的提问,分析用户希望创建的站点的主题,生成这个主题相关的 SiteMap。
75
- // 然后遍历这些页面,生成每个页面的 HTML 内容。
76
-
77
- // 用户的问题是:${question}
78
- // 用户希望创建的站点的语言是:${locale}
79
- // 用户希望创建的站点的项目ID是:${projectId}
80
- // `
81
- // );
82
-
83
- // const teamAgent = TeamAgent.from({
84
- // name: 'generate web site',
85
- // inputSchema: z.object({
86
- // question: z.string(),
87
- // locale: z.string(),
88
- // projectId: z.string(),
89
- // }),
90
- // mode: ProcessMode.sequential,
91
- // skills: [siteMapGeneratorAgent],
92
- // });
93
-
94
64
  const stream = await engine.invoke(
95
65
  siteMapGeneratorAgent,
96
66
  {
@@ -1,115 +0,0 @@
1
- import { Agent, type AgentInvokeOptions, type AgentOptions, type Message } from '@aigne/core';
2
- import { type FullPlanOutput, type StepWithResult } from './orchestrator-prompts.js';
3
- /**
4
- * Re-export orchestrator prompt templates and related types
5
- */
6
- export * from './orchestrator-prompts.js';
7
- /**
8
- * Represents a complete plan with execution results
9
- * @hidden
10
- */
11
- export interface FullPlanWithResult {
12
- /**
13
- * The overall objective
14
- */
15
- objective: string;
16
- /**
17
- * The generated complete plan
18
- */
19
- plan?: FullPlanOutput;
20
- /**
21
- * List of executed steps with their results
22
- */
23
- steps: StepWithResult[];
24
- /**
25
- * Final result
26
- */
27
- result?: string;
28
- /**
29
- * Plan completion status
30
- */
31
- status?: boolean;
32
- }
33
- /**
34
- * Configuration options for the Orchestrator Agent
35
- */
36
- export interface OrchestratorAgentOptions<I extends Message = Message, O extends Message = Message> extends AgentOptions<I, O> {
37
- /**
38
- * Maximum number of iterations to prevent infinite loops
39
- * Default: 30
40
- */
41
- maxIterations?: number;
42
- /**
43
- * Number of concurrent tasks
44
- * Default: 5
45
- */
46
- tasksConcurrency?: number;
47
- /**
48
- * Chain step results as input to the next step
49
- * Default: false
50
- */
51
- chainStepResults?: boolean;
52
- }
53
- /**
54
- * Orchestrator Agent Class
55
- *
56
- * This Agent is responsible for:
57
- * 1. Generating an execution plan based on the objective
58
- * 2. Breaking down the plan into steps and tasks
59
- * 3. Coordinating the execution of steps and tasks
60
- * 4. Synthesizing the final result
61
- *
62
- * Workflow:
63
- * - Receives input objective
64
- * - Uses planner to create execution plan
65
- * - Executes tasks and steps according to the plan
66
- * - Synthesizes final result through completer
67
- */
68
- export declare class OrchestratorAgent<I extends Message = Message, O extends Message = Message> extends Agent<I, O> {
69
- /**
70
- * Factory method to create an OrchestratorAgent instance
71
- * @param options - Configuration options for the Orchestrator Agent
72
- * @returns A new OrchestratorAgent instance
73
- */
74
- static from<I extends Message, O extends Message>(options: OrchestratorAgentOptions<I, O>): OrchestratorAgent<I, O>;
75
- /**
76
- * Creates an OrchestratorAgent instance
77
- * @param options - Configuration options for the Orchestrator Agent
78
- */
79
- constructor(options: OrchestratorAgentOptions<I, O>);
80
- private planner;
81
- private completer;
82
- /**
83
- * Maximum number of iterations
84
- * Prevents infinite execution loops
85
- */
86
- maxIterations?: number;
87
- /**
88
- * Number of concurrent tasks
89
- * Controls how many tasks can be executed simultaneously
90
- */
91
- tasksConcurrency?: number;
92
- /**
93
- * Whether to chain step results as input to next step
94
- */
95
- chainStepResults?: boolean;
96
- /**
97
- * Process input and execute the orchestrator workflow
98
- *
99
- * Workflow:
100
- * 1. Extract the objective
101
- * 2. Loop until plan completion or maximum iterations:
102
- * a. Generate/update execution plan
103
- * b. If plan is complete, synthesize result
104
- * c. Otherwise, execute steps in the plan
105
- *
106
- * @param input - Input message containing the objective
107
- * @param options - Agent invocation options
108
- * @returns Processing result
109
- */
110
- process(input: I, options: AgentInvokeOptions): Promise<O>;
111
- private getFullPlanInput;
112
- private getFullPlan;
113
- private synthesizePlanResult;
114
- private executeStep;
115
- }
@@ -1,264 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- var __importDefault = (this && this.__importDefault) || function (mod) {
17
- return (mod && mod.__esModule) ? mod : { "default": mod };
18
- };
19
- Object.defineProperty(exports, "__esModule", { value: true });
20
- exports.OrchestratorAgent = void 0;
21
- /* eslint-disable no-await-in-loop */
22
- const core_1 = require("@aigne/core");
23
- const type_utils_js_1 = require("@aigne/core/utils/type-utils.js");
24
- const fastq_1 = __importDefault(require("fastq"));
25
- const zod_1 = require("zod");
26
- const orchestrator_prompts_js_1 = require("./orchestrator-prompts.js");
27
- /**
28
- * Default maximum number of iterations to prevent infinite loops
29
- */
30
- const DEFAULT_MAX_ITERATIONS = 30;
31
- /**
32
- * Default number of concurrent tasks
33
- */
34
- const DEFAULT_TASK_CONCURRENCY = 5;
35
- /**
36
- * Re-export orchestrator prompt templates and related types
37
- */
38
- __exportStar(require("./orchestrator-prompts.js"), exports);
39
- /**
40
- * Orchestrator Agent Class
41
- *
42
- * This Agent is responsible for:
43
- * 1. Generating an execution plan based on the objective
44
- * 2. Breaking down the plan into steps and tasks
45
- * 3. Coordinating the execution of steps and tasks
46
- * 4. Synthesizing the final result
47
- *
48
- * Workflow:
49
- * - Receives input objective
50
- * - Uses planner to create execution plan
51
- * - Executes tasks and steps according to the plan
52
- * - Synthesizes final result through completer
53
- */
54
- class OrchestratorAgent extends core_1.Agent {
55
- /**
56
- * Factory method to create an OrchestratorAgent instance
57
- * @param options - Configuration options for the Orchestrator Agent
58
- * @returns A new OrchestratorAgent instance
59
- */
60
- static from(options) {
61
- return new OrchestratorAgent(options);
62
- }
63
- /**
64
- * Creates an OrchestratorAgent instance
65
- * @param options - Configuration options for the Orchestrator Agent
66
- */
67
- constructor(options) {
68
- (0, type_utils_js_1.checkArguments)('OrchestratorAgent', orchestratorAgentOptionsSchema, options);
69
- super({ ...options });
70
- this.maxIterations = options.maxIterations;
71
- this.tasksConcurrency = options.tasksConcurrency;
72
- this.chainStepResults = options.chainStepResults;
73
- this.planner = new core_1.AIAgent({
74
- name: 'llm_orchestration_planner',
75
- instructions: orchestrator_prompts_js_1.FULL_PLAN_PROMPT_TEMPLATE,
76
- outputSchema: () => (0, orchestrator_prompts_js_1.getFullPlanSchema)(this.skills),
77
- });
78
- this.completer = new core_1.AIAgent({
79
- name: 'llm_orchestration_completer',
80
- instructions: orchestrator_prompts_js_1.FULL_PLAN_PROMPT_TEMPLATE,
81
- outputSchema: this.outputSchema,
82
- });
83
- }
84
- planner;
85
- completer;
86
- /**
87
- * Maximum number of iterations
88
- * Prevents infinite execution loops
89
- */
90
- maxIterations;
91
- /**
92
- * Number of concurrent tasks
93
- * Controls how many tasks can be executed simultaneously
94
- */
95
- tasksConcurrency;
96
- /**
97
- * Whether to chain step results as input to next step
98
- */
99
- chainStepResults;
100
- /**
101
- * Process input and execute the orchestrator workflow
102
- *
103
- * Workflow:
104
- * 1. Extract the objective
105
- * 2. Loop until plan completion or maximum iterations:
106
- * a. Generate/update execution plan
107
- * b. If plan is complete, synthesize result
108
- * c. Otherwise, execute steps in the plan
109
- *
110
- * @param input - Input message containing the objective
111
- * @param options - Agent invocation options
112
- * @returns Processing result
113
- */
114
- async process(input, options) {
115
- const { model } = options.context;
116
- if (!model)
117
- throw new Error('model is required to run OrchestratorAgent');
118
- const objective = (0, core_1.getMessage)(input);
119
- if (!objective)
120
- throw new Error('Objective is required to run OrchestratorAgent');
121
- const result = {
122
- objective,
123
- steps: [],
124
- };
125
- let iterations = 0;
126
- const maxIterations = this.maxIterations ?? DEFAULT_MAX_ITERATIONS;
127
- while (iterations++ < maxIterations) {
128
- const plan = await this.getFullPlan(result, options.context);
129
- result.plan = plan;
130
- if (plan.isComplete) {
131
- return this.synthesizePlanResult(result, options.context);
132
- }
133
- for (const step of plan.steps) {
134
- const stepResult = await this.executeStep(result, step, options.context);
135
- result.steps.push(stepResult);
136
- }
137
- }
138
- throw new Error(`Max iterations reached: ${maxIterations}`);
139
- }
140
- getFullPlanInput(planResult) {
141
- return {
142
- objective: planResult.objective,
143
- steps: planResult.steps,
144
- plan: {
145
- status: planResult.status ? 'Complete' : 'In Progress',
146
- result: planResult.result || 'No results yet',
147
- },
148
- agents: this.skills.map((i) => ({
149
- name: i.name,
150
- description: i.description,
151
- tools: i.skills.map((i) => ({ name: i.name, description: i.description })),
152
- })),
153
- };
154
- }
155
- async getFullPlan(planResult, context) {
156
- return context.invoke(this.planner, this.getFullPlanInput(planResult));
157
- }
158
- async synthesizePlanResult(planResult, context) {
159
- return context.invoke(this.completer, {
160
- ...this.getFullPlanInput(planResult),
161
- ...(0, core_1.createMessage)(orchestrator_prompts_js_1.SYNTHESIZE_PLAN_USER_PROMPT_TEMPLATE),
162
- });
163
- }
164
- async executeStep(planResult, step, context) {
165
- const concurrency = this.tasksConcurrency ?? DEFAULT_TASK_CONCURRENCY;
166
- const { model } = context;
167
- if (!model)
168
- throw new Error('model is required to run OrchestratorAgent');
169
- let lastTaskResult = {};
170
- // 将上一步最后一个任务的输入作为下一步的输入
171
- if (this.chainStepResults) {
172
- if (planResult.steps.length > 0) {
173
- const lastStep = planResult.steps[planResult.steps.length - 1];
174
- if (lastStep?.result) {
175
- try {
176
- const lastStepResult = JSON.parse(lastStep.result);
177
- if (lastStepResult?.step?.results && Array.isArray(lastStepResult.step.results) && lastStepResult.step.results.length > 0) {
178
- const lastStepResults = lastStepResult.step.results[lastStepResult.step.results.length - 1];
179
- console.log('lastStepResults', lastStepResults.result);
180
- lastTaskResult = JSON.parse(lastStepResults.result);
181
- }
182
- }
183
- catch (error) {
184
- console.error('Failed to parse last step result', error);
185
- }
186
- }
187
- }
188
- }
189
- const queue = fastq_1.default.promise(async (task) => {
190
- const agent = this.skills.find((skill) => skill.name === task.agent);
191
- if (!agent)
192
- throw new Error(`Agent ${task.agent} not found`);
193
- const prompt = core_1.PromptTemplate.from(orchestrator_prompts_js_1.TASK_PROMPT_TEMPLATE).format({
194
- // eslint-disable-next-line prettier/prettier
195
- objective: planResult.objective,
196
- step,
197
- task,
198
- steps: planResult.steps,
199
- });
200
- let result;
201
- if (agent.isInvokable) {
202
- result = getMessageOrJsonString(await context.invoke(agent, { ...lastTaskResult, [core_1.MESSAGE_KEY]: prompt }));
203
- }
204
- else {
205
- const executor = core_1.AIAgent.from({
206
- name: 'llm_orchestration_task_executor',
207
- instructions: prompt,
208
- skills: agent.skills,
209
- });
210
- result = getMessageOrJsonString(await context.invoke(executor, this.chainStepResults ? { ...lastTaskResult } : {}));
211
- }
212
- return { task, result };
213
- }, concurrency);
214
- let results;
215
- try {
216
- results = await Promise.all(step.tasks.map((task) => queue.push(task)));
217
- }
218
- catch (error) {
219
- queue.kill();
220
- throw error;
221
- }
222
- let result = '';
223
- if (!this.chainStepResults) {
224
- result = getMessageOrJsonString(await context.invoke(core_1.AIAgent.from({
225
- name: 'llm_orchestration_step_synthesizer',
226
- instructions: orchestrator_prompts_js_1.SYNTHESIZE_STEP_PROMPT_TEMPLATE,
227
- }), { objective: planResult.objective, step, tasks: results }));
228
- }
229
- else {
230
- const resultData = {
231
- step: {
232
- description: step.description,
233
- results: results.map((task) => ({
234
- agent: task.task.agent,
235
- task: task.task.description,
236
- result: task.result,
237
- })),
238
- },
239
- };
240
- result = JSON.stringify(resultData);
241
- }
242
- if (!result)
243
- throw new Error('unexpected empty result from synthesize step\'s tasks results');
244
- return {
245
- step,
246
- tasks: results,
247
- result,
248
- };
249
- }
250
- }
251
- exports.OrchestratorAgent = OrchestratorAgent;
252
- function getMessageOrJsonString(output) {
253
- const entries = Object.entries(output);
254
- const firstValue = entries[0]?.[1];
255
- if (entries.length === 1 && typeof firstValue === 'string') {
256
- return firstValue;
257
- }
258
- return JSON.stringify(output);
259
- }
260
- const orchestratorAgentOptionsSchema = zod_1.z.object({
261
- maxIterations: zod_1.z.number().optional(),
262
- tasksConcurrency: zod_1.z.number().optional(),
263
- chainStepResults: zod_1.z.boolean().optional(),
264
- });
@@ -1,130 +0,0 @@
1
- import type { Agent, Message } from '@aigne/core';
2
- import { z } from 'zod';
3
- /**
4
- * @hidden
5
- */
6
- export declare const SYNTHESIZE_PLAN_USER_PROMPT_TEMPLATE = "Synthesize the results of executing all steps in the plan into a cohesive result\n";
7
- /**
8
- * @hidden
9
- */
10
- export declare function getFullPlanSchema(agents: Agent[]): z.ZodObject<{
11
- steps: z.ZodArray<z.ZodObject<{
12
- description: z.ZodString;
13
- tasks: z.ZodArray<z.ZodObject<{
14
- description: z.ZodString;
15
- agent: z.ZodUnion<[z.ZodLiteral<string>, z.ZodLiteral<string>, ...z.ZodLiteral<string>[]]>;
16
- }, "strip", z.ZodTypeAny, {
17
- description: string;
18
- agent: string;
19
- }, {
20
- description: string;
21
- agent: string;
22
- }>, "many">;
23
- }, "strip", z.ZodTypeAny, {
24
- description: string;
25
- tasks: {
26
- description: string;
27
- agent: string;
28
- }[];
29
- }, {
30
- description: string;
31
- tasks: {
32
- description: string;
33
- agent: string;
34
- }[];
35
- }>, "many">;
36
- isComplete: z.ZodBoolean;
37
- }, "strip", z.ZodTypeAny, {
38
- steps: {
39
- description: string;
40
- tasks: {
41
- description: string;
42
- agent: string;
43
- }[];
44
- }[];
45
- isComplete: boolean;
46
- }, {
47
- steps: {
48
- description: string;
49
- tasks: {
50
- description: string;
51
- agent: string;
52
- }[];
53
- }[];
54
- isComplete: boolean;
55
- }>;
56
- /**
57
- * @hidden
58
- */
59
- export type FullPlanOutput = z.infer<ReturnType<typeof getFullPlanSchema>>;
60
- /**
61
- * @hidden
62
- */
63
- export type Step = FullPlanOutput['steps'][number];
64
- /**
65
- * @hidden
66
- */
67
- export type Task = Step['tasks'][number];
68
- /**
69
- * @hidden
70
- */
71
- export interface StepWithResult {
72
- step: Step;
73
- tasks: Array<TaskWithResult>;
74
- result: string;
75
- }
76
- /**
77
- * @hidden
78
- */
79
- export interface TaskWithResult {
80
- task: Task;
81
- result: string;
82
- }
83
- /**
84
- * @hidden
85
- */
86
- export interface FullPlanInput extends Message {
87
- objective: string;
88
- steps: StepWithResult[];
89
- plan: {
90
- status: string;
91
- result: string;
92
- };
93
- agents: {
94
- name: string;
95
- description?: string;
96
- tools: {
97
- name: string;
98
- description?: string;
99
- }[];
100
- }[];
101
- }
102
- /**
103
- * @hidden
104
- */
105
- export declare const FULL_PLAN_PROMPT_TEMPLATE = "You are tasked with orchestrating a plan to complete an objective.\nYou can analyze results from the previous steps already executed to decide if the objective is complete.\nYour plan must be structured in sequential steps, with each step containing independent parallel subtasks.\n\n<objective>\n{{objective}}\n</objective>\n\n<steps_completed>\n{{#steps}}\n- Step: {{step.description}}\n Result: {{result}}\n{{/steps}}\n</steps_completed>\n\n<previous_plan_status>\n{{plan.status}}\n</previous_plan_status>\n\n<previous_plan_result>\n{{plan.result}}\n</previous_plan_result>\n\nYou have access to the following Agents(which are collections of tools/functions):\n\n<agents>\n{{#agents}}\n- Agent: {{name}}\n Description: {{description}}\n Functions:\n {{#tools}}\n - Tool: {{name}}\n Description: {{description}}\n {{/tools}}\n{{/agents}}\n</agents>\n\n- If the previous plan results achieve the objective, return isComplete=true.\n- Otherwise, generate remaining steps needed.\n- Generate a plan with all remaining steps needed.\n- Steps are sequential, but each Step can have parallel subtasks.\n- For each Step, specify a description of the step and independent subtasks that can run in parallel.\n- For each subtask specify:\n 1. Clear description of the task that an LLM can execute\n 2. Name of 1 Agent to use for the task";
106
- /**
107
- * @hidden
108
- */
109
- export interface TaskPromptInput extends Message {
110
- objective: string;
111
- step: Step;
112
- task: Task;
113
- steps: StepWithResult[];
114
- }
115
- /**
116
- * @hidden
117
- */
118
- export declare const TASK_PROMPT_TEMPLATE = "You are part of a larger workflow to achieve the step then the objective:\n\n<objective>\n{{objective}}\n</objective>\n\n<step>\n{{step.description}}\n</step>\n\nYour job is to accomplish only the following task:\n\n<task>\n{{task.description}}\n</task>\n\nResults so far that may provide helpful context:\n\n<steps_completed>\n{{#steps}}\n- Step: {{step.description}}\n Result: {{result}}\n{{/steps}}\n</steps_completed>\n";
119
- /**
120
- * @hidden
121
- */
122
- export interface SynthesizeStepPromptInput extends Message {
123
- objective: string;
124
- step: Step;
125
- tasks: TaskWithResult[];
126
- }
127
- /**
128
- * @hidden
129
- */
130
- export declare const SYNTHESIZE_STEP_PROMPT_TEMPLATE = "Synthesize the results of these parallel tasks into a cohesive result\n\n<objective>\n{{objective}}\n</objective>\n\n<step>\n{{step.description}}\n</step>\n\n<tasks>\n{{#tasks}}\n- Task: {{task.description}}\n Result: {{result}}\n{{/tasks}}\n</tasks>\n";