@aigne/example-workflow-router 1.2.0 → 1.3.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 CHANGED
@@ -76,14 +76,17 @@ pnpm start
76
76
  The following example demonstrates how to build a router workflow:
77
77
 
78
78
  ```typescript
79
- import { AIAgent, ChatModelOpenAI, ExecutionEngine } from "@aigne/core-next";
79
+ import assert from "node:assert";
80
+ import { AIAgent, OpenAIChatModel, ExecutionEngine } from "@aigne/core";
80
81
 
81
- const model = new ChatModelOpenAI({
82
- apiKey: process.env.OPENAI_API_KEY,
82
+ const { OPENAI_API_KEY } = process.env;
83
+ assert(OPENAI_API_KEY, "Please set the OPENAI_API_KEY environment variable");
84
+
85
+ const model = new OpenAIChatModel({
86
+ apiKey: OPENAI_API_KEY,
83
87
  });
84
88
 
85
89
  const productSupport = AIAgent.from({
86
- enableHistory: true,
87
90
  name: "product_support",
88
91
  description: "Agent to assist with any product-related questions.",
89
92
  instructions: `You are an agent capable of handling any product-related questions.
@@ -93,7 +96,6 @@ const productSupport = AIAgent.from({
93
96
  });
94
97
 
95
98
  const feedback = AIAgent.from({
96
- enableHistory: true,
97
99
  name: "feedback",
98
100
  description: "Agent to assist with any feedback-related questions.",
99
101
  instructions: `You are an agent capable of handling any feedback-related questions.
@@ -103,7 +105,6 @@ const feedback = AIAgent.from({
103
105
  });
104
106
 
105
107
  const other = AIAgent.from({
106
- enableHistory: true,
107
108
  name: "other",
108
109
  description: "Agent to assist with any general questions.",
109
110
  instructions: `You are an agent capable of handling any general questions.
@@ -123,19 +124,19 @@ const triage = AIAgent.from({
123
124
 
124
125
  const engine = new ExecutionEngine({ model });
125
126
 
126
- const result1 = await engine.run("How to use this product?", triage);
127
+ const result1 = await engine.call(triage, "How to use this product?");
127
128
  console.log(result1);
128
129
  // {
129
130
  // 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?",
130
131
  // }
131
132
 
132
- const result2 = await engine.run("I have feedback about the app.", triage);
133
+ const result2 = await engine.call(triage, "I have feedback about the app.");
133
134
  console.log(result2);
134
135
  // {
135
136
  // 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.",
136
137
  // }
137
138
 
138
- const result3 = await engine.run("What is the weather today?", triage);
139
+ const result3 = await engine.call(triage, "What is the weather today?");
139
140
  console.log(result3);
140
141
  // {
141
142
  // 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.ts CHANGED
@@ -1,43 +1,43 @@
1
1
  #!/usr/bin/env npx -y bun
2
2
 
3
3
  import assert from "node:assert";
4
- import { AIAgent, ChatModelOpenAI, ExecutionEngine, runChatLoopInTerminal } from "@aigne/core-next";
4
+ import { AIAgent, ExecutionEngine, OpenAIChatModel, runChatLoopInTerminal } from "@aigne/core";
5
5
 
6
6
  const { OPENAI_API_KEY } = process.env;
7
7
  assert(OPENAI_API_KEY, "Please set the OPENAI_API_KEY environment variable");
8
8
 
9
- const model = new ChatModelOpenAI({
9
+ const model = new OpenAIChatModel({
10
10
  apiKey: OPENAI_API_KEY,
11
11
  });
12
12
 
13
13
  const productSupport = AIAgent.from({
14
- enableHistory: true,
15
14
  name: "product_support",
16
15
  description: "Agent to assist with any product-related questions.",
17
16
  instructions: `You are an agent capable of handling any product-related questions.
18
17
  Your goal is to provide accurate and helpful information about the product.
19
18
  Be polite, professional, and ensure the user feels supported.`,
20
19
  outputKey: "product_support",
20
+ memory: true,
21
21
  });
22
22
 
23
23
  const feedback = AIAgent.from({
24
- enableHistory: true,
25
24
  name: "feedback",
26
25
  description: "Agent to assist with any feedback-related questions.",
27
26
  instructions: `You are an agent capable of handling any feedback-related questions.
28
27
  Your goal is to listen to the user's feedback, acknowledge their input, and provide appropriate responses.
29
28
  Be empathetic, understanding, and ensure the user feels heard.`,
30
29
  outputKey: "feedback",
30
+ memory: true,
31
31
  });
32
32
 
33
33
  const other = AIAgent.from({
34
- enableHistory: true,
35
34
  name: "other",
36
35
  description: "Agent to assist with any general questions.",
37
36
  instructions: `You are an agent capable of handling any general questions.
38
37
  Your goal is to provide accurate and helpful information on a wide range of topics.
39
38
  Be friendly, knowledgeable, and ensure the user feels satisfied with the information provided.`,
40
39
  outputKey: "other",
40
+ memory: true,
41
41
  });
42
42
 
43
43
  const triage = AIAgent.from({
@@ -51,7 +51,7 @@ const triage = AIAgent.from({
51
51
 
52
52
  const engine = new ExecutionEngine({ model });
53
53
 
54
- const userAgent = await engine.run(triage);
54
+ const userAgent = engine.call(triage);
55
55
 
56
56
  await runChatLoopInTerminal(userAgent, {
57
57
  welcome: `Welcome to the support chat!
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aigne/example-workflow-router",
3
- "version": "1.2.0",
3
+ "version": "1.3.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",
@@ -16,10 +16,12 @@
16
16
  "README.md"
17
17
  ],
18
18
  "dependencies": {
19
+ "openai": "^4.89.0",
19
20
  "zod": "^3.24.2",
20
- "@aigne/core-next": "^1.2.0"
21
+ "@aigne/core": "^1.3.0"
21
22
  },
22
23
  "scripts": {
23
- "start": "npx -y bun run index.ts"
24
+ "start": "npx -y bun run index.ts",
25
+ "lint": "tsc --noEmit"
24
26
  }
25
27
  }
package/usages.ts CHANGED
@@ -1,15 +1,14 @@
1
1
  import assert from "node:assert";
2
- import { AIAgent, ChatModelOpenAI, ExecutionEngine } from "@aigne/core-next";
2
+ import { AIAgent, ExecutionEngine, OpenAIChatModel } from "@aigne/core";
3
3
 
4
4
  const { OPENAI_API_KEY } = process.env;
5
5
  assert(OPENAI_API_KEY, "Please set the OPENAI_API_KEY environment variable");
6
6
 
7
- const model = new ChatModelOpenAI({
7
+ const model = new OpenAIChatModel({
8
8
  apiKey: OPENAI_API_KEY,
9
9
  });
10
10
 
11
11
  const productSupport = AIAgent.from({
12
- enableHistory: true,
13
12
  name: "product_support",
14
13
  description: "Agent to assist with any product-related questions.",
15
14
  instructions: `You are an agent capable of handling any product-related questions.
@@ -19,7 +18,6 @@ const productSupport = AIAgent.from({
19
18
  });
20
19
 
21
20
  const feedback = AIAgent.from({
22
- enableHistory: true,
23
21
  name: "feedback",
24
22
  description: "Agent to assist with any feedback-related questions.",
25
23
  instructions: `You are an agent capable of handling any feedback-related questions.
@@ -29,7 +27,6 @@ const feedback = AIAgent.from({
29
27
  });
30
28
 
31
29
  const other = AIAgent.from({
32
- enableHistory: true,
33
30
  name: "other",
34
31
  description: "Agent to assist with any general questions.",
35
32
  instructions: `You are an agent capable of handling any general questions.
@@ -49,19 +46,19 @@ const triage = AIAgent.from({
49
46
 
50
47
  const engine = new ExecutionEngine({ model });
51
48
 
52
- const result1 = await engine.run("How to use this product?", triage);
49
+ const result1 = await engine.call(triage, "How to use this product?");
53
50
  console.log(result1);
54
51
  // {
55
52
  // 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?",
56
53
  // }
57
54
 
58
- const result2 = await engine.run("I have feedback about the app.", triage);
55
+ const result2 = await engine.call(triage, "I have feedback about the app.");
59
56
  console.log(result2);
60
57
  // {
61
58
  // 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.",
62
59
  // }
63
60
 
64
- const result3 = await engine.run("What is the weather today?", triage);
61
+ const result3 = await engine.call(triage, "What is the weather today?");
65
62
  console.log(result3);
66
63
  // {
67
64
  // 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!",