Back to snippets
livekit_openai_voice_pipeline_agent_quickstart.py
pythonA minimal voice agent that uses OpenAI for LLM, TTS, and STT via
Agent Votes
1
0
100% positive
livekit_openai_voice_pipeline_agent_quickstart.py
1import asyncio
2
3from livekit.agents import JobContext, WorkerOptions, cli, voice_pipeline
4from livekit.plugins import openai
5
6
7async def entrypoint(ctx: JobContext):
8 initial_ctx = openai.llm.ChatContext().append(
9 role="system",
10 text="You are a funny, helpful assistant. Keep your responses concise and polite.",
11 )
12
13 await ctx.connect()
14
15 agent = voice_pipeline.VoicePipelineAgent(
16 vad=ctx.wait_for_participant().vad, # Using default VAD
17 stt=openai.STT(),
18 llm=openai.LLM(),
19 tts=openai.TTS(),
20 chat_ctx=initial_ctx,
21 )
22
23 agent.start(ctx.room)
24
25 # Listen for a participant to join and greet them
26 await agent.say("Hey, how can I help you today?", allow_interruptions=True)
27
28
29if __name__ == "__main__":
30 cli.run_app(WorkerOptions(entrypoint_fnc=entrypoint))