@aigne/example-workflow-router 1.7.2 → 1.9.0
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/LICENSE +93 -0
- package/README.md +6 -6
- package/index.test.ts +11 -0
- package/index.ts +4 -7
- package/package.json +9 -5
- package/usages.ts +6 -6
package/LICENSE
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
Elastic License 2.0
|
|
2
|
+
|
|
3
|
+
URL: https://www.elastic.co/licensing/elastic-license
|
|
4
|
+
|
|
5
|
+
## Acceptance
|
|
6
|
+
|
|
7
|
+
By using the software, you agree to all of the terms and conditions below.
|
|
8
|
+
|
|
9
|
+
## Copyright License
|
|
10
|
+
|
|
11
|
+
The licensor grants you a non-exclusive, royalty-free, worldwide,
|
|
12
|
+
non-sublicensable, non-transferable license to use, copy, distribute, make
|
|
13
|
+
available, and prepare derivative works of the software, in each case subject to
|
|
14
|
+
the limitations and conditions below.
|
|
15
|
+
|
|
16
|
+
## Limitations
|
|
17
|
+
|
|
18
|
+
You may not provide the software to third parties as a hosted or managed
|
|
19
|
+
service, where the service provides users with access to any substantial set of
|
|
20
|
+
the features or functionality of the software.
|
|
21
|
+
|
|
22
|
+
You may not move, change, disable, or circumvent the license key functionality
|
|
23
|
+
in the software, and you may not remove or obscure any functionality in the
|
|
24
|
+
software that is protected by the license key.
|
|
25
|
+
|
|
26
|
+
You may not alter, remove, or obscure any licensing, copyright, or other notices
|
|
27
|
+
of the licensor in the software. Any use of the licensor’s trademarks is subject
|
|
28
|
+
to applicable law.
|
|
29
|
+
|
|
30
|
+
## Patents
|
|
31
|
+
|
|
32
|
+
The licensor grants you a license, under any patent claims the licensor can
|
|
33
|
+
license, or becomes able to license, to make, have made, use, sell, offer for
|
|
34
|
+
sale, import and have imported the software, in each case subject to the
|
|
35
|
+
limitations and conditions in this license. This license does not cover any
|
|
36
|
+
patent claims that you cause to be infringed by modifications or additions to
|
|
37
|
+
the software. If you or your company make any written claim that the software
|
|
38
|
+
infringes or contributes to infringement of any patent, your patent license for
|
|
39
|
+
the software granted under these terms ends immediately. If your company makes
|
|
40
|
+
such a claim, your patent license ends immediately for work on behalf of your
|
|
41
|
+
company.
|
|
42
|
+
|
|
43
|
+
## Notices
|
|
44
|
+
|
|
45
|
+
You must ensure that anyone who gets a copy of any part of the software from you
|
|
46
|
+
also gets a copy of these terms.
|
|
47
|
+
|
|
48
|
+
If you modify the software, you must include in any modified copies of the
|
|
49
|
+
software prominent notices stating that you have modified the software.
|
|
50
|
+
|
|
51
|
+
## No Other Rights
|
|
52
|
+
|
|
53
|
+
These terms do not imply any licenses other than those expressly granted in
|
|
54
|
+
these terms.
|
|
55
|
+
|
|
56
|
+
## Termination
|
|
57
|
+
|
|
58
|
+
If you use the software in violation of these terms, such use is not licensed,
|
|
59
|
+
and your licenses will automatically terminate. If the licensor provides you
|
|
60
|
+
with a notice of your violation, and you cease all violation of this license no
|
|
61
|
+
later than 30 days after you receive that notice, your licenses will be
|
|
62
|
+
reinstated retroactively. However, if you violate these terms after such
|
|
63
|
+
reinstatement, any additional violation of these terms will cause your licenses
|
|
64
|
+
to terminate automatically and permanently.
|
|
65
|
+
|
|
66
|
+
## No Liability
|
|
67
|
+
|
|
68
|
+
*As far as the law allows, the software comes as is, without any warranty or
|
|
69
|
+
condition, and the licensor will not be liable to you for any damages arising
|
|
70
|
+
out of these terms or the use or nature of the software, under any kind of
|
|
71
|
+
legal claim.*
|
|
72
|
+
|
|
73
|
+
## Definitions
|
|
74
|
+
|
|
75
|
+
The **licensor** is the entity offering these terms, and the **software** is the
|
|
76
|
+
software the licensor makes available under these terms, including any portion
|
|
77
|
+
of it.
|
|
78
|
+
|
|
79
|
+
**you** refers to the individual or entity agreeing to these terms.
|
|
80
|
+
|
|
81
|
+
**your company** is any legal entity, sole proprietorship, or other kind of
|
|
82
|
+
organization that you work for, plus all organizations that have control over,
|
|
83
|
+
are under the control of, or are under common control with that
|
|
84
|
+
organization. **control** means ownership of substantially all the assets of an
|
|
85
|
+
entity, or the power to direct its management and policies by vote, contract, or
|
|
86
|
+
otherwise. Control can be direct or indirect.
|
|
87
|
+
|
|
88
|
+
**your licenses** are all the licenses granted to you for the software under
|
|
89
|
+
these terms.
|
|
90
|
+
|
|
91
|
+
**use** means anything you do with the software requiring one of your licenses.
|
|
92
|
+
|
|
93
|
+
**trademark** means trademarks, service marks, and similar rights.
|
package/README.md
CHANGED
|
@@ -79,7 +79,7 @@ The following example demonstrates how to build a router workflow:
|
|
|
79
79
|
|
|
80
80
|
```typescript
|
|
81
81
|
import assert from "node:assert";
|
|
82
|
-
import { AIAgent,
|
|
82
|
+
import { AIAgent, AIGNE } from "@aigne/core";
|
|
83
83
|
import { OpenAIChatModel } from "@aigne/core/models/openai-chat-model.js";
|
|
84
84
|
|
|
85
85
|
const { OPENAI_API_KEY } = process.env;
|
|
@@ -121,25 +121,25 @@ const triage = AIAgent.from({
|
|
|
121
121
|
instructions: `You are an agent capable of routing questions to the appropriate agent.
|
|
122
122
|
Your goal is to understand the user's query and direct them to the agent best suited to assist them.
|
|
123
123
|
Be efficient, clear, and ensure the user is connected to the right resource quickly.`,
|
|
124
|
-
|
|
124
|
+
skills: [productSupport, feedback, other],
|
|
125
125
|
toolChoice: "router", // Set toolChoice to "router" to enable router mode
|
|
126
126
|
});
|
|
127
127
|
|
|
128
|
-
const
|
|
128
|
+
const aigne = new AIGNE({ model });
|
|
129
129
|
|
|
130
|
-
const result1 = await
|
|
130
|
+
const result1 = await aigne.invoke(triage, "How to use this product?");
|
|
131
131
|
console.log(result1);
|
|
132
132
|
// {
|
|
133
133
|
// product_support: "I’d be happy to help you with that! However, I need to know which specific product you’re referring to. Could you please provide me with the name or type of product you have in mind?",
|
|
134
134
|
// }
|
|
135
135
|
|
|
136
|
-
const result2 = await
|
|
136
|
+
const result2 = await aigne.invoke(triage, "I have feedback about the app.");
|
|
137
137
|
console.log(result2);
|
|
138
138
|
// {
|
|
139
139
|
// feedback: "Thank you for sharing your feedback! I'm here to listen. Please go ahead and let me know what you’d like to share about the app.",
|
|
140
140
|
// }
|
|
141
141
|
|
|
142
|
-
const result3 = await
|
|
142
|
+
const result3 = await aigne.invoke(triage, "What is the weather today?");
|
|
143
143
|
console.log(result3);
|
|
144
144
|
// {
|
|
145
145
|
// other: "I can't provide real-time weather updates. However, you can check a reliable weather website or a weather app on your phone for the current conditions in your area. If you tell me your location, I can suggest a few sources where you can find accurate weather information!",
|
package/index.test.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { expect, test } from "bun:test";
|
|
2
|
+
import { runExampleTest } from "@aigne/test-utils/run-example-test.js";
|
|
3
|
+
|
|
4
|
+
test(
|
|
5
|
+
"should successfully run the workflow-router",
|
|
6
|
+
async () => {
|
|
7
|
+
const { code } = await runExampleTest();
|
|
8
|
+
expect(code).toBe(0);
|
|
9
|
+
},
|
|
10
|
+
{ timeout: 600000 },
|
|
11
|
+
);
|
package/index.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env bunwrapper
|
|
2
2
|
|
|
3
3
|
import { runChatLoopInTerminal } from "@aigne/cli/utils/run-chat-loop.js";
|
|
4
|
-
import { AIAgent,
|
|
4
|
+
import { AIAgent, AIGNE } from "@aigne/core";
|
|
5
5
|
import { loadModel } from "@aigne/core/loader/index.js";
|
|
6
6
|
|
|
7
7
|
const model = await loadModel();
|
|
@@ -12,7 +12,6 @@ const productSupport = AIAgent.from({
|
|
|
12
12
|
instructions: `You are an agent capable of handling any product-related questions.
|
|
13
13
|
Your goal is to provide accurate and helpful information about the product.
|
|
14
14
|
Be polite, professional, and ensure the user feels supported.`,
|
|
15
|
-
outputKey: "product_support",
|
|
16
15
|
memory: true,
|
|
17
16
|
});
|
|
18
17
|
|
|
@@ -22,7 +21,6 @@ const feedback = AIAgent.from({
|
|
|
22
21
|
instructions: `You are an agent capable of handling any feedback-related questions.
|
|
23
22
|
Your goal is to listen to the user's feedback, acknowledge their input, and provide appropriate responses.
|
|
24
23
|
Be empathetic, understanding, and ensure the user feels heard.`,
|
|
25
|
-
outputKey: "feedback",
|
|
26
24
|
memory: true,
|
|
27
25
|
});
|
|
28
26
|
|
|
@@ -32,7 +30,6 @@ const other = AIAgent.from({
|
|
|
32
30
|
instructions: `You are an agent capable of handling any general questions.
|
|
33
31
|
Your goal is to provide accurate and helpful information on a wide range of topics.
|
|
34
32
|
Be friendly, knowledgeable, and ensure the user feels satisfied with the information provided.`,
|
|
35
|
-
outputKey: "other",
|
|
36
33
|
memory: true,
|
|
37
34
|
});
|
|
38
35
|
|
|
@@ -41,13 +38,13 @@ const triage = AIAgent.from({
|
|
|
41
38
|
instructions: `You are an agent capable of routing questions to the appropriate agent.
|
|
42
39
|
Your goal is to understand the user's query and direct them to the agent best suited to assist them.
|
|
43
40
|
Be efficient, clear, and ensure the user is connected to the right resource quickly.`,
|
|
44
|
-
|
|
41
|
+
skills: [productSupport, feedback, other],
|
|
45
42
|
toolChoice: "router",
|
|
46
43
|
});
|
|
47
44
|
|
|
48
|
-
const
|
|
45
|
+
const aigne = new AIGNE({ model });
|
|
49
46
|
|
|
50
|
-
const userAgent =
|
|
47
|
+
const userAgent = aigne.invoke(triage);
|
|
51
48
|
|
|
52
49
|
await runChatLoopInTerminal(userAgent, {
|
|
53
50
|
welcome: `Welcome to the support chat!
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aigne/example-workflow-router",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.9.0",
|
|
4
4
|
"description": "A demonstration of using AIGNE Framework to build a router 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-router",
|
|
7
|
-
"license": "
|
|
7
|
+
"license": "MIT",
|
|
8
8
|
"repository": {
|
|
9
9
|
"type": "git",
|
|
10
10
|
"url": "git+https://github.com/AIGNE-io/aigne-framework"
|
|
@@ -18,11 +18,15 @@
|
|
|
18
18
|
"dependencies": {
|
|
19
19
|
"openai": "^4.94.0",
|
|
20
20
|
"zod": "^3.24.2",
|
|
21
|
-
"@aigne/cli": "^1.
|
|
22
|
-
"@aigne/core": "^1.
|
|
21
|
+
"@aigne/cli": "^1.8.0",
|
|
22
|
+
"@aigne/core": "^1.12.0"
|
|
23
|
+
},
|
|
24
|
+
"devDependencies": {
|
|
25
|
+
"@aigne/test-utils": "^0.1.0"
|
|
23
26
|
},
|
|
24
27
|
"scripts": {
|
|
25
28
|
"start": "bun run index.ts",
|
|
26
|
-
"lint": "tsc --noEmit"
|
|
29
|
+
"lint": "tsc --noEmit",
|
|
30
|
+
"test:llm": "bun test"
|
|
27
31
|
}
|
|
28
32
|
}
|
package/usages.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import assert from "node:assert";
|
|
2
|
-
import { AIAgent,
|
|
2
|
+
import { AIAgent, AIGNE } from "@aigne/core";
|
|
3
3
|
import { OpenAIChatModel } from "@aigne/core/models/openai-chat-model.js";
|
|
4
4
|
|
|
5
5
|
const { OPENAI_API_KEY } = process.env;
|
|
@@ -41,25 +41,25 @@ const triage = AIAgent.from({
|
|
|
41
41
|
instructions: `You are an agent capable of routing questions to the appropriate agent.
|
|
42
42
|
Your goal is to understand the user's query and direct them to the agent best suited to assist them.
|
|
43
43
|
Be efficient, clear, and ensure the user is connected to the right resource quickly.`,
|
|
44
|
-
|
|
44
|
+
skills: [productSupport, feedback, other],
|
|
45
45
|
toolChoice: "router", // Set toolChoice to "router" to enable router mode
|
|
46
46
|
});
|
|
47
47
|
|
|
48
|
-
const
|
|
48
|
+
const aigne = new AIGNE({ model });
|
|
49
49
|
|
|
50
|
-
const result1 = await
|
|
50
|
+
const result1 = await aigne.invoke(triage, "How to use this product?");
|
|
51
51
|
console.log(result1);
|
|
52
52
|
// {
|
|
53
53
|
// product_support: "I’d be happy to help you with that! However, I need to know which specific product you’re referring to. Could you please provide me with the name or type of product you have in mind?",
|
|
54
54
|
// }
|
|
55
55
|
|
|
56
|
-
const result2 = await
|
|
56
|
+
const result2 = await aigne.invoke(triage, "I have feedback about the app.");
|
|
57
57
|
console.log(result2);
|
|
58
58
|
// {
|
|
59
59
|
// feedback: "Thank you for sharing your feedback! I'm here to listen. Please go ahead and let me know what you’d like to share about the app.",
|
|
60
60
|
// }
|
|
61
61
|
|
|
62
|
-
const result3 = await
|
|
62
|
+
const result3 = await aigne.invoke(triage, "What is the weather today?");
|
|
63
63
|
console.log(result3);
|
|
64
64
|
// {
|
|
65
65
|
// other: "I can't provide real-time weather updates. However, you can check a reliable weather website or a weather app on your phone for the current conditions in your area. If you tell me your location, I can suggest a few sources where you can find accurate weather information!",
|