few-afternoon-34452
11/18/2025, 8:57 PMproc.userdata["vad"] = silero.VAD.load()
turn_detection=MultilingualModel(),
vad=ctx.proc.userdata["vad"],
preemptive_generation=True,
Above is my agent configuration.
@session.on("user_state_changed")
def _on_user_state_changed(ev):
"""Track user state changes (speaking vs listening)"""
logger.info(f"user_state_changed + {ev.old_state} -> {ev.new_state}")
callbacks are not coming when use is having the conversation. what could be the possible reason?few-afternoon-34452
11/18/2025, 8:58 PMlively-winter-88668
11/19/2025, 10:23 AMuser_state_changed to one of our basic examples as follows and I see the callbacks, can you see if this works for you?
import logging
import os
from pathlib import Path
from dotenv import load_dotenv
from livekit.agents import JobContext, UserStateChangedEvent, WorkerOptions, cli
from livekit.agents.voice import Agent, AgentSession
from livekit.plugins import silero
from livekit.plugins.turn_detector.multilingual import MultilingualModel
load_dotenv(dotenv_path=Path(__file__).parent.parent / '.env')
logger = logging.getLogger("listen-and-respond")
logger.setLevel(logging.INFO)
class ListenAndRespondAgent(Agent):
def __init__(self) -> None:
super().__init__(
instructions="""
You are a helpful agent. When the user speaks, you listen and respond.
""",
stt="assemblyai/universal-streaming",
llm="openai/gpt-4.1-mini",
tts="cartesia/sonic-2:6f84f4b8-58a2-430c-8c79-688dad597532",
vad=silero.VAD.load()
)
async def on_enter(self):
self.session.generate_reply()
async def entrypoint(ctx: JobContext):
session = AgentSession(
turn_detection=MultilingualModel()
)
@session.on("user_state_changed")
def on_user_state_changed(event: UserStateChangedEvent):
logger.info(f"User state changed: {event.old_state} -> {event.new_state}")
await session.start(
agent=ListenAndRespondAgent(),
room=ctx.room
)
if __name__ == "__main__":
cli.run_app(WorkerOptions(entrypoint_fnc=entrypoint))few-afternoon-34452
11/19/2025, 12:53 PMturn_detection=MultilingualModel(), is added to the Agent?