@aigne/example-workflow-orchestrator 1.1.0-beta.12
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/.env.local.example +5 -0
- package/README.md +192 -0
- package/index.ts +105 -0
- package/package.json +26 -0
- package/usage.ts +98 -0
package/README.md
ADDED
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
# Workflow Orchestrator Demo
|
|
2
|
+
|
|
3
|
+
This is a demonstration of using [AIGNE Framework](https://github.com/AIGNE-io/aigne-framework) to build a orchestrator workflow.
|
|
4
|
+
|
|
5
|
+
```mermaid
|
|
6
|
+
flowchart LR
|
|
7
|
+
|
|
8
|
+
in(In)
|
|
9
|
+
out(Out)
|
|
10
|
+
orchestrator(Orchestrator)
|
|
11
|
+
synthesizer(Synthesizer)
|
|
12
|
+
finder(Finder)
|
|
13
|
+
writer(Writer)
|
|
14
|
+
proofreader(Proofreader)
|
|
15
|
+
fact_checker(Fact Checker)
|
|
16
|
+
style_enforcer(Style Enforcer)
|
|
17
|
+
|
|
18
|
+
in ==> orchestrator
|
|
19
|
+
orchestrator -.-> finder -.-> synthesizer
|
|
20
|
+
orchestrator -.-> writer -.-> synthesizer
|
|
21
|
+
orchestrator -.-> proofreader -.-> synthesizer
|
|
22
|
+
orchestrator -.-> fact_checker -.-> synthesizer
|
|
23
|
+
orchestrator -.-> style_enforcer -.-> synthesizer
|
|
24
|
+
synthesizer ==> out
|
|
25
|
+
|
|
26
|
+
classDef inputOutput fill:#f9f0ed,stroke:#debbae,stroke-width:2px,color:#b35b39,font-weight:bolder;
|
|
27
|
+
classDef processing fill:#F0F4EB,stroke:#C2D7A7,stroke-width:2px,color:#6B8F3C,font-weight:bolder;
|
|
28
|
+
|
|
29
|
+
class in inputOutput
|
|
30
|
+
class out inputOutput
|
|
31
|
+
class orchestrator processing
|
|
32
|
+
class synthesizer processing
|
|
33
|
+
class finder processing
|
|
34
|
+
class writer processing
|
|
35
|
+
class proofreader processing
|
|
36
|
+
class fact_checker processing
|
|
37
|
+
class style_enforcer processing
|
|
38
|
+
```
|
|
39
|
+
## Prerequisites
|
|
40
|
+
|
|
41
|
+
- [Node.js](https://nodejs.org) and npm installed on your machine
|
|
42
|
+
- [OpenAI API key](https://platform.openai.com/api-keys) used to interact with OpenAI API
|
|
43
|
+
- [Pnpm](https://pnpm.io) [Optional] if you want to run the example from source code
|
|
44
|
+
|
|
45
|
+
## Try without Installation
|
|
46
|
+
|
|
47
|
+
```bash
|
|
48
|
+
export OPENAI_API_KEY=YOUR_OPENAI_API_KEY # setup your OpenAI API key
|
|
49
|
+
|
|
50
|
+
npx -y @aigne/example-workflow-orchestrator # run the example
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
## Installation
|
|
54
|
+
|
|
55
|
+
### Clone the Repository
|
|
56
|
+
|
|
57
|
+
```bash
|
|
58
|
+
git clone https://github.com/AIGNE-io/aigne-framework
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
### Install Dependencies
|
|
62
|
+
|
|
63
|
+
```bash
|
|
64
|
+
cd aigne-framework/examples/workflow-orchestrator
|
|
65
|
+
|
|
66
|
+
pnpm install
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
### Setup Environment Variables
|
|
70
|
+
|
|
71
|
+
Setup your OpenAI API key in the `.env.local` file:
|
|
72
|
+
|
|
73
|
+
```bash
|
|
74
|
+
OPENAI_API_KEY="" # setup your OpenAI API key here
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
### Run the Example
|
|
78
|
+
|
|
79
|
+
```bash
|
|
80
|
+
pnpm start
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
## Example
|
|
84
|
+
|
|
85
|
+
The following example demonstrates how to build a orchestrator workflow:
|
|
86
|
+
|
|
87
|
+
Here is the generated report for this example: [arcblock-deep-research.md](./generated-report-arcblock.md)
|
|
88
|
+
|
|
89
|
+
```typescript
|
|
90
|
+
import assert from "node:assert";
|
|
91
|
+
import { OrchestratorAgent } from "@aigne/agent-library";
|
|
92
|
+
import { AIAgent, ChatModelOpenAI, ExecutionEngine, MCPAgent } from "@aigne/core-next";
|
|
93
|
+
|
|
94
|
+
const { OPENAI_API_KEY } = process.env;
|
|
95
|
+
assert(OPENAI_API_KEY, "Please set the OPENAI_API_KEY environment variable");
|
|
96
|
+
|
|
97
|
+
const model = new ChatModelOpenAI({
|
|
98
|
+
apiKey: OPENAI_API_KEY,
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
const puppeteer = await MCPAgent.from({
|
|
102
|
+
command: "npx",
|
|
103
|
+
args: ["-y", "@modelcontextprotocol/server-puppeteer"],
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
const finder = AIAgent.from({
|
|
107
|
+
name: "finder",
|
|
108
|
+
description: "Find the closest match to a user's request",
|
|
109
|
+
instructions: `You are an agent with access to the filesystem,
|
|
110
|
+
as well as the ability to fetch URLs. Your job is to identify
|
|
111
|
+
the closest match to a user's request, make the appropriate tool calls,
|
|
112
|
+
and return the URI and CONTENTS of the closest match.
|
|
113
|
+
|
|
114
|
+
Rules:
|
|
115
|
+
- use document.body.innerText to get the text content of a page
|
|
116
|
+
- if you want a url to some page, you should get all link and it's title of current(home) page,
|
|
117
|
+
then you can use the title to search the url of the page you want to visit.
|
|
118
|
+
`,
|
|
119
|
+
tools: [puppeteer],
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
const enhancedFinder = OrchestratorAgent.from({
|
|
123
|
+
name: "enhanced_finder",
|
|
124
|
+
description: "Enhanced finder with more tools",
|
|
125
|
+
tools: [finder],
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
const filesystem = await MCPAgent.from({
|
|
129
|
+
command: "npx",
|
|
130
|
+
args: ["-y", "@modelcontextprotocol/server-filesystem", import.meta.dir],
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
const writer = AIAgent.from({
|
|
134
|
+
name: "writer",
|
|
135
|
+
description: "Write to the filesystem",
|
|
136
|
+
instructions: `You are an agent that can write to the filesystem.
|
|
137
|
+
You are tasked with taking the user's input, addressing it, and
|
|
138
|
+
writing the result to disk in the appropriate location.`,
|
|
139
|
+
tools: [filesystem],
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
const proofreader = AIAgent.from({
|
|
143
|
+
name: "proofreader",
|
|
144
|
+
description: "Review the short story for grammar, spelling, and punctuation errors",
|
|
145
|
+
instructions: `Review the short story for grammar, spelling, and punctuation errors.
|
|
146
|
+
Identify any awkward phrasing or structural issues that could improve clarity.
|
|
147
|
+
Provide detailed feedback on corrections.`,
|
|
148
|
+
tools: [],
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
const fact_checker = AIAgent.from({
|
|
152
|
+
name: "fact_checker",
|
|
153
|
+
description: "Verify the factual consistency within the story",
|
|
154
|
+
instructions: `Verify the factual consistency within the story. Identify any contradictions,
|
|
155
|
+
logical inconsistencies, or inaccuracies in the plot, character actions, or setting.
|
|
156
|
+
Highlight potential issues with reasoning or coherence.`,
|
|
157
|
+
tools: [],
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
const style_enforcer = AIAgent.from({
|
|
161
|
+
name: "style_enforcer",
|
|
162
|
+
description: "Analyze the story for adherence to style guidelines",
|
|
163
|
+
instructions: `Analyze the story for adherence to style guidelines.
|
|
164
|
+
Evaluate the narrative flow, clarity of expression, and tone. Suggest improvements to
|
|
165
|
+
enhance storytelling, readability, and engagement.`,
|
|
166
|
+
tools: [],
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
const agent = OrchestratorAgent.from({
|
|
170
|
+
tools: [enhancedFinder, writer, proofreader, fact_checker, style_enforcer],
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
const engine = new ExecutionEngine({ model });
|
|
174
|
+
|
|
175
|
+
const result = await engine.run(
|
|
176
|
+
`\
|
|
177
|
+
Conduct an in-depth research on ArcBlock using only the official website\
|
|
178
|
+
(avoid search engines or third-party sources) and compile a detailed report saved as arcblock.md. \
|
|
179
|
+
The report should include comprehensive insights into the company's products \
|
|
180
|
+
(with detailed research findings and links), technical architecture, and future plans.`,
|
|
181
|
+
agent,
|
|
182
|
+
);
|
|
183
|
+
console.log(result);
|
|
184
|
+
// Output:
|
|
185
|
+
// {
|
|
186
|
+
// text: "Having completed the research and documentation tasks focused on ArcBlock, the final deliverable, a comprehensive report titled \"arcblock.md,\" has been created. ...",
|
|
187
|
+
// }
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
## License
|
|
191
|
+
|
|
192
|
+
This project is licensed under the MIT License.
|
package/index.ts
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
#!/usr/bin/env npx -y bun
|
|
2
|
+
|
|
3
|
+
import assert from "node:assert";
|
|
4
|
+
import { OrchestratorAgent } from "@aigne/agent-library";
|
|
5
|
+
import {
|
|
6
|
+
AIAgent,
|
|
7
|
+
ChatModelOpenAI,
|
|
8
|
+
ExecutionEngine,
|
|
9
|
+
MCPAgent,
|
|
10
|
+
runChatLoopInTerminal,
|
|
11
|
+
} from "@aigne/core-next";
|
|
12
|
+
|
|
13
|
+
const { OPENAI_API_KEY } = process.env;
|
|
14
|
+
assert(OPENAI_API_KEY, "Please set the OPENAI_API_KEY environment variable");
|
|
15
|
+
|
|
16
|
+
const model = new ChatModelOpenAI({
|
|
17
|
+
apiKey: OPENAI_API_KEY,
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
const puppeteer = await MCPAgent.from({
|
|
21
|
+
command: "npx",
|
|
22
|
+
args: ["-y", "@modelcontextprotocol/server-puppeteer"],
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
const finder = AIAgent.from({
|
|
26
|
+
name: "finder",
|
|
27
|
+
description: "Find the closest match to a user's request",
|
|
28
|
+
instructions: `You are an agent with access to the filesystem,
|
|
29
|
+
as well as the ability to fetch URLs. Your job is to identify
|
|
30
|
+
the closest match to a user's request, make the appropriate tool calls,
|
|
31
|
+
and return the URI and CONTENTS of the closest match.
|
|
32
|
+
|
|
33
|
+
Rules:
|
|
34
|
+
- use document.body.innerText to get the text content of a page
|
|
35
|
+
- if you want a url to some page, you should get all link and it's title of current(home) page,
|
|
36
|
+
then you can use the title to search the url of the page you want to visit.
|
|
37
|
+
`,
|
|
38
|
+
tools: [puppeteer],
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
const enhancedFinder = OrchestratorAgent.from({
|
|
42
|
+
name: "enhanced_finder",
|
|
43
|
+
description: "Enhanced finder with more tools",
|
|
44
|
+
tools: [finder],
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
const filesystem = await MCPAgent.from({
|
|
48
|
+
command: "npx",
|
|
49
|
+
args: ["-y", "@modelcontextprotocol/server-filesystem", import.meta.dir],
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
const writer = AIAgent.from({
|
|
53
|
+
name: "writer",
|
|
54
|
+
description: "Write to the filesystem",
|
|
55
|
+
instructions: `You are an agent that can write to the filesystem.
|
|
56
|
+
You are tasked with taking the user's input, addressing it, and
|
|
57
|
+
writing the result to disk in the appropriate location.`,
|
|
58
|
+
tools: [filesystem],
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
const proofreader = AIAgent.from({
|
|
62
|
+
name: "proofreader",
|
|
63
|
+
description: "Review the short story for grammar, spelling, and punctuation errors",
|
|
64
|
+
instructions: `Review the short story for grammar, spelling, and punctuation errors.
|
|
65
|
+
Identify any awkward phrasing or structural issues that could improve clarity.
|
|
66
|
+
Provide detailed feedback on corrections.`,
|
|
67
|
+
tools: [],
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
const fact_checker = AIAgent.from({
|
|
71
|
+
name: "fact_checker",
|
|
72
|
+
description: "Verify the factual consistency within the story",
|
|
73
|
+
instructions: `Verify the factual consistency within the story. Identify any contradictions,
|
|
74
|
+
logical inconsistencies, or inaccuracies in the plot, character actions, or setting.
|
|
75
|
+
Highlight potential issues with reasoning or coherence.`,
|
|
76
|
+
tools: [],
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
const style_enforcer = AIAgent.from({
|
|
80
|
+
name: "style_enforcer",
|
|
81
|
+
description: "Analyze the story for adherence to style guidelines",
|
|
82
|
+
instructions: `Analyze the story for adherence to style guidelines.
|
|
83
|
+
Evaluate the narrative flow, clarity of expression, and tone. Suggest improvements to
|
|
84
|
+
enhance storytelling, readability, and engagement.`,
|
|
85
|
+
tools: [],
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
const agent = OrchestratorAgent.from({
|
|
89
|
+
tools: [enhancedFinder, writer, proofreader, fact_checker, style_enforcer],
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
const engine = new ExecutionEngine({ model });
|
|
93
|
+
|
|
94
|
+
const userAgent = await engine.run(agent);
|
|
95
|
+
|
|
96
|
+
await runChatLoopInTerminal(userAgent, {
|
|
97
|
+
welcome: "Welcome to the Orchestrator Agent!",
|
|
98
|
+
defaultQuestion: `\
|
|
99
|
+
Conduct an in-depth research on ArcBlock using only the official website\
|
|
100
|
+
(avoid search engines or third-party sources) and compile a detailed report saved as arcblock.md. \
|
|
101
|
+
The report should include comprehensive insights into the company's products \
|
|
102
|
+
(with detailed research findings and links), technical architecture, and future plans.`,
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
process.exit(0);
|
package/package.json
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@aigne/example-workflow-orchestrator",
|
|
3
|
+
"version": "1.1.0-beta.12",
|
|
4
|
+
"description": "A demonstration of using AIGNE Framework to build a orchestrator workflow",
|
|
5
|
+
"author": "Arcblock <blocklet@arcblock.io> https://github.com/blocklet",
|
|
6
|
+
"homepage": "https://github.com/AIGNE-io/aigne-framework/tree/main/examples/workflow-orchestrator",
|
|
7
|
+
"license": "ISC",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "git+https://github.com/AIGNE-io/aigne-framework"
|
|
11
|
+
},
|
|
12
|
+
"bin": "index.ts",
|
|
13
|
+
"files": [
|
|
14
|
+
".env.local.example",
|
|
15
|
+
"*.ts",
|
|
16
|
+
"README.md"
|
|
17
|
+
],
|
|
18
|
+
"dependencies": {
|
|
19
|
+
"zod": "^3.24.2",
|
|
20
|
+
"@aigne/agent-library": "^1.1.0-beta.12",
|
|
21
|
+
"@aigne/core-next": "^1.1.0-beta.12"
|
|
22
|
+
},
|
|
23
|
+
"scripts": {
|
|
24
|
+
"start": "npx -y bun run index.ts"
|
|
25
|
+
}
|
|
26
|
+
}
|
package/usage.ts
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import assert from "node:assert";
|
|
2
|
+
import { OrchestratorAgent } from "@aigne/agent-library";
|
|
3
|
+
import { AIAgent, ChatModelOpenAI, ExecutionEngine, MCPAgent } from "@aigne/core-next";
|
|
4
|
+
|
|
5
|
+
const { OPENAI_API_KEY } = process.env;
|
|
6
|
+
assert(OPENAI_API_KEY, "Please set the OPENAI_API_KEY environment variable");
|
|
7
|
+
|
|
8
|
+
const model = new ChatModelOpenAI({
|
|
9
|
+
apiKey: OPENAI_API_KEY,
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
const puppeteer = await MCPAgent.from({
|
|
13
|
+
command: "npx",
|
|
14
|
+
args: ["-y", "@modelcontextprotocol/server-puppeteer"],
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
const finder = AIAgent.from({
|
|
18
|
+
name: "finder",
|
|
19
|
+
description: "Find the closest match to a user's request",
|
|
20
|
+
instructions: `You are an agent with access to the filesystem,
|
|
21
|
+
as well as the ability to fetch URLs. Your job is to identify
|
|
22
|
+
the closest match to a user's request, make the appropriate tool calls,
|
|
23
|
+
and return the URI and CONTENTS of the closest match.
|
|
24
|
+
|
|
25
|
+
Rules:
|
|
26
|
+
- use document.body.innerText to get the text content of a page
|
|
27
|
+
- if you want a url to some page, you should get all link and it's title of current(home) page,
|
|
28
|
+
then you can use the title to search the url of the page you want to visit.
|
|
29
|
+
`,
|
|
30
|
+
tools: [puppeteer],
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
const enhancedFinder = OrchestratorAgent.from({
|
|
34
|
+
name: "enhanced_finder",
|
|
35
|
+
description: "Enhanced finder with more tools",
|
|
36
|
+
tools: [finder],
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
const filesystem = await MCPAgent.from({
|
|
40
|
+
command: "npx",
|
|
41
|
+
args: ["-y", "@modelcontextprotocol/server-filesystem", import.meta.dir],
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
const writer = AIAgent.from({
|
|
45
|
+
name: "writer",
|
|
46
|
+
description: "Write to the filesystem",
|
|
47
|
+
instructions: `You are an agent that can write to the filesystem.
|
|
48
|
+
You are tasked with taking the user's input, addressing it, and
|
|
49
|
+
writing the result to disk in the appropriate location.`,
|
|
50
|
+
tools: [filesystem],
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
const proofreader = AIAgent.from({
|
|
54
|
+
name: "proofreader",
|
|
55
|
+
description: "Review the short story for grammar, spelling, and punctuation errors",
|
|
56
|
+
instructions: `Review the short story for grammar, spelling, and punctuation errors.
|
|
57
|
+
Identify any awkward phrasing or structural issues that could improve clarity.
|
|
58
|
+
Provide detailed feedback on corrections.`,
|
|
59
|
+
tools: [],
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
const fact_checker = AIAgent.from({
|
|
63
|
+
name: "fact_checker",
|
|
64
|
+
description: "Verify the factual consistency within the story",
|
|
65
|
+
instructions: `Verify the factual consistency within the story. Identify any contradictions,
|
|
66
|
+
logical inconsistencies, or inaccuracies in the plot, character actions, or setting.
|
|
67
|
+
Highlight potential issues with reasoning or coherence.`,
|
|
68
|
+
tools: [],
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
const style_enforcer = AIAgent.from({
|
|
72
|
+
name: "style_enforcer",
|
|
73
|
+
description: "Analyze the story for adherence to style guidelines",
|
|
74
|
+
instructions: `Analyze the story for adherence to style guidelines.
|
|
75
|
+
Evaluate the narrative flow, clarity of expression, and tone. Suggest improvements to
|
|
76
|
+
enhance storytelling, readability, and engagement.`,
|
|
77
|
+
tools: [],
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
const agent = OrchestratorAgent.from({
|
|
81
|
+
tools: [enhancedFinder, writer, proofreader, fact_checker, style_enforcer],
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
const engine = new ExecutionEngine({ model });
|
|
85
|
+
|
|
86
|
+
const result = await engine.run(
|
|
87
|
+
`\
|
|
88
|
+
Conduct an in-depth research on ArcBlock using only the official website\
|
|
89
|
+
(avoid search engines or third-party sources) and compile a detailed report saved as arcblock.md. \
|
|
90
|
+
The report should include comprehensive insights into the company's products \
|
|
91
|
+
(with detailed research findings and links), technical architecture, and future plans.`,
|
|
92
|
+
agent,
|
|
93
|
+
);
|
|
94
|
+
console.log(result);
|
|
95
|
+
// Output:
|
|
96
|
+
// {
|
|
97
|
+
// text: "Having completed the research and documentation tasks focused on ArcBlock, the final deliverable, a comprehensive report titled \"arcblock.md,\" has been created. ...",
|
|
98
|
+
// }
|