@aigne/example-workflow-handoff 1.6.2 → 1.8.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 +7 -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
|
@@ -92,7 +92,7 @@ The following example demonstrates how to build a handoff workflow:
|
|
|
92
92
|
|
|
93
93
|
```typescript
|
|
94
94
|
import assert from "node:assert";
|
|
95
|
-
import { AIAgent,
|
|
95
|
+
import { AIAgent, AIGNE } from "@aigne/core";
|
|
96
96
|
import { OpenAIChatModel } from "@aigne/core/models/openai-chat-model.js";
|
|
97
97
|
|
|
98
98
|
const { OPENAI_API_KEY } = process.env;
|
|
@@ -110,7 +110,7 @@ const agentA = AIAgent.from({
|
|
|
110
110
|
name: "AgentA",
|
|
111
111
|
instructions: "You are a helpful agent.",
|
|
112
112
|
outputKey: "A",
|
|
113
|
-
|
|
113
|
+
skills: [transfer_to_b],
|
|
114
114
|
});
|
|
115
115
|
|
|
116
116
|
const agentB = AIAgent.from({
|
|
@@ -119,18 +119,18 @@ const agentB = AIAgent.from({
|
|
|
119
119
|
outputKey: "B",
|
|
120
120
|
});
|
|
121
121
|
|
|
122
|
-
const
|
|
122
|
+
const aigne = new AIGNE({ model });
|
|
123
123
|
|
|
124
|
-
const userAgent =
|
|
124
|
+
const userAgent = aigne.invoke(agentA);
|
|
125
125
|
|
|
126
|
-
const result1 = await userAgent.
|
|
126
|
+
const result1 = await userAgent.invoke("transfer to agent b");
|
|
127
127
|
console.log(result1);
|
|
128
128
|
// Output:
|
|
129
129
|
// {
|
|
130
130
|
// B: "Transfer now complete, \nAgent B is here to help. \nWhat do you need, friend?",
|
|
131
131
|
// }
|
|
132
132
|
|
|
133
|
-
const result2 = await userAgent.
|
|
133
|
+
const result2 = await userAgent.invoke("It's a beautiful day");
|
|
134
134
|
console.log(result2);
|
|
135
135
|
// Output:
|
|
136
136
|
// {
|
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-handoff",
|
|
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, type Agent,
|
|
4
|
+
import { AIAgent, AIGNE, type Agent, FunctionAgent } from "@aigne/core";
|
|
5
5
|
import { loadModel } from "@aigne/core/loader/index.js";
|
|
6
6
|
import { z } from "zod";
|
|
7
7
|
|
|
@@ -97,7 +97,7 @@ Follow the following routine with the user:
|
|
|
97
97
|
4. Only after everything, and if the user says yes,
|
|
98
98
|
tell them a crazy caveat and execute their order.
|
|
99
99
|
`,
|
|
100
|
-
|
|
100
|
+
skills: [transfer_back_to_triage, execute_order_tool],
|
|
101
101
|
outputKey: "sales",
|
|
102
102
|
memory: true,
|
|
103
103
|
});
|
|
@@ -114,7 +114,7 @@ Follow the following routine with the user:
|
|
|
114
114
|
3. ONLY if not satisfied, offer a refund.
|
|
115
115
|
4. If accepted, search for the ID and then execute refund.
|
|
116
116
|
`,
|
|
117
|
-
|
|
117
|
+
skills: [transfer_back_to_triage, execute_refund_tool, look_up_item_tool],
|
|
118
118
|
outputKey: "issuesAndRepairs",
|
|
119
119
|
memory: true,
|
|
120
120
|
});
|
|
@@ -127,7 +127,7 @@ You are a human manager for ACME Inc.
|
|
|
127
127
|
Just chat with the user and help them with their problem.
|
|
128
128
|
Only transfer to another agent if user explicitly asks for it.
|
|
129
129
|
`,
|
|
130
|
-
|
|
130
|
+
skills: [transfer_back_to_triage, transfer_to_sales_agent, transfer_to_issues_and_repairs],
|
|
131
131
|
outputKey: "human",
|
|
132
132
|
memory: true,
|
|
133
133
|
});
|
|
@@ -140,14 +140,14 @@ Introduce yourself. Always be very brief.
|
|
|
140
140
|
Gather information to direct the customer to the right department.
|
|
141
141
|
But make your questions subtle and natural.
|
|
142
142
|
`,
|
|
143
|
-
|
|
143
|
+
skills: [transfer_to_issues_and_repairs, transfer_to_sales_agent, transfer_to_human_manager],
|
|
144
144
|
outputKey: "triage",
|
|
145
145
|
memory: true,
|
|
146
146
|
});
|
|
147
147
|
|
|
148
|
-
const
|
|
148
|
+
const aigne = new AIGNE({ model });
|
|
149
149
|
|
|
150
|
-
const userAgent =
|
|
150
|
+
const userAgent = aigne.invoke(triage);
|
|
151
151
|
|
|
152
152
|
await runChatLoopInTerminal(userAgent, {
|
|
153
153
|
welcome: `Hello, I'm a customer service bot for ACME Inc. How can I help you today?`,
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aigne/example-workflow-handoff",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.8.0",
|
|
4
4
|
"description": "A demonstration of using AIGNE Framework to build a handoff 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-handoff",
|
|
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;
|
|
@@ -17,7 +17,7 @@ const agentA = AIAgent.from({
|
|
|
17
17
|
name: "AgentA",
|
|
18
18
|
instructions: "You are a helpful agent.",
|
|
19
19
|
outputKey: "A",
|
|
20
|
-
|
|
20
|
+
skills: [transfer_to_b],
|
|
21
21
|
});
|
|
22
22
|
|
|
23
23
|
const agentB = AIAgent.from({
|
|
@@ -26,18 +26,18 @@ const agentB = AIAgent.from({
|
|
|
26
26
|
outputKey: "B",
|
|
27
27
|
});
|
|
28
28
|
|
|
29
|
-
const
|
|
29
|
+
const aigne = new AIGNE({ model });
|
|
30
30
|
|
|
31
|
-
const userAgent =
|
|
31
|
+
const userAgent = aigne.invoke(agentA);
|
|
32
32
|
|
|
33
|
-
const result1 = await userAgent.
|
|
33
|
+
const result1 = await userAgent.invoke("transfer to agent b");
|
|
34
34
|
console.log(result1);
|
|
35
35
|
// Output:
|
|
36
36
|
// {
|
|
37
37
|
// B: "Transfer now complete, \nAgent B is here to help. \nWhat do you need, friend?",
|
|
38
38
|
// }
|
|
39
39
|
|
|
40
|
-
const result2 = await userAgent.
|
|
40
|
+
const result2 = await userAgent.invoke("It's a beautiful day");
|
|
41
41
|
console.log(result2);
|
|
42
42
|
// Output:
|
|
43
43
|
// {
|