@aigne/example-workflow-code-execution 1.7.0 → 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/README.md +5 -6
- package/index.test.ts +10 -4
- package/index.ts +10 -10
- package/package.json +6 -3
- package/usage.ts +5 -5
package/README.md
CHANGED
|
@@ -26,7 +26,6 @@ class sandbox processing
|
|
|
26
26
|
|
|
27
27
|
Workflow of a code-execution between user and coder using a sandbox:
|
|
28
28
|
|
|
29
|
-
|
|
30
29
|
```mermaid
|
|
31
30
|
sequenceDiagram
|
|
32
31
|
|
|
@@ -92,7 +91,7 @@ The following example demonstrates how to build a code-execution workflow:
|
|
|
92
91
|
|
|
93
92
|
```typescript
|
|
94
93
|
import assert from "node:assert";
|
|
95
|
-
import { AIAgent,
|
|
94
|
+
import { AIAgent, AIGNE, FunctionAgent } from "@aigne/core";
|
|
96
95
|
import { OpenAIChatModel } from "@aigne/core/models/openai-chat-model.js";
|
|
97
96
|
import { z } from "zod";
|
|
98
97
|
|
|
@@ -104,7 +103,7 @@ const model = new OpenAIChatModel({
|
|
|
104
103
|
});
|
|
105
104
|
|
|
106
105
|
const sandbox = FunctionAgent.from({
|
|
107
|
-
name: "
|
|
106
|
+
name: "evaluateJs",
|
|
108
107
|
description: "A js sandbox for running javascript code",
|
|
109
108
|
inputSchema: z.object({
|
|
110
109
|
code: z.string().describe("The code to run"),
|
|
@@ -123,12 +122,12 @@ const coder = AIAgent.from({
|
|
|
123
122
|
You are a proficient coder. You write code to solve problems.
|
|
124
123
|
Work with the sandbox to execute your code.
|
|
125
124
|
`,
|
|
126
|
-
|
|
125
|
+
skills: [sandbox],
|
|
127
126
|
});
|
|
128
127
|
|
|
129
|
-
const
|
|
128
|
+
const aigne = new AIGNE({ model });
|
|
130
129
|
|
|
131
|
-
const result = await
|
|
130
|
+
const result = await aigne.invoke(coder, "10! = ?");
|
|
132
131
|
console.log(result);
|
|
133
132
|
// Output:
|
|
134
133
|
// {
|
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-code-execution",
|
|
6
|
+
async () => {
|
|
7
|
+
const { code } = await runExampleTest();
|
|
8
|
+
expect(code).toBe(0);
|
|
9
|
+
},
|
|
10
|
+
{ timeout: 600000 },
|
|
11
|
+
);
|
package/index.ts
CHANGED
|
@@ -1,22 +1,22 @@
|
|
|
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, FunctionAgent } from "@aigne/core";
|
|
5
5
|
import { loadModel } from "@aigne/core/loader/index.js";
|
|
6
6
|
import { z } from "zod";
|
|
7
7
|
|
|
8
8
|
const model = await loadModel();
|
|
9
9
|
|
|
10
10
|
const sandbox = FunctionAgent.from({
|
|
11
|
-
name: "
|
|
12
|
-
description: "
|
|
11
|
+
name: "evaluateJs",
|
|
12
|
+
description: "Run JavaScript code in a sandboxed environment and return the result.",
|
|
13
13
|
inputSchema: z.object({
|
|
14
|
-
|
|
14
|
+
jsCode: z.string().describe("The code to run"),
|
|
15
15
|
}),
|
|
16
|
-
fn: async (input: {
|
|
17
|
-
const {
|
|
16
|
+
fn: async (input: { jsCode: string }) => {
|
|
17
|
+
const { jsCode } = input;
|
|
18
18
|
// biome-ignore lint/security/noGlobalEval: <explanation>
|
|
19
|
-
const result = eval(
|
|
19
|
+
const result = eval(jsCode);
|
|
20
20
|
return { result };
|
|
21
21
|
},
|
|
22
22
|
});
|
|
@@ -27,13 +27,13 @@ const coder = AIAgent.from({
|
|
|
27
27
|
You are a proficient coder. You write code to solve problems.
|
|
28
28
|
Work with the sandbox to execute your code.
|
|
29
29
|
`,
|
|
30
|
-
|
|
30
|
+
skills: [sandbox],
|
|
31
31
|
memory: true,
|
|
32
32
|
});
|
|
33
33
|
|
|
34
|
-
const
|
|
34
|
+
const aigne = new AIGNE({ model });
|
|
35
35
|
|
|
36
|
-
const user =
|
|
36
|
+
const user = aigne.invoke(coder);
|
|
37
37
|
|
|
38
38
|
await runChatLoopInTerminal(user, {
|
|
39
39
|
welcome:
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aigne/example-workflow-code-execution",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.9.0",
|
|
4
4
|
"description": "A demonstration of using AIGNE Framework to build a code-execution 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-code-execution",
|
|
@@ -18,8 +18,11 @@
|
|
|
18
18
|
"dependencies": {
|
|
19
19
|
"openai": "^4.94.0",
|
|
20
20
|
"zod": "^3.24.2",
|
|
21
|
-
"@aigne/
|
|
22
|
-
"@aigne/
|
|
21
|
+
"@aigne/cli": "^1.8.1",
|
|
22
|
+
"@aigne/core": "^1.13.0"
|
|
23
|
+
},
|
|
24
|
+
"devDependencies": {
|
|
25
|
+
"@aigne/test-utils": "^0.1.0"
|
|
23
26
|
},
|
|
24
27
|
"scripts": {
|
|
25
28
|
"start": "bun run index.ts",
|
package/usage.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import assert from "node:assert";
|
|
2
|
-
import { AIAgent,
|
|
2
|
+
import { AIAgent, AIGNE, FunctionAgent } from "@aigne/core";
|
|
3
3
|
import { OpenAIChatModel } from "@aigne/core/models/openai-chat-model.js";
|
|
4
4
|
import { z } from "zod";
|
|
5
5
|
|
|
@@ -11,7 +11,7 @@ const model = new OpenAIChatModel({
|
|
|
11
11
|
});
|
|
12
12
|
|
|
13
13
|
const sandbox = FunctionAgent.from({
|
|
14
|
-
name: "
|
|
14
|
+
name: "evaluateJs",
|
|
15
15
|
description: "A js sandbox for running javascript code",
|
|
16
16
|
inputSchema: z.object({
|
|
17
17
|
code: z.string().describe("The code to run"),
|
|
@@ -30,12 +30,12 @@ const coder = AIAgent.from({
|
|
|
30
30
|
You are a proficient coder. You write code to solve problems.
|
|
31
31
|
Work with the sandbox to execute your code.
|
|
32
32
|
`,
|
|
33
|
-
|
|
33
|
+
skills: [sandbox],
|
|
34
34
|
});
|
|
35
35
|
|
|
36
|
-
const
|
|
36
|
+
const aigne = new AIGNE({ model });
|
|
37
37
|
|
|
38
|
-
const result = await
|
|
38
|
+
const result = await aigne.invoke(coder, "10! = ?");
|
|
39
39
|
console.log(result);
|
|
40
40
|
// Output:
|
|
41
41
|
// {
|