-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathinngest_alt.ts
53 lines (48 loc) · 1.46 KB
/
inngest_alt.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
/* eslint-disable @typescript-eslint/no-unused-vars */
import { defaultRoutingAgent } from "@inngest/agent-kit";
import { EventSchemas, Inngest } from "inngest";
import { z } from "zod";
import { codeWritingNetworkMiddleware } from "./mw";
export const inngest = new Inngest({
id: "agents",
schemas: new EventSchemas().fromZod({
"agent/run": {
data: z.object({
input: z.string(),
}),
},
}),
middleware: [codeWritingNetworkMiddleware({ model: "gpt-3.5-turbo" })],
});
export const fn = inngest.createFunction(
{ id: "agent" },
{ event: "agent/run" },
async ({
event,
ai: {
agents: { codeWritingAgent, executingAgent },
networks: { codeWritingNetwork },
},
}) => {
// 1. Single agents
//
// Run a single agent as a prompt without a network.
const { output, raw } = await codeWritingAgent.run(event.data.input);
// 2. Networks of agents
//
// This uses the defaut agentic router to determine which agent to handle first. You can
// optinoally specifiy the agent that should execute first, and provide your own logic for
// handling logic in between agent calls.
const result = await codeWritingNetwork.run(
event.data.input,
({ network }) => {
if (network.state.kv.has("files")) {
// Okay, we have some files. Did an agent run tests?
return executingAgent;
}
return defaultRoutingAgent;
},
);
return result;
},
);