Repository navigation
Expand file tree
/
Copy pathagent.py
More file actions
55 lines (43 loc) · 1.45 KB
/
Copy pathagent.py
File metadata and controls
55 lines (43 loc) · 1.45 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
from dotenv import load_dotenv
from livekit import agents
from livekit.agents import AgentSession, Agent, RoomInputOptions
from livekit.plugins import (
noise_cancellation,
)
from livekit.plugins import google
from prompts import AGENT_INSTRUCTION, SESSION_INSTRUCTION
from tools import get_weather, search_web, send_email
load_dotenv()
class Assistant(Agent):
def __init__(self) -> None:
super().__init__(
instructions=AGENT_INSTRUCTION, # baseline persona
llm=google.beta.realtime.RealtimeModel(
voice="Fenrir",
temperature=0.8,
),
# tools=[get_weather, search_web, send_email],
)
async def entrypoint(ctx: agents.JobContext):
session = AgentSession()
await session.start(
room=ctx.room,
agent=Assistant(),
room_input_options=RoomInputOptions(
video_enabled=False,
noise_cancellation=noise_cancellation.BVC(),
),
)
await ctx.connect()
# 🔥 Kick off with the introduction + interview flow
await session.generate_reply(
instructions=SESSION_INSTRUCTION,
)
# ✅ Handle user messages
async for event in session.stream():
if event.type == "message_received":
await session.generate_reply(
instructions=SESSION_INSTRUCTION,
)
if __name__ == "__main__":
agents.cli.run_app(agents.WorkerOptions(entrypoint_fnc=entrypoint))