-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathagent.js
More file actions
60 lines (54 loc) · 1.57 KB
/
agent.js
File metadata and controls
60 lines (54 loc) · 1.57 KB
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
import {
AutoSubscribe,
WorkerOptions,
cli,
defineAgent,
llm,
pipeline,
} from "@livekit/agents";
import * as deepgram from "@livekit/agents-plugin-deepgram";
import * as livekit from "@livekit/agents-plugin-livekit";
import * as openai from "@livekit/agents-plugin-openai";
import * as silero from "@livekit/agents-plugin-silero";
import { fileURLToPath } from "url";
import {
model,
salonSystemPrompt,
startMessage,
} from "./src/Agent/constants.js";
import tools from "./src/Agent/tools.js";
import dotenv from "dotenv";
dotenv.config();
export const agentDefinition = {
prewarm: async (proc) => {
proc.userData.vad = await silero.VAD.load();
},
entry: async (ctx) => {
const vad = ctx.proc.userData.vad;
const initialContext = new llm.ChatContext().append({
role: llm.ChatRole.SYSTEM,
text: salonSystemPrompt,
});
await ctx.connect(undefined, AutoSubscribe.AUDIO_ONLY);
console.log("waiting for participant");
const participant = await ctx.waitForParticipant();
console.log(`starting agent for ${participant.identity}`);
const agent = new pipeline.VoicePipelineAgent(
vad,
new deepgram.STT(),
new openai.LLM({
model: model,
}),
new openai.TTS(),
{
chatCtx: initialContext,
fncCtx: tools,
turnDetector: new livekit.turnDetector.EOUModel(),
}
);
agent.start(ctx.room, participant);
await agent.say(startMessage, true);
},
};
export default defineAgent(agentDefinition);
cli.runApp(new WorkerOptions({ agent: fileURLToPath(import.meta.url) }));