-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcompiled.ts
31 lines (27 loc) · 943 Bytes
/
compiled.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import fs from "fs/promises";
import Agent from "./agent"; // import agent
// {
// "task": "Fix the file main.js and write the fixed code to main_fixed.js"
// }
const fileContent = await fs.readFile("./main.js", "utf8");
const agent = new Agent({
// here you define the task for the sub-agent. It should be simpler than your main task.
// in this case, the sub-agent's task is simpler than the main because it only has to fix the code,
// without thinking about reading/writing files.
task: "Fix the given JavaScript code.",
input: {
code: fileContent,
},
// if you want the agent to return something, you must define an outputSchema!
outputSchema: {
type: "object",
properties: {
fixedCode: {
type: "string",
},
},
},
});
// fixedCode is defined in the schema above
const { fixedCode } = await agent.run(); // run takes no arguments
await fs.writeFile("./main_fixed.js", fixedCode);