async def entrypoint(ctx: agents.JobContext): ...
# ask-ai
b
async def entrypoint(ctx: agents.JobContext): system_prompt = prompts.prompt2 # parts = str(ctx.room.name).split("-") # filename = "-".join(parts[:-1]) # prompt_file_path = f'{get_constant("custom_prompt_dir")}/{filename}.txt' # print("looking for file name:-",filename) # if(os.path.exists(prompt_file_path)): # print("custom prompt file exists") # with open(prompt_file_path, 'r', encoding='utf-8') as file: # system_prompt = file.read() # print("content read success",system_prompt) # else: # print("custom prompt file does not exists") session = AgentSession( # llm=openai.realtime.RealtimeModel( # voice="coral" # ) llm=google.beta.realtime.RealtimeModel( model="gemini-2.0-flash-exp", voice="Aoede", temperature=0.8, instructions="start with a greeting", ), ) print("session created") # Event handler for when a participant connects @ctx.room.on("participant_connected") def on_participant_connected(participant: rtc.RemoteParticipant): print(f"Participant connected: {participant.name} (SID: {participant.sid})") # Subscribe to existing tracks for track_publication in participant.track_publications.values(): if track_publication.track is not None: print(f"Subscribing to existing track: {track_publication.track.kind} from {participant.name}") track_publication.set_subscribed(True) # Event handler for when a track is published by a participant @ctx.room.on("track_published") def on_track_published(publication: rtc.RemoteTrackPublication, participant: rtc.RemoteParticipant): print(f"Track published by {participant.name}: {publication.kind}") # Automatically subscribe to the published track if publication.kind == rtc.TrackKind.KIND_AUDIO: print(f"Subscribing to audio track from {participant.name}") publication.set_subscribed(True) elif publication.kind == rtc.TrackKind.KIND_VIDEO: print(f"Subscribing to video track from {participant.name}") publication.set_subscribed(True) # Event handler for when a track is subscribed @ctx.room.on("track_subscribed") def on_track_subscribed(track: rtc.Track, publication: rtc.RemoteTrackPublication, participant: rtc.RemoteParticipant): print(f"Successfully subscribed to {track.kind} track from {participant.name}") # You can add additional processing here for the subscribed track if track.kind == rtc.TrackKind.KIND_AUDIO: print(f"Audio track ready for processing from {participant.name}") elif track.kind == rtc.TrackKind.KIND_VIDEO: print(f"Video track ready for processing from {participant.name}") # Event handler for when a participant disconnects @ctx.room.on("participant_disconnected") def on_participant_disconnected(participant: rtc.RemoteParticipant): print(f"Participant disconnected: {participant.name} (SID: {participant.sid})") # Event handler for when a track is unsubscribed @ctx.room.on("track_unsubscribed") def on_track_unsubscribed(track: rtc.Track, publication: rtc.RemoteTrackPublication, participant: rtc.RemoteParticipant): print(f"Unsubscribed from {track.kind} track from {participant.name}") await session.start( room=ctx.room, agent=Assistant(prompt=system_prompt), room_input_options=RoomInputOptions( # LiveKit Cloud enhanced noise cancellation # - If self-hosting, omit this parameter # - For telephony applications, use
BVCTelephony
for best results noise_cancellation=noise_cancellation.BVC(), ), ) print("Room created:", ctx.room) await ctx.connect() # Subscribe to tracks from participants who are already in the room for participant in ctx.room.remote_participants.values(): print(f"Found existing participant: {participant.name}") for track_publication in participant.track_publications.values(): if track_publication.track is not None: print(f"Subscribing to existing track: {track_publication.track.kind} from {participant.name}") track_publication.set_subscribed(True) await session.generate_reply( instructions="start with a greeting ", ) even though i am subscribing to the new track still the agent cant listen to the new partecipant agent is not responding to the new partecipants audio .
t
Thanks for reaching out, Aman. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
There could be a few reasons why the agent isn’t responding to new participant audio even after subscribing to the track. Let’s walk through some possibilities together: • Voice Activity Detection (VAD) Threshold: Sometimes the VAD threshold might be set a bit too high, which can stop the agent from picking up speech. Try lowering the
min_silence_duration
in your VAD settings to see if that helps. • Participant Linking: Double-check that the agent is properly linked to the participant using the
#linkParticipant
method. The agent only processes audio from the participant it’s linked to. • Track Source Verification: Make sure the published track’s source is
TrackSource.SOURCE_MICROPHONE
. The agent only works with microphone audio. • Audio Stream Processing: Confirm that the audio stream is being created and processed correctly. It’s a good idea to verify details like sample rate, channels, and frame size. • Stream Attachment: Check that the input stream is properly attached using the
on_attached()
method. If streams aren’t attached, frames can get dropped. • Session Initialization: Make sure the agent’s session is created and started before it tries to process any participant audio. If you want to dig a bit deeper, here are some helpful tips: • Keep an eye on the agent’s state transitions (like
initializing
,
listening
,
thinking
,
speaking
). • Listen for
TrackSubscribed
events to confirm the track subscription is working. • Log audio frames to see if they’re being received and processed properly. • Verify that the
linkedParticipant.identity
matches the participant whose audio you want to process. If you want, I’m here to help you troubleshoot any part of your setup or go through logs that might shed some light on the issue. Just let me know! Sources: agents/src/multimodal/multimodal_agent.ts | livekit-agents/livekit/agents/voice/room_io/_input.py | Web and mobile frontends | LiveKit Docs | Web and mobile frontends | LiveKit Docs | Speech & Audio Processing | livekit/livekit_composite | DeepWiki