I am using something like this, from dotenv import...
# ask-ai
t
I am using something like this, from dotenv import load_dotenv from livekit import agents from livekit.agents import AgentSession, Agent, RoomInputOptions from livekit.plugins import noise_cancellation, silero from livekit.plugins.turn_detector.multilingual import MultilingualModel load_dotenv(".env") class Assistant(Agent): def __init__(self) -> None: super().__init__( instructions="""You are a helpful voice AI assistant. You eagerly assist users with their questions by providing information from your extensive knowledge. Your responses are concise, to the point, and without any complex formatting or punctuation including emojis, asterisks, or other symbols. You are curious, friendly, and have a sense of humor.""", ) async def entrypoint(ctx: agents.JobContext): session = AgentSession( stt="assemblyai/universal-streaming:en", llm="openai/gpt-5-nano", tts="cartesia/sonic-3:a167e0f3-df7e-4d52-a9c3-f949145efdab", vad=silero.VAD.load(), turn_detection=MultilingualModel(), ) await session.start( room=ctx.room, agent=Assistant(), room_input_options=RoomInputOptions( noise_cancellation=noise_cancellation.BVC(), ), ) await session.generate_reply( instructions="Greet the user and offer your assistance." ) if name == "__main__": agents.cli.run_app(agents.WorkerOptions(entrypoint_fnc=entrypoint)) how do i set a system prompt in this case
t
Thanks for reaching out, Aritra. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
I'd be happy to help you set a system prompt! You have a couple of great options to choose from: Method 1: Define Instructions in the Agent Class In your custom
Assistant
class, you can simply pass the system prompt through the
instructions
argument inside the
super().__init__()
call, like this:
Copy code
class Assistant(Agent):
    def __init__(self) -> None:
        super().__init__(
            instructions="You are a helpful voice AI assistant. You respond clearly and concisely."
        )
This way, the system prompt is set directly to guide your agent’s behavior. Method 2: Pass a Custom Chat Context Alternatively, you can create a custom
ChatContext
and provide it when starting your session. This gives you more flexibility over the initial messages, like so:
Copy code
from livekit.agents import llm

initial_ctx = llm.ChatContext().append(
    role="system",
    text="You are a helpful voice AI assistant."
)

await session.start(
    room=ctx.room,
    agent=Assistant(),
    chat_ctx=initial_ctx
)
Both approaches work well! The first is straightforward and quick to set up, while the second offers more dynamic control during runtime. If you have any questions or want to explore these options further, just let me know—I’m here to help! Sources: Voice AI quickstart | LiveKit docs | Workflows | LiveKit docs | External data and RAG | LiveKit Docs
t
super().__init__( instructions="""You are a helpful voice AI assistant. You eagerly assist users with their questions by providing information from your extensive knowledge. Your responses are concise, to the point, and without any complex formatting or punctuation including emojis, asterisks, or other symbols. You are curious, friendly, and have a sense of humor.""", ) does the same instruction is passed to llm as well ?
t
Absolutely! The
instructions
parameter in the
Agent
class is automatically passed along to the LLM. Think of these instructions as helpful guidance that gets included in the chat context sent to the LLM during inference, shaping how the model responds. These instructions are kept within the agent's context and are dynamically added to the system-level messages for the LLM. This way, the behavior you've set in the instructions stays consistent throughout your entire session, making sure everything runs smoothly. Sources: livekit-agents/livekit/agents/voice/generation.py | examples/src/basic_tool_call_agent.ts | Agent Session Management & Turn Detection | livekit/livekit_composite | Dee...
t
const handle = session.generateReply({ instructions: "Greet the user and offer your assistance.", }); what this part does
t
I'm happy to help explain how the
session.generateReply
method works with the
instructions
parameter! Essentially, it allows the AI agent to create a verbal response based on the guidance you provide. For example, when you use the instruction "Greet the user and offer your assistance," the agent will respond by warmly greeting the user and offering help. Once the response is generated, it’s added to the chat history and turned into speech so the user can hear it. The
generateReply
method gives you a
SpeechHandle
object, which is super handy because it lets you manage the speech playback—like waiting for it to finish or handling any interruptions. This method is a great tool for steering the agent’s behavior dynamically during your session. If you have any questions or want me to walk you through it further, just let me know—I’m here to help! Sources: README.md | External data and RAG | LiveKit Docs | livekit-plugins/livekit-plugins-ultravox/livekit/plugins/ultravox/realtime/... | Agent speech and audio | LiveKit docs
t
objc[16431]: Class GNotificationCenterDelegate is implemented in both /Users/aritra/Documents/voice-agent-node/livekit-voice-agent/node_modules/.pnpm/@img+sharp-libvips-darwin-arm64@1.2.0/node_modules/@img/sharp-libvips-darwin-arm64/lib/libvips-cpp.8.17.1.dylib (0x130dd1af0) and /Users/aritra/Documents/voice-agent-node/livekit-voice-agent/node_modules/.pnpm/@img+sharp-libvips-darwin-arm64@1.2.4/node_modules/@img/sharp-libvips-darwin-arm64/lib/libvips-cpp.8.17.3.dylib (0x131f49978). This may cause spurious casting failures and mysterious crashes. One of the duplicates must be removed or renamed. [dotenv@17.2.3] injecting env (7) from .env.local -- tip: 📡 add observability to secrets: https://dotenvx.com/ops objc[16441]: Class GNotificationCenterDelegate is implemented in both /Users/aritra/Documents/voice-agent-node/livekit-voice-agent/node_modules/.pnpm/@img+sharp-libvips-darwin-arm64@1.2.0/node_modules/@img/sharp-libvips-darwin-arm64/lib/libvips-cpp.8.17.1.dylib (0x11fd19af0) and /Users/aritra/Documents/voice-agent-node/livekit-voice-agent/node_modules/.pnpm/@img+sharp-libvips-darwin-arm64@1.2.4/node_modules/@img/sharp-libvips-darwin-arm64/lib/libvips-cpp.8.17.3.dylib (0x126a31978). This may cause spurious casting failures and mysterious crashes. One of the duplicates must be removed or renamed. [173547.704] INFO (16431): starting worker version: "0.1.0" [173547.737] INFO (16431): Server is listening on port 64591 [173548.061] INFO (16431): registered worker version: "0.1.0" id: "AW_QpW6Ub5SGFYG" server_info: { "edition": "Cloud", "version": "1.9.3", "protocol": 16, "region": "India South", "nodeId": "NC_OHYDERABAD1A_FjAkGFdRiqqi", "debugInfo": "", "agentProtocol": 0 } [173555.030] INFO (16431): received job request version: "0.1.0" job: { "id": "AJ_42i4Bsp5y5DS", "type": "JT_ROOM", "room": { "sid": "RM_Sx2fMqDewq3m", "name": "playground-mBQZ-6fcX", "emptyTimeout": 300, "maxParticipants": 0, "creationTime": "1763208354", "turnPassword": "", "enabledCodecs": [ { "mime": "video/H264", "fmtpLine": "" }, { "mime": "video/VP8", "fmtpLine": "" }, { "mime": "video/VP9", "fmtpLine": "" }, { "mime": "video/AV1", "fmtpLine": "" }, { "mime": "audio/red", "fmtpLine": "" }, { "mime": "audio/opus", "fmtpLine": "" }, { "mime": "audio/PCMU", "fmtpLine": "" }, { "mime": "audio/PCMA", "fmtpLine": "" } ], "metadata": "", "numParticipants": 0, "activeRecording": false, "numPublishers": 0, "version": { "unixMicro": "1763208355041915", "ticks": 0 }, "departureTimeout": 20, "creationTimeMs": "1763208354864" }, "namespace": "", "metadata": "", "agentName": "", "state": { "status": "JS_RUNNING", "error": "", "startedAt": "1763208355179569795", "endedAt": "0", "updatedAt": "1763208355179569795", "participantIdentity": "agent_xPZJsNEX7uqs", "workerId": "AW_QpW6Ub5SGFYG", "agentId": "A_GWC46HSatpy7" }, "dispatchId": "AD_4bZFBod83HST", "enableRecording": false } resuming: false agentName: "" objc[16578]: Class GNotificationCenterDelegate is implemented in both /Users/aritra/Documents/voice-agent-node/livekit-voice-agent/node_modules/.pnpm/@img+sharp-libvips-darwin-arm64@1.2.0/node_modules/@img/sharp-libvips-darwin-arm64/lib/libvips-cpp.8.17.1.dylib (0x141d19af0) and /Users/aritra/Documents/voice-agent-node/livekit-voice-agent/node_modules/.pnpm/@img+sharp-libvips-darwin-arm64@1.2.4/node_modules/@img/sharp-libvips-darwin-arm64/lib/libvips-cpp.8.17.3.dylib (0x160ddd978). This may cause spurious casting failures and mysterious crashes. One of the duplicates must be removed or renamed. [dotenv@17.2.3] injecting env (0) from .env.local -- tip: ⚙️ enable debug logging with { debug: true } [173557.126] DEBUG (lk-rtc/16578): Connect callback received [173557.129] INFO (16578): Creating speech handle speech_id: "speech_a49ddaa2-a62" [173557.138] INFO (16578): participantValue.trackPublications participantValue: "identity-iK1V" trackPublications: [ { "info": { "sid": "TR_AMQNyxXyrUCFer", "name": "", "kind": "KIND_AUDIO", "source": "SOURCE_MICROPHONE", "simulcasted": false, "width": 0, "height": 0, "mimeType": "audio/red", "muted": false, "remote": true, "encryptionType": "NONE", "audioFeatures": [] }, "ffiHandle": {}, "subscribed": false } ] lengthOfTrackPublications: 1 [173559.681] INFO (16578): speech interrupted by VAD speech id: "speech_a49ddaa2-a62" [173602.079] INFO (16578): speech interrupted, new user turn detected speech id: "speech_a49ddaa2-a62" [173602.079] INFO (16578): Creating speech handle speech_id: "speech_ffc3c604-006" [173603.120] ERROR (16578): Error in SynthesizeStream [173603.125] INFO (16578): playout interrupted speech_id: "speech_a49ddaa2-a62" playbackPosition: 0 [173603.126] INFO (16578): playout completed with interrupt speech_id: "speech_a49ddaa2-a62" message: "Hi" [173632.514] INFO (16578): playout completed without interruption speech_id: "speech_ffc3c604-006" message: "Yes, I’m prepared. I can walk through my journey from a curious engineering student to a builder, including TrailMine (Smart India Hackathon 2024 winner), HashX (ETHGlobal project), QuizFlow, and my work at ISI Kolkata and Scale AI. I’ll show how I bridge theory and practice with production-scale ML systems, LLM training feedback, and full-stack/Web3 skills, and connect all of it to the AI Agent role. If you’d like, I can tailor the focus to the specific problems you’re hiring for." [173638.063] INFO (16578): Creating speech handle speech_id: "speech_5ab1c38b-2ca" [173703.038] INFO (16578): speech interrupted by VAD speech id: "speech_5ab1c38b-2ca" [173703.072] INFO (16578): playout interrupted speech_id: "speech_5ab1c38b-2ca" playbackPosition: 0 [173703.073] INFO (16578): playout completed with interrupt speech_id: "speech_5ab1c38b-2ca" message: "TrailMine, the real-time on-chain analytics tool I built, and its Smart India Hackathon 2024 win is what I’m most proud of. It was a full-stack, end-to-end project (Python, DuneSQL, Moralis, Neo4j, Streamlit) that combined data engineering with blockchain analytics under a tight deadline. The win proved my ability to bridge theory and production-grade" [173709.775] INFO (16578): Creating speech handle speech_id: "speech_7486834d-24d" [173711.582] INFO (16578): speech interrupted by VAD speech id: "speech_7486834d-24d" [173714.363] ERROR (16578): Error in SynthesizeStream [173715.157] INFO (16578): speech interrupted, new user turn detected speech id: "speech_7486834d-24d" [173715.157] INFO (16578): Creating speech handle speech_id: "speech_0141aa92-0f2" [173749.353] INFO (16578): closing agent session due to participant disconnect (disable via
RoomInputOptions.closeOnDisconnect=False
) participant: "identity-iK1V" reason: "CLIENT_INITIATED" [173749.378] INFO (16578): playout interrupted speech_id: "speech_7486834d-24d" playbackPosition: 0 [173749.378] INFO (16578): playout completed with interrupt speech_id: "speech_7486834d-24d" message: "-" ^CForce exit (Ctrl+C pressed twice) why the errors are coming
t
I'm sorry you're encountering the "Error in SynthesizeStream"—I know how frustrating that can be! This usually happens during real-time text-to-speech (TTS) streaming and can be caused by a few things, such as: • Network interruptions or issues with the WebSocket connection to the TTS provider. • Challenges during text input processing or managing the stream. • Trying to flush or interact with a stream that’s already closed. These errors come through an error callback, so having proper cleanup logic in place really helps to avoid any lingering connections. About the duplicate class implementation warnings like
GNotificationCenterDelegate
, the LiveKit sources don’t offer specific details on this. It might be worth taking a closer look at your runtime environment or how your dependencies are set up to get to the bottom of it. Please don’t hesitate to reach out if you’d like me to walk you through any of this or if you have more questions—I’m here to help! Sources: plugins/deepgram/src/tts.ts | Node.js Agents Architecture | livekit/livekit_composite | DeepWiki