async def entrypoint(ctx: agents.JobContext): ...
# ask-ai
r
async def entrypoint(ctx: agents.JobContext): room_id = ctx.room.name # Use room name as room ID # Initialize chat history for this room if room_id not in chat_history: chat_history[room_id] = [] session = AgentSession( llm=google.beta.realtime.RealtimeModel( model="gemini-2.0-flash-exp", voice="Puck", temperature=0.8, instructions=tts_instructions, modalities=["text"], ), tts=openai.TTS(model="gpt-4o-mini-tts", voice="ash",instructions=tts_instructions), vad=ctx.proc.userdata["vad"], ) mcp_server = MCPServerSse( params={"url": "http://localhost:7777/sse"}, cache_tools_list=True, name="FestoMCP" ) # Create room context to pass to MCP tools room_context = { "room_name": ctx.room.name, "room_id": ctx.room.name, # Using room name as room ID # You can add more context here: # "participant_count": len(ctx.room.participants), # "session_start_time": datetime.now().isoformat(), } agent = await MCPToolsIntegration.create_agent_with_tools( agent_class=Assistant, mcp_servers=[mcp_server], room_context=room_context # Pass the room context ) # Handle errors @session.on("error") def on_error(event): logger.error(f"Session error: {event.error}, recoverable: {event.error.recoverable}, source: {event.source}") if not event.error.recoverable: # asyncio.create_task(session.say("Sorry, an error occurred. Please try again.")) logger.error("Unrecoverable error occurred, stopping session.") await session.start( room=ctx.room, agent=agent, room_input_options=RoomInputOptions( # noise_cancellation=noise_cancellation.BVC(), # noise_cancellation=noise_cancellation.NC(), ), ) await ctx.connect() await session.generate_reply( instructions=SESSION_INSTRUCTION, ) if name == "__main__": agents.cli.run_app(agents.WorkerOptions(entrypoint_fnc=entrypoint, prewarm_fnc=prewarm)) i have this code but this code dont work vad . i mean not intrupted by user talk ?
t
Thanks for reaching out, Av. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
I'm here to help you get VAD (Voice Activity Detection) working smoothly so it can properly interrupt the agent when a user speaks. Let’s walk through some important settings together: • Enable Interruptions: Make sure the
allow_interruptions
setting is set to
True
. This lets users interrupt the agent while it’s speaking. • Set Minimum Speech Duration: Use the
interrupt_speech_duration
parameter to set how long a user needs to speak (for example, 0.5 seconds) before an interruption counts. • Configure Minimum Words: If you’re using STT (Speech-to-Text), the
interrupt_min_words
parameter helps specify how many words are needed to trigger an interruption. • Turn Detection Mode: If you’re working with server-side turn detection (like the OpenAI Realtime API), be sure to disable client-side VAD interruptions to prevent any conflicts. • Manual Interruptions: If you ever need to, you can use the
agent.interrupt()
method to manually interrupt the agent. Also, combining VAD with STT can make things even more responsive since VAD picks up interruptions faster than transcription alone. If you’d like, I’m happy to help you set these up or answer any questions you have along the way! Sources: VoicePipelineAgent | LiveKit Docs | livekit-agents/livekit/agents/voice/audio_recognition.py | agents/src/voice/agent_activity.ts | Improving voice AI's turn detection with transformers
r
ok give me sample code. what should i change
t
I'm glad to share this sample code snippet to help ensure VAD interruptions work smoothly in your session:
r
please give me
t
Here is the updated sample code with the necessary changes for VAD interruptions: