Repository navigation
Expand file tree
/
Copy pathagent.py
More file actions
70 lines (51 loc) · 1.82 KB
/
Copy pathagent.py
File metadata and controls
70 lines (51 loc) · 1.82 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
66
67
68
69
70
import logging
from pathlib import Path
from dotenv import load_dotenv
from protocol import SessionRequest
from livekit.agents import (
Agent,
AgentServer,
AgentSession,
JobContext,
TurnHandlingOptions,
cli,
inference,
)
logger = logging.getLogger("expressive-agent")
load_dotenv()
AGENT_NAME = "expressive_agent"
INSTRUCTIONS = (Path(__file__).parent / "prompt.md").read_text()
GREETING = (
"Open the call the way you'd answer the phone to someone you know well. "
"Short and warm, and leave them room to say what's going on."
)
class Friend(Agent):
def __init__(self) -> None:
super().__init__(instructions=INSTRUCTIONS)
async def on_enter(self) -> None:
await self.session.generate_reply(instructions=GREETING)
server = AgentServer()
@server.rtc_session(agent_name=AGENT_NAME)
async def expressive_agent(ctx: JobContext) -> None:
ctx.log_context_fields = {"room": ctx.room.name}
config = SessionRequest.parse(ctx.job.metadata).resolve()
logger.info(
"starting session",
extra={"expressive": config.expressive, "voice": config.voice.label},
)
session = AgentSession(
stt=inference.STT("assemblyai/assemblyai-stt-3-7-realtime-agent", language="en"),
llm=inference.LLM("google/gemma-4-31b-it"),
tts=inference.TTS(config.voice.model, voice=config.voice.voice),
turn_handling=TurnHandlingOptions(
turn_detection=inference.TurnDetector(version="v1"),
interruption={"mode": "adaptive"},
preemptive_generation={"enabled": True},
),
expressive=config.expressive,
)
await session.start(agent=Friend(), room=ctx.room)
await ctx.connect()
await ctx.room.local_participant.set_attributes(config.attributes())
if __name__ == "__main__":
cli.run_app(server)