@aigne/example-workflow-orchestrator 1.2.0 → 1.3.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.
Files changed (4) hide show
  1. package/README.md +28 -63
  2. package/index.ts +27 -56
  3. package/package.json +6 -4
  4. package/usage.ts +27 -56
package/README.md CHANGED
@@ -98,53 +98,44 @@ Here is the generated report for this example: [arcblock-deep-research.md](./gen
98
98
  ```typescript
99
99
  import assert from "node:assert";
100
100
  import { OrchestratorAgent } from "@aigne/agent-library";
101
- import {
102
- AIAgent,
103
- ChatModelOpenAI,
104
- ExecutionEngine,
105
- MCPAgent,
106
- } from "@aigne/core-next";
101
+ import { AIAgent, ExecutionEngine, MCPAgent, OpenAIChatModel } from "@aigne/core";
107
102
 
108
103
  const { OPENAI_API_KEY } = process.env;
109
104
  assert(OPENAI_API_KEY, "Please set the OPENAI_API_KEY environment variable");
110
105
 
111
- const model = new ChatModelOpenAI({
106
+ const model = new OpenAIChatModel({
112
107
  apiKey: OPENAI_API_KEY,
108
+ modelOptions: {
109
+ parallelToolCalls: false, // puppeteer can only run one task at a time
110
+ },
113
111
  });
114
112
 
115
113
  const puppeteer = await MCPAgent.from({
116
114
  command: "npx",
117
115
  args: ["-y", "@modelcontextprotocol/server-puppeteer"],
118
- env: {
119
- ...(process.env as Record<string, string>),
120
- },
116
+ env: process.env as Record<string, string>,
117
+ });
118
+
119
+ const filesystem = await MCPAgent.from({
120
+ command: "npx",
121
+ args: ["-y", "@modelcontextprotocol/server-filesystem", import.meta.dir],
121
122
  });
122
123
 
123
124
  const finder = AIAgent.from({
124
125
  name: "finder",
125
126
  description: "Find the closest match to a user's request",
126
- instructions: `You are an agent with access to the filesystem,
127
- as well as the ability to fetch URLs. Your job is to identify
128
- the closest match to a user's request, make the appropriate tool calls,
129
- and return the URI and CONTENTS of the closest match.
130
-
131
- Rules:
132
- - use document.body.innerText to get the text content of a page
133
- - if you want a url to some page, you should get all link and it's title of current(home) page,
134
- then you can use the title to search the url of the page you want to visit.
127
+ instructions: `You are an agent that can find information on the web.
128
+ You are tasked with finding the closest match to the user's request.
129
+ You can use puppeteer to scrape the web for information.
130
+ You can also use the filesystem to save the information you find.
131
+
132
+ Rules:
133
+ - do not use screenshot of puppeteer
134
+ - use document.body.innerText to get the text content of a page
135
+ - if you want a url to some page, you should get all link and it's title of current(home) page,
136
+ then you can use the title to search the url of the page you want to visit.
135
137
  `,
136
- tools: [puppeteer],
137
- });
138
-
139
- const enhancedFinder = OrchestratorAgent.from({
140
- name: "enhanced_finder",
141
- description: "Enhanced finder with more tools",
142
- tools: [finder],
143
- });
144
-
145
- const filesystem = await MCPAgent.from({
146
- command: "npx",
147
- args: ["-y", "@modelcontextprotocol/server-filesystem", import.meta.dir],
138
+ tools: [puppeteer, filesystem],
148
139
  });
149
140
 
150
141
  const writer = AIAgent.from({
@@ -156,52 +147,26 @@ const writer = AIAgent.from({
156
147
  tools: [filesystem],
157
148
  });
158
149
 
159
- const proofreader = AIAgent.from({
160
- name: "proofreader",
161
- description:
162
- "Review the short story for grammar, spelling, and punctuation errors",
163
- instructions: `Review the short story for grammar, spelling, and punctuation errors.
164
- Identify any awkward phrasing or structural issues that could improve clarity.
165
- Provide detailed feedback on corrections.`,
166
- tools: [],
167
- });
168
-
169
- const fact_checker = AIAgent.from({
170
- name: "fact_checker",
171
- description: "Verify the factual consistency within the story",
172
- instructions: `Verify the factual consistency within the story. Identify any contradictions,
173
- logical inconsistencies, or inaccuracies in the plot, character actions, or setting.
174
- Highlight potential issues with reasoning or coherence.`,
175
- tools: [],
176
- });
177
-
178
- const style_enforcer = AIAgent.from({
179
- name: "style_enforcer",
180
- description: "Analyze the story for adherence to style guidelines",
181
- instructions: `Analyze the story for adherence to style guidelines.
182
- Evaluate the narrative flow, clarity of expression, and tone. Suggest improvements to
183
- enhance storytelling, readability, and engagement.`,
184
- tools: [],
185
- });
186
-
187
150
  const agent = OrchestratorAgent.from({
188
- tools: [enhancedFinder, writer, proofreader, fact_checker, style_enforcer],
151
+ tools: [finder, writer],
152
+ maxIterations: 3,
153
+ tasksConcurrency: 1, // puppeteer can only run one task at a time
189
154
  });
190
155
 
191
156
  const engine = new ExecutionEngine({ model });
192
157
 
193
- const result = await engine.run(
158
+ const result = await engine.call(
159
+ agent,
194
160
  `\
195
161
  Conduct an in-depth research on ArcBlock using only the official website\
196
162
  (avoid search engines or third-party sources) and compile a detailed report saved as arcblock.md. \
197
163
  The report should include comprehensive insights into the company's products \
198
164
  (with detailed research findings and links), technical architecture, and future plans.`,
199
- agent
200
165
  );
201
166
  console.log(result);
202
167
  // Output:
203
168
  // {
204
- // text: "Having completed the research and documentation tasks focused on ArcBlock, the final deliverable, a comprehensive report titled \"arcblock.md,\" has been created. ...",
169
+ // $message: "The objective of conducting in-depth research on ArcBlock using only the official website has been successfully completed...",
205
170
  // }
206
171
  ```
207
172
 
package/index.ts CHANGED
@@ -4,52 +4,48 @@ import assert from "node:assert";
4
4
  import { OrchestratorAgent } from "@aigne/agent-library";
5
5
  import {
6
6
  AIAgent,
7
- ChatModelOpenAI,
8
7
  ExecutionEngine,
9
8
  MCPAgent,
9
+ OpenAIChatModel,
10
10
  runChatLoopInTerminal,
11
- } from "@aigne/core-next";
11
+ } from "@aigne/core";
12
12
 
13
13
  const { OPENAI_API_KEY } = process.env;
14
14
  assert(OPENAI_API_KEY, "Please set the OPENAI_API_KEY environment variable");
15
15
 
16
- const model = new ChatModelOpenAI({
16
+ const model = new OpenAIChatModel({
17
17
  apiKey: OPENAI_API_KEY,
18
+ modelOptions: {
19
+ parallelToolCalls: false, // puppeteer can only run one task at a time
20
+ },
18
21
  });
19
22
 
20
23
  const puppeteer = await MCPAgent.from({
21
24
  command: "npx",
22
25
  args: ["-y", "@modelcontextprotocol/server-puppeteer"],
23
- env: {
24
- ...(process.env as Record<string, string>),
25
- },
26
+ env: process.env as Record<string, string>,
27
+ });
28
+
29
+ const filesystem = await MCPAgent.from({
30
+ command: "npx",
31
+ args: ["-y", "@modelcontextprotocol/server-filesystem", import.meta.dir],
26
32
  });
27
33
 
28
34
  const finder = AIAgent.from({
29
35
  name: "finder",
30
36
  description: "Find the closest match to a user's request",
31
- instructions: `You are an agent with access to the filesystem,
32
- as well as the ability to fetch URLs. Your job is to identify
33
- the closest match to a user's request, make the appropriate tool calls,
34
- and return the URI and CONTENTS of the closest match.
35
-
36
- Rules:
37
- - use document.body.innerText to get the text content of a page
38
- - if you want a url to some page, you should get all link and it's title of current(home) page,
39
- then you can use the title to search the url of the page you want to visit.
37
+ instructions: `You are an agent that can find information on the web.
38
+ You are tasked with finding the closest match to the user's request.
39
+ You can use puppeteer to scrape the web for information.
40
+ You can also use the filesystem to save the information you find.
41
+
42
+ Rules:
43
+ - do not use screenshot of puppeteer
44
+ - use document.body.innerText to get the text content of a page
45
+ - if you want a url to some page, you should get all link and it's title of current(home) page,
46
+ then you can use the title to search the url of the page you want to visit.
40
47
  `,
41
- tools: [puppeteer],
42
- });
43
-
44
- const enhancedFinder = OrchestratorAgent.from({
45
- name: "enhanced_finder",
46
- description: "Enhanced finder with more tools",
47
- tools: [finder],
48
- });
49
-
50
- const filesystem = await MCPAgent.from({
51
- command: "npx",
52
- args: ["-y", "@modelcontextprotocol/server-filesystem", import.meta.dir],
48
+ tools: [puppeteer, filesystem],
53
49
  });
54
50
 
55
51
  const writer = AIAgent.from({
@@ -61,40 +57,15 @@ const writer = AIAgent.from({
61
57
  tools: [filesystem],
62
58
  });
63
59
 
64
- const proofreader = AIAgent.from({
65
- name: "proofreader",
66
- description: "Review the short story for grammar, spelling, and punctuation errors",
67
- instructions: `Review the short story for grammar, spelling, and punctuation errors.
68
- Identify any awkward phrasing or structural issues that could improve clarity.
69
- Provide detailed feedback on corrections.`,
70
- tools: [],
71
- });
72
-
73
- const fact_checker = AIAgent.from({
74
- name: "fact_checker",
75
- description: "Verify the factual consistency within the story",
76
- instructions: `Verify the factual consistency within the story. Identify any contradictions,
77
- logical inconsistencies, or inaccuracies in the plot, character actions, or setting.
78
- Highlight potential issues with reasoning or coherence.`,
79
- tools: [],
80
- });
81
-
82
- const style_enforcer = AIAgent.from({
83
- name: "style_enforcer",
84
- description: "Analyze the story for adherence to style guidelines",
85
- instructions: `Analyze the story for adherence to style guidelines.
86
- Evaluate the narrative flow, clarity of expression, and tone. Suggest improvements to
87
- enhance storytelling, readability, and engagement.`,
88
- tools: [],
89
- });
90
-
91
60
  const agent = OrchestratorAgent.from({
92
- tools: [enhancedFinder, writer, proofreader, fact_checker, style_enforcer],
61
+ tools: [finder, writer],
62
+ maxIterations: 3,
63
+ tasksConcurrency: 1, // puppeteer can only run one task at a time
93
64
  });
94
65
 
95
66
  const engine = new ExecutionEngine({ model });
96
67
 
97
- const userAgent = await engine.run(agent);
68
+ const userAgent = engine.call(agent);
98
69
 
99
70
  await runChatLoopInTerminal(userAgent, {
100
71
  welcome: "Welcome to the Orchestrator Agent!",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aigne/example-workflow-orchestrator",
3
- "version": "1.2.0",
3
+ "version": "1.3.1",
4
4
  "description": "A demonstration of using AIGNE Framework to build a orchestrator workflow",
5
5
  "author": "Arcblock <blocklet@arcblock.io> https://github.com/blocklet",
6
6
  "homepage": "https://github.com/AIGNE-io/aigne-framework/tree/main/examples/workflow-orchestrator",
@@ -16,11 +16,13 @@
16
16
  "README.md"
17
17
  ],
18
18
  "dependencies": {
19
+ "openai": "^4.89.0",
19
20
  "zod": "^3.24.2",
20
- "@aigne/agent-library": "^1.2.0",
21
- "@aigne/core-next": "^1.2.0"
21
+ "@aigne/agent-library": "^1.3.1",
22
+ "@aigne/core": "^1.4.0"
22
23
  },
23
24
  "scripts": {
24
- "start": "npx -y bun run index.ts"
25
+ "start": "npx -y bun run index.ts",
26
+ "lint": "tsc --noEmit"
25
27
  }
26
28
  }
package/usage.ts CHANGED
@@ -1,47 +1,43 @@
1
1
  import assert from "node:assert";
2
2
  import { OrchestratorAgent } from "@aigne/agent-library";
3
- import { AIAgent, ChatModelOpenAI, ExecutionEngine, MCPAgent } from "@aigne/core-next";
3
+ import { AIAgent, ExecutionEngine, MCPAgent, OpenAIChatModel } from "@aigne/core";
4
4
 
5
5
  const { OPENAI_API_KEY } = process.env;
6
6
  assert(OPENAI_API_KEY, "Please set the OPENAI_API_KEY environment variable");
7
7
 
8
- const model = new ChatModelOpenAI({
8
+ const model = new OpenAIChatModel({
9
9
  apiKey: OPENAI_API_KEY,
10
+ modelOptions: {
11
+ parallelToolCalls: false, // puppeteer can only run one task at a time
12
+ },
10
13
  });
11
14
 
12
15
  const puppeteer = await MCPAgent.from({
13
16
  command: "npx",
14
17
  args: ["-y", "@modelcontextprotocol/server-puppeteer"],
15
- env: {
16
- ...(process.env as Record<string, string>),
17
- },
18
+ env: process.env as Record<string, string>,
19
+ });
20
+
21
+ const filesystem = await MCPAgent.from({
22
+ command: "npx",
23
+ args: ["-y", "@modelcontextprotocol/server-filesystem", import.meta.dir],
18
24
  });
19
25
 
20
26
  const finder = AIAgent.from({
21
27
  name: "finder",
22
28
  description: "Find the closest match to a user's request",
23
- instructions: `You are an agent with access to the filesystem,
24
- as well as the ability to fetch URLs. Your job is to identify
25
- the closest match to a user's request, make the appropriate tool calls,
26
- and return the URI and CONTENTS of the closest match.
29
+ instructions: `You are an agent that can find information on the web.
30
+ You are tasked with finding the closest match to the user's request.
31
+ You can use puppeteer to scrape the web for information.
32
+ You can also use the filesystem to save the information you find.
27
33
 
28
- Rules:
29
- - use document.body.innerText to get the text content of a page
30
- - if you want a url to some page, you should get all link and it's title of current(home) page,
31
- then you can use the title to search the url of the page you want to visit.
34
+ Rules:
35
+ - do not use screenshot of puppeteer
36
+ - use document.body.innerText to get the text content of a page
37
+ - if you want a url to some page, you should get all link and it's title of current(home) page,
38
+ then you can use the title to search the url of the page you want to visit.
32
39
  `,
33
- tools: [puppeteer],
34
- });
35
-
36
- const enhancedFinder = OrchestratorAgent.from({
37
- name: "enhanced_finder",
38
- description: "Enhanced finder with more tools",
39
- tools: [finder],
40
- });
41
-
42
- const filesystem = await MCPAgent.from({
43
- command: "npx",
44
- args: ["-y", "@modelcontextprotocol/server-filesystem", import.meta.dir],
40
+ tools: [puppeteer, filesystem],
45
41
  });
46
42
 
47
43
  const writer = AIAgent.from({
@@ -53,49 +49,24 @@ const writer = AIAgent.from({
53
49
  tools: [filesystem],
54
50
  });
55
51
 
56
- const proofreader = AIAgent.from({
57
- name: "proofreader",
58
- description: "Review the short story for grammar, spelling, and punctuation errors",
59
- instructions: `Review the short story for grammar, spelling, and punctuation errors.
60
- Identify any awkward phrasing or structural issues that could improve clarity.
61
- Provide detailed feedback on corrections.`,
62
- tools: [],
63
- });
64
-
65
- const fact_checker = AIAgent.from({
66
- name: "fact_checker",
67
- description: "Verify the factual consistency within the story",
68
- instructions: `Verify the factual consistency within the story. Identify any contradictions,
69
- logical inconsistencies, or inaccuracies in the plot, character actions, or setting.
70
- Highlight potential issues with reasoning or coherence.`,
71
- tools: [],
72
- });
73
-
74
- const style_enforcer = AIAgent.from({
75
- name: "style_enforcer",
76
- description: "Analyze the story for adherence to style guidelines",
77
- instructions: `Analyze the story for adherence to style guidelines.
78
- Evaluate the narrative flow, clarity of expression, and tone. Suggest improvements to
79
- enhance storytelling, readability, and engagement.`,
80
- tools: [],
81
- });
82
-
83
52
  const agent = OrchestratorAgent.from({
84
- tools: [enhancedFinder, writer, proofreader, fact_checker, style_enforcer],
53
+ tools: [finder, writer],
54
+ maxIterations: 3,
55
+ tasksConcurrency: 1, // puppeteer can only run one task at a time
85
56
  });
86
57
 
87
58
  const engine = new ExecutionEngine({ model });
88
59
 
89
- const result = await engine.run(
60
+ const result = await engine.call(
61
+ agent,
90
62
  `\
91
63
  Conduct an in-depth research on ArcBlock using only the official website\
92
64
  (avoid search engines or third-party sources) and compile a detailed report saved as arcblock.md. \
93
65
  The report should include comprehensive insights into the company's products \
94
66
  (with detailed research findings and links), technical architecture, and future plans.`,
95
- agent,
96
67
  );
97
68
  console.log(result);
98
69
  // Output:
99
70
  // {
100
- // text: "Having completed the research and documentation tasks focused on ArcBlock, the final deliverable, a comprehensive report titled \"arcblock.md,\" has been created. ...",
71
+ // $message: "The objective of conducting in-depth research on ArcBlock using only the official website has been successfully completed...",
101
72
  // }