Skip to content

Instantly share code, notes, and snippets.

@davidzhao
Created October 2, 2025 20:18
Show Gist options
  • Save davidzhao/61f43c479369b74e436033efed3db88f to your computer and use it in GitHub Desktop.
Save davidzhao/61f43c479369b74e436033efed3db88f to your computer and use it in GitHub Desktop.
import logging
from dotenv import load_dotenv
from livekit.agents import (
Agent,
AgentSession,
JobContext,
WorkerOptions,
cli,
)
from livekit.plugins import deepgram, silero
logger = logging.getLogger("flux-agent")
load_dotenv()
class MyAgent(Agent):
def __init__(self) -> None:
super().__init__(
instructions="Your name is Flux. You would interact with users via voice."
"with that in mind keep your responses concise and to the point."
"do not use emojis, asterisks, markdown, or other special characters in your responses."
"You are curious and friendly, and have a sense of humor."
"you will speak english to the user",
)
async def on_enter(self):
# when the agent is added to the session, it'll generate a reply
# according to its instructions
self.session.generate_reply(instructions="introduce yourself to the user")
async def entrypoint(ctx: JobContext):
# each log entry will include these fields
ctx.log_context_fields = {
"room": ctx.room.name,
}
session = AgentSession(
# a VAD for the best interruption handling
# Flux also has VAD builtin, so you can try disabling this
vad=silero.VAD.load(),
llm="openai/gpt-4.1",
stt=deepgram.STTv2(model="flux-general-en", eager_eot_threshold=0.4),
tts="cartesia/sonic-2",
# allow the LLM to generate a response while waiting for the end of turn
# this works with Flux's EagerEndOfTurn events to start LLM generation earlier
preemptive_generation=True,
# sometimes background noise could interrupt the agent session, these are considered false positive interruptions
# when it's detected, you may resume the agent's speech
resume_false_interruption=True,
)
await session.start(
agent=MyAgent(),
room=ctx.room,
)
if __name__ == "__main__":
cli.run_app(WorkerOptions(entrypoint_fnc=entrypoint))
@suhaima-ilyas
Copy link

whats the version of livekit that supports this

@lasryaric
Copy link

whats the version of livekit that supports this

+1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment