-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Expand file tree
/
Copy pathagent_worker.py
More file actions
65 lines (51 loc) · 1.7 KB
/
Copy pathagent_worker.py
File metadata and controls
65 lines (51 loc) · 1.7 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
61
62
63
64
65
"""
Minimal LiveKit agent with Keyframe avatar plugin.
"""
from dotenv import load_dotenv
from livekit.agents import (
Agent,
AgentSession,
JobContext,
RunContext,
WorkerOptions,
cli,
function_tool,
inference,
)
from livekit.plugins import keyframe
from livekit.plugins.keyframe import Emotion
load_dotenv()
class AvatarAgent(Agent):
def __init__(self, avatar: keyframe.AvatarSession) -> None:
super().__init__(
instructions=(
"You are a friendly voice assistant with an avatar. "
"Use the set_emotion tool to change your facial expression "
"whenever the conversation mood shifts."
),
)
self._avatar = avatar
@function_tool()
async def set_emotion(self, context: RunContext, emotion: Emotion) -> str:
"""Set the avatar's facial expression to match the conversation mood.
Args:
emotion: The emotion to express. One of 'neutral', 'happy', 'sad', or 'angry'.
"""
await self._avatar.set_emotion(emotion)
return f"Emotion set to {emotion}"
async def entrypoint(ctx: JobContext):
await ctx.connect()
session = AgentSession(
stt=inference.STT("deepgram/nova-3"),
llm=inference.LLM("google/gemini-2.5-flash"),
tts=inference.TTS("cartesia/sonic-3"),
resume_false_interruption=False,
)
avatar = keyframe.AvatarSession(persona_slug="public:cosmo_persona-1.5-live")
await avatar.start(session, room=ctx.room)
await session.start(
agent=AvatarAgent(avatar=avatar),
room=ctx.room,
)
if __name__ == "__main__":
cli.run_app(WorkerOptions(entrypoint_fnc=entrypoint))