-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmw.ts
94 lines (77 loc) · 2.75 KB
/
mw.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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
import { createAgent, createNetwork } from "@inngest/agent-kit";
import { InngestMiddleware, openai, type OpenAi } from "inngest";
export const codeWritingNetworkMiddleware = (
defaultModelOptions: OpenAi.AiModelOptions,
) => {
return new InngestMiddleware({
name: "Code Writing Agent Middleware",
init() {
const model = openai({ ...defaultModelOptions });
return {
onFunctionRun() {
return {
transformInput() {
const codeWritingNetwork = createNetwork({
agents: [codeWritingAgent, executingAgent],
maxIter: 4,
defaultModel: model,
});
return {
ctx: {
ai: {
agents: {
codeWritingAgent,
executingAgent,
},
networks: {
codeWritingNetwork,
},
},
},
};
},
};
},
};
},
});
};
const codeWritingAgent = createAgent({
name: "Code writing agent",
description: "Writes TypeScript code and tests based off of a given input.",
lifecycle: {
onResponse: ({ result }) => {
// Does this contain a solution?
// TODO: Parse filenames out of content.
return result;
},
},
system: `You are an expert TypeScript engineer who excels at test-driven-development. Your primary focus is to take system requirements and write unit tests for a set of functions.
Think carefully about the request that the user is asking for. Do not respond with anything else other than the following XML tags:
- If you would like to write code, add all code within the following tags (replace $filename and $contents appropriately):
<file name="$filename.ts">
$contents
</file>
`,
});
const executingAgent = createAgent({
name: "Test execution agent",
description: "Executes written TypeScript tests",
lifecycle: {
enabled: ({ network }) => {
// Only allow executing of tests if there are files available.
return network?.state.kv.get("files") !== undefined;
},
},
system: `You are an export TypeScript engineer that can execute commands, run tests, debug the output, and make modifications to code.
Think carefully about the request that the user is asking for. Do not respond with anything else other than the following XML tags:
- If you would like to write code, add all code within the following tags (replace $filename and $contents appropriately):
<file name="$filename.ts">
$contents
</file>
- If you would like to run commands, respond with the following tags:
<command>
$command
</command>
`,
});