@aigne/example-workflow-orchestrator 1.3.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.
- package/README.md +27 -55
- package/index.ts +22 -49
- package/package.json +3 -3
- package/usage.ts +25 -53
package/README.md
CHANGED
|
@@ -98,48 +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 { AIAgent,
|
|
101
|
+
import { AIAgent, ExecutionEngine, MCPAgent, OpenAIChatModel } from "@aigne/core";
|
|
102
102
|
|
|
103
103
|
const { OPENAI_API_KEY } = process.env;
|
|
104
104
|
assert(OPENAI_API_KEY, "Please set the OPENAI_API_KEY environment variable");
|
|
105
105
|
|
|
106
106
|
const model = new OpenAIChatModel({
|
|
107
107
|
apiKey: OPENAI_API_KEY,
|
|
108
|
+
modelOptions: {
|
|
109
|
+
parallelToolCalls: false, // puppeteer can only run one task at a time
|
|
110
|
+
},
|
|
108
111
|
});
|
|
109
112
|
|
|
110
113
|
const puppeteer = await MCPAgent.from({
|
|
111
114
|
command: "npx",
|
|
112
115
|
args: ["-y", "@modelcontextprotocol/server-puppeteer"],
|
|
113
|
-
env:
|
|
114
|
-
|
|
115
|
-
|
|
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],
|
|
116
122
|
});
|
|
117
123
|
|
|
118
124
|
const finder = AIAgent.from({
|
|
119
125
|
name: "finder",
|
|
120
126
|
description: "Find the closest match to a user's request",
|
|
121
|
-
instructions: `You are an agent
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
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.
|
|
130
137
|
`,
|
|
131
|
-
tools: [puppeteer],
|
|
132
|
-
});
|
|
133
|
-
|
|
134
|
-
const enhancedFinder = OrchestratorAgent.from({
|
|
135
|
-
name: "enhanced_finder",
|
|
136
|
-
description: "Enhanced finder with more tools",
|
|
137
|
-
tools: [finder],
|
|
138
|
-
});
|
|
139
|
-
|
|
140
|
-
const filesystem = await MCPAgent.from({
|
|
141
|
-
command: "npx",
|
|
142
|
-
args: ["-y", "@modelcontextprotocol/server-filesystem", import.meta.dir],
|
|
138
|
+
tools: [puppeteer, filesystem],
|
|
143
139
|
});
|
|
144
140
|
|
|
145
141
|
const writer = AIAgent.from({
|
|
@@ -151,42 +147,18 @@ const writer = AIAgent.from({
|
|
|
151
147
|
tools: [filesystem],
|
|
152
148
|
});
|
|
153
149
|
|
|
154
|
-
const proofreader = AIAgent.from({
|
|
155
|
-
name: "proofreader",
|
|
156
|
-
description: "Review the short story for grammar, spelling, and punctuation errors",
|
|
157
|
-
instructions: `Review the short story for grammar, spelling, and punctuation errors.
|
|
158
|
-
Identify any awkward phrasing or structural issues that could improve clarity.
|
|
159
|
-
Provide detailed feedback on corrections.`,
|
|
160
|
-
tools: [],
|
|
161
|
-
});
|
|
162
|
-
|
|
163
|
-
const fact_checker = AIAgent.from({
|
|
164
|
-
name: "fact_checker",
|
|
165
|
-
description: "Verify the factual consistency within the story",
|
|
166
|
-
instructions: `Verify the factual consistency within the story. Identify any contradictions,
|
|
167
|
-
logical inconsistencies, or inaccuracies in the plot, character actions, or setting.
|
|
168
|
-
Highlight potential issues with reasoning or coherence.`,
|
|
169
|
-
tools: [],
|
|
170
|
-
});
|
|
171
|
-
|
|
172
|
-
const style_enforcer = AIAgent.from({
|
|
173
|
-
name: "style_enforcer",
|
|
174
|
-
description: "Analyze the story for adherence to style guidelines",
|
|
175
|
-
instructions: `Analyze the story for adherence to style guidelines.
|
|
176
|
-
Evaluate the narrative flow, clarity of expression, and tone. Suggest improvements to
|
|
177
|
-
enhance storytelling, readability, and engagement.`,
|
|
178
|
-
tools: [],
|
|
179
|
-
});
|
|
180
|
-
|
|
181
150
|
const agent = OrchestratorAgent.from({
|
|
182
|
-
tools: [
|
|
151
|
+
tools: [finder, writer],
|
|
152
|
+
maxIterations: 3,
|
|
153
|
+
tasksConcurrency: 1, // puppeteer can only run one task at a time
|
|
183
154
|
});
|
|
184
155
|
|
|
185
156
|
const engine = new ExecutionEngine({ model });
|
|
186
157
|
|
|
187
158
|
const result = await engine.call(
|
|
188
159
|
agent,
|
|
189
|
-
|
|
160
|
+
`\
|
|
161
|
+
Conduct an in-depth research on ArcBlock using only the official website\
|
|
190
162
|
(avoid search engines or third-party sources) and compile a detailed report saved as arcblock.md. \
|
|
191
163
|
The report should include comprehensive insights into the company's products \
|
|
192
164
|
(with detailed research findings and links), technical architecture, and future plans.`,
|
|
@@ -194,7 +166,7 @@ The report should include comprehensive insights into the company's products \
|
|
|
194
166
|
console.log(result);
|
|
195
167
|
// Output:
|
|
196
168
|
// {
|
|
197
|
-
// $message: "
|
|
169
|
+
// $message: "The objective of conducting in-depth research on ArcBlock using only the official website has been successfully completed...",
|
|
198
170
|
// }
|
|
199
171
|
```
|
|
200
172
|
|
package/index.ts
CHANGED
|
@@ -15,6 +15,9 @@ assert(OPENAI_API_KEY, "Please set the OPENAI_API_KEY environment variable");
|
|
|
15
15
|
|
|
16
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({
|
|
@@ -23,31 +26,26 @@ const puppeteer = await MCPAgent.from({
|
|
|
23
26
|
env: process.env as Record<string, string>,
|
|
24
27
|
});
|
|
25
28
|
|
|
29
|
+
const filesystem = await MCPAgent.from({
|
|
30
|
+
command: "npx",
|
|
31
|
+
args: ["-y", "@modelcontextprotocol/server-filesystem", import.meta.dir],
|
|
32
|
+
});
|
|
33
|
+
|
|
26
34
|
const finder = AIAgent.from({
|
|
27
35
|
name: "finder",
|
|
28
36
|
description: "Find the closest match to a user's request",
|
|
29
|
-
instructions: `You are an agent
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
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.
|
|
38
47
|
`,
|
|
39
|
-
tools: [puppeteer],
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
const enhancedFinder = OrchestratorAgent.from({
|
|
43
|
-
name: "enhanced_finder",
|
|
44
|
-
description: "Enhanced finder with more tools",
|
|
45
|
-
tools: [finder],
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
const filesystem = await MCPAgent.from({
|
|
49
|
-
command: "npx",
|
|
50
|
-
args: ["-y", "@modelcontextprotocol/server-filesystem", import.meta.dir],
|
|
48
|
+
tools: [puppeteer, filesystem],
|
|
51
49
|
});
|
|
52
50
|
|
|
53
51
|
const writer = AIAgent.from({
|
|
@@ -59,35 +57,10 @@ const writer = AIAgent.from({
|
|
|
59
57
|
tools: [filesystem],
|
|
60
58
|
});
|
|
61
59
|
|
|
62
|
-
const proofreader = AIAgent.from({
|
|
63
|
-
name: "proofreader",
|
|
64
|
-
description: "Review the short story for grammar, spelling, and punctuation errors",
|
|
65
|
-
instructions: `Review the short story for grammar, spelling, and punctuation errors.
|
|
66
|
-
Identify any awkward phrasing or structural issues that could improve clarity.
|
|
67
|
-
Provide detailed feedback on corrections.`,
|
|
68
|
-
tools: [],
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
const fact_checker = AIAgent.from({
|
|
72
|
-
name: "fact_checker",
|
|
73
|
-
description: "Verify the factual consistency within the story",
|
|
74
|
-
instructions: `Verify the factual consistency within the story. Identify any contradictions,
|
|
75
|
-
logical inconsistencies, or inaccuracies in the plot, character actions, or setting.
|
|
76
|
-
Highlight potential issues with reasoning or coherence.`,
|
|
77
|
-
tools: [],
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
const style_enforcer = AIAgent.from({
|
|
81
|
-
name: "style_enforcer",
|
|
82
|
-
description: "Analyze the story for adherence to style guidelines",
|
|
83
|
-
instructions: `Analyze the story for adherence to style guidelines.
|
|
84
|
-
Evaluate the narrative flow, clarity of expression, and tone. Suggest improvements to
|
|
85
|
-
enhance storytelling, readability, and engagement.`,
|
|
86
|
-
tools: [],
|
|
87
|
-
});
|
|
88
|
-
|
|
89
60
|
const agent = OrchestratorAgent.from({
|
|
90
|
-
tools: [
|
|
61
|
+
tools: [finder, writer],
|
|
62
|
+
maxIterations: 3,
|
|
63
|
+
tasksConcurrency: 1, // puppeteer can only run one task at a time
|
|
91
64
|
});
|
|
92
65
|
|
|
93
66
|
const engine = new ExecutionEngine({ model });
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aigne/example-workflow-orchestrator",
|
|
3
|
-
"version": "1.3.
|
|
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",
|
|
@@ -18,8 +18,8 @@
|
|
|
18
18
|
"dependencies": {
|
|
19
19
|
"openai": "^4.89.0",
|
|
20
20
|
"zod": "^3.24.2",
|
|
21
|
-
"@aigne/agent-library": "^1.3.
|
|
22
|
-
"@aigne/core": "^1.
|
|
21
|
+
"@aigne/agent-library": "^1.3.1",
|
|
22
|
+
"@aigne/core": "^1.4.0"
|
|
23
23
|
},
|
|
24
24
|
"scripts": {
|
|
25
25
|
"start": "npx -y bun run index.ts",
|
package/usage.ts
CHANGED
|
@@ -7,41 +7,37 @@ assert(OPENAI_API_KEY, "Please set the OPENAI_API_KEY environment variable");
|
|
|
7
7
|
|
|
8
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
|
-
|
|
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
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
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
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
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,42 +49,18 @@ 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: [
|
|
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
60
|
const result = await engine.call(
|
|
90
61
|
agent,
|
|
91
|
-
|
|
62
|
+
`\
|
|
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.`,
|
|
@@ -96,5 +68,5 @@ The report should include comprehensive insights into the company's products \
|
|
|
96
68
|
console.log(result);
|
|
97
69
|
// Output:
|
|
98
70
|
// {
|
|
99
|
-
// $message: "
|
|
71
|
+
// $message: "The objective of conducting in-depth research on ArcBlock using only the official website has been successfully completed...",
|
|
100
72
|
// }
|