@aigne/example-workflow-orchestrator 1.3.0 → 1.3.2
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 +29 -56
- package/index.ts +26 -57
- package/package.json +4 -4
- package/usage.ts +28 -55
package/README.md
CHANGED
|
@@ -97,49 +97,46 @@ Here is the generated report for this example: [arcblock-deep-research.md](./gen
|
|
|
97
97
|
|
|
98
98
|
```typescript
|
|
99
99
|
import assert from "node:assert";
|
|
100
|
-
import { OrchestratorAgent } from "@aigne/agent-library";
|
|
101
|
-
import { AIAgent,
|
|
100
|
+
import { OrchestratorAgent } from "@aigne/agent-library/orchestrator/index.js";
|
|
101
|
+
import { AIAgent, ExecutionEngine, MCPAgent } from "@aigne/core";
|
|
102
|
+
import { OpenAIChatModel } from "@aigne/core/models/openai-chat-model.js";
|
|
102
103
|
|
|
103
104
|
const { OPENAI_API_KEY } = process.env;
|
|
104
105
|
assert(OPENAI_API_KEY, "Please set the OPENAI_API_KEY environment variable");
|
|
105
106
|
|
|
106
107
|
const model = new OpenAIChatModel({
|
|
107
108
|
apiKey: OPENAI_API_KEY,
|
|
109
|
+
modelOptions: {
|
|
110
|
+
parallelToolCalls: false, // puppeteer can only run one task at a time
|
|
111
|
+
},
|
|
108
112
|
});
|
|
109
113
|
|
|
110
114
|
const puppeteer = await MCPAgent.from({
|
|
111
115
|
command: "npx",
|
|
112
116
|
args: ["-y", "@modelcontextprotocol/server-puppeteer"],
|
|
113
|
-
env:
|
|
114
|
-
|
|
115
|
-
|
|
117
|
+
env: process.env as Record<string, string>,
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
const filesystem = await MCPAgent.from({
|
|
121
|
+
command: "npx",
|
|
122
|
+
args: ["-y", "@modelcontextprotocol/server-filesystem", import.meta.dir],
|
|
116
123
|
});
|
|
117
124
|
|
|
118
125
|
const finder = AIAgent.from({
|
|
119
126
|
name: "finder",
|
|
120
127
|
description: "Find the closest match to a user's request",
|
|
121
|
-
instructions: `You are an agent
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
128
|
+
instructions: `You are an agent that can find information on the web.
|
|
129
|
+
You are tasked with finding the closest match to the user's request.
|
|
130
|
+
You can use puppeteer to scrape the web for information.
|
|
131
|
+
You can also use the filesystem to save the information you find.
|
|
132
|
+
|
|
133
|
+
Rules:
|
|
134
|
+
- do not use screenshot of puppeteer
|
|
135
|
+
- use document.body.innerText to get the text content of a page
|
|
136
|
+
- if you want a url to some page, you should get all link and it's title of current(home) page,
|
|
137
|
+
then you can use the title to search the url of the page you want to visit.
|
|
130
138
|
`,
|
|
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],
|
|
139
|
+
tools: [puppeteer, filesystem],
|
|
143
140
|
});
|
|
144
141
|
|
|
145
142
|
const writer = AIAgent.from({
|
|
@@ -151,42 +148,18 @@ const writer = AIAgent.from({
|
|
|
151
148
|
tools: [filesystem],
|
|
152
149
|
});
|
|
153
150
|
|
|
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
151
|
const agent = OrchestratorAgent.from({
|
|
182
|
-
tools: [
|
|
152
|
+
tools: [finder, writer],
|
|
153
|
+
maxIterations: 3,
|
|
154
|
+
tasksConcurrency: 1, // puppeteer can only run one task at a time
|
|
183
155
|
});
|
|
184
156
|
|
|
185
157
|
const engine = new ExecutionEngine({ model });
|
|
186
158
|
|
|
187
159
|
const result = await engine.call(
|
|
188
160
|
agent,
|
|
189
|
-
|
|
161
|
+
`\
|
|
162
|
+
Conduct an in-depth research on ArcBlock using only the official website\
|
|
190
163
|
(avoid search engines or third-party sources) and compile a detailed report saved as arcblock.md. \
|
|
191
164
|
The report should include comprehensive insights into the company's products \
|
|
192
165
|
(with detailed research findings and links), technical architecture, and future plans.`,
|
|
@@ -194,7 +167,7 @@ The report should include comprehensive insights into the company's products \
|
|
|
194
167
|
console.log(result);
|
|
195
168
|
// Output:
|
|
196
169
|
// {
|
|
197
|
-
// $message: "
|
|
170
|
+
// $message: "The objective of conducting in-depth research on ArcBlock using only the official website has been successfully completed...",
|
|
198
171
|
// }
|
|
199
172
|
```
|
|
200
173
|
|
package/index.ts
CHANGED
|
@@ -1,20 +1,19 @@
|
|
|
1
1
|
#!/usr/bin/env npx -y bun
|
|
2
2
|
|
|
3
3
|
import assert from "node:assert";
|
|
4
|
-
import { OrchestratorAgent } from "@aigne/agent-library";
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
MCPAgent,
|
|
9
|
-
OpenAIChatModel,
|
|
10
|
-
runChatLoopInTerminal,
|
|
11
|
-
} from "@aigne/core";
|
|
4
|
+
import { OrchestratorAgent } from "@aigne/agent-library/orchestrator/index.js";
|
|
5
|
+
import { AIAgent, ExecutionEngine, MCPAgent } from "@aigne/core";
|
|
6
|
+
import { OpenAIChatModel } from "@aigne/core/models/openai-chat-model.js";
|
|
7
|
+
import { runChatLoopInTerminal } from "@aigne/core/utils/run-chat-loop.js";
|
|
12
8
|
|
|
13
9
|
const { OPENAI_API_KEY } = process.env;
|
|
14
10
|
assert(OPENAI_API_KEY, "Please set the OPENAI_API_KEY environment variable");
|
|
15
11
|
|
|
16
12
|
const model = new OpenAIChatModel({
|
|
17
13
|
apiKey: OPENAI_API_KEY,
|
|
14
|
+
modelOptions: {
|
|
15
|
+
parallelToolCalls: false, // puppeteer can only run one task at a time
|
|
16
|
+
},
|
|
18
17
|
});
|
|
19
18
|
|
|
20
19
|
const puppeteer = await MCPAgent.from({
|
|
@@ -23,31 +22,26 @@ const puppeteer = await MCPAgent.from({
|
|
|
23
22
|
env: process.env as Record<string, string>,
|
|
24
23
|
});
|
|
25
24
|
|
|
25
|
+
const filesystem = await MCPAgent.from({
|
|
26
|
+
command: "npx",
|
|
27
|
+
args: ["-y", "@modelcontextprotocol/server-filesystem", import.meta.dir],
|
|
28
|
+
});
|
|
29
|
+
|
|
26
30
|
const finder = AIAgent.from({
|
|
27
31
|
name: "finder",
|
|
28
32
|
description: "Find the closest match to a user's request",
|
|
29
|
-
instructions: `You are an agent
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
33
|
+
instructions: `You are an agent that can find information on the web.
|
|
34
|
+
You are tasked with finding the closest match to the user's request.
|
|
35
|
+
You can use puppeteer to scrape the web for information.
|
|
36
|
+
You can also use the filesystem to save the information you find.
|
|
37
|
+
|
|
38
|
+
Rules:
|
|
39
|
+
- do not use screenshot of puppeteer
|
|
40
|
+
- use document.body.innerText to get the text content of a page
|
|
41
|
+
- if you want a url to some page, you should get all link and it's title of current(home) page,
|
|
42
|
+
then you can use the title to search the url of the page you want to visit.
|
|
38
43
|
`,
|
|
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],
|
|
44
|
+
tools: [puppeteer, filesystem],
|
|
51
45
|
});
|
|
52
46
|
|
|
53
47
|
const writer = AIAgent.from({
|
|
@@ -59,35 +53,10 @@ const writer = AIAgent.from({
|
|
|
59
53
|
tools: [filesystem],
|
|
60
54
|
});
|
|
61
55
|
|
|
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
56
|
const agent = OrchestratorAgent.from({
|
|
90
|
-
tools: [
|
|
57
|
+
tools: [finder, writer],
|
|
58
|
+
maxIterations: 3,
|
|
59
|
+
tasksConcurrency: 1, // puppeteer can only run one task at a time
|
|
91
60
|
});
|
|
92
61
|
|
|
93
62
|
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.2",
|
|
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,10 +16,10 @@
|
|
|
16
16
|
"README.md"
|
|
17
17
|
],
|
|
18
18
|
"dependencies": {
|
|
19
|
-
"openai": "^4.89.
|
|
19
|
+
"openai": "^4.89.1",
|
|
20
20
|
"zod": "^3.24.2",
|
|
21
|
-
"@aigne/agent-library": "^1.3.
|
|
22
|
-
"@aigne/core": "^1.
|
|
21
|
+
"@aigne/agent-library": "^1.3.2",
|
|
22
|
+
"@aigne/core": "^1.5.0"
|
|
23
23
|
},
|
|
24
24
|
"scripts": {
|
|
25
25
|
"start": "npx -y bun run index.ts",
|
package/usage.ts
CHANGED
|
@@ -1,47 +1,44 @@
|
|
|
1
1
|
import assert from "node:assert";
|
|
2
|
-
import { OrchestratorAgent } from "@aigne/agent-library";
|
|
3
|
-
import { AIAgent, ExecutionEngine, MCPAgent
|
|
2
|
+
import { OrchestratorAgent } from "@aigne/agent-library/orchestrator/index.js";
|
|
3
|
+
import { AIAgent, ExecutionEngine, MCPAgent } from "@aigne/core";
|
|
4
|
+
import { OpenAIChatModel } from "@aigne/core/models/openai-chat-model.js";
|
|
4
5
|
|
|
5
6
|
const { OPENAI_API_KEY } = process.env;
|
|
6
7
|
assert(OPENAI_API_KEY, "Please set the OPENAI_API_KEY environment variable");
|
|
7
8
|
|
|
8
9
|
const model = new OpenAIChatModel({
|
|
9
10
|
apiKey: OPENAI_API_KEY,
|
|
11
|
+
modelOptions: {
|
|
12
|
+
parallelToolCalls: false, // puppeteer can only run one task at a time
|
|
13
|
+
},
|
|
10
14
|
});
|
|
11
15
|
|
|
12
16
|
const puppeteer = await MCPAgent.from({
|
|
13
17
|
command: "npx",
|
|
14
18
|
args: ["-y", "@modelcontextprotocol/server-puppeteer"],
|
|
15
|
-
env:
|
|
16
|
-
|
|
17
|
-
|
|
19
|
+
env: process.env as Record<string, string>,
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
const filesystem = await MCPAgent.from({
|
|
23
|
+
command: "npx",
|
|
24
|
+
args: ["-y", "@modelcontextprotocol/server-filesystem", import.meta.dir],
|
|
18
25
|
});
|
|
19
26
|
|
|
20
27
|
const finder = AIAgent.from({
|
|
21
28
|
name: "finder",
|
|
22
29
|
description: "Find the closest match to a user's request",
|
|
23
|
-
instructions: `You are an agent
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
30
|
+
instructions: `You are an agent that can find information on the web.
|
|
31
|
+
You are tasked with finding the closest match to the user's request.
|
|
32
|
+
You can use puppeteer to scrape the web for information.
|
|
33
|
+
You can also use the filesystem to save the information you find.
|
|
27
34
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
35
|
+
Rules:
|
|
36
|
+
- do not use screenshot of puppeteer
|
|
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.
|
|
32
40
|
`,
|
|
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],
|
|
41
|
+
tools: [puppeteer, filesystem],
|
|
45
42
|
});
|
|
46
43
|
|
|
47
44
|
const writer = AIAgent.from({
|
|
@@ -53,42 +50,18 @@ const writer = AIAgent.from({
|
|
|
53
50
|
tools: [filesystem],
|
|
54
51
|
});
|
|
55
52
|
|
|
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
53
|
const agent = OrchestratorAgent.from({
|
|
84
|
-
tools: [
|
|
54
|
+
tools: [finder, writer],
|
|
55
|
+
maxIterations: 3,
|
|
56
|
+
tasksConcurrency: 1, // puppeteer can only run one task at a time
|
|
85
57
|
});
|
|
86
58
|
|
|
87
59
|
const engine = new ExecutionEngine({ model });
|
|
88
60
|
|
|
89
61
|
const result = await engine.call(
|
|
90
62
|
agent,
|
|
91
|
-
|
|
63
|
+
`\
|
|
64
|
+
Conduct an in-depth research on ArcBlock using only the official website\
|
|
92
65
|
(avoid search engines or third-party sources) and compile a detailed report saved as arcblock.md. \
|
|
93
66
|
The report should include comprehensive insights into the company's products \
|
|
94
67
|
(with detailed research findings and links), technical architecture, and future plans.`,
|
|
@@ -96,5 +69,5 @@ The report should include comprehensive insights into the company's products \
|
|
|
96
69
|
console.log(result);
|
|
97
70
|
// Output:
|
|
98
71
|
// {
|
|
99
|
-
// $message: "
|
|
72
|
+
// $message: "The objective of conducting in-depth research on ArcBlock using only the official website has been successfully completed...",
|
|
100
73
|
// }
|