@aigne/example-workflow-handoff 1.7.0 → 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/README.md +6 -6
- package/index.test.ts +10 -4
- package/index.ts +7 -7
- package/package.json +6 -3
- package/usages.ts +6 -6
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
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
|
-
import { test } from "bun:test";
|
|
1
|
+
import { expect, test } from "bun:test";
|
|
2
|
+
import { runExampleTest } from "@aigne/test-utils/run-example-test.js";
|
|
2
3
|
|
|
3
|
-
test(
|
|
4
|
-
|
|
5
|
-
|
|
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,6 +1,6 @@
|
|
|
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",
|
|
@@ -18,8 +18,11 @@
|
|
|
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",
|
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
|
// {
|