I am using AI agent worker server with vad = "manu...
# ask-ai
f
I am using AI agent worker server with vad = "manual". In a session if a user interrupts the agent. I am getting the on_conversation_item_added event first for the user(which interrupted) then I am getting it for the agent, I am using this event for transcripts and I want agent's transcript first in such a case. First, why is it this way? Is there any way to fix this?
t
Thanks for reaching out, Tushar. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Hey there! What you’re seeing—where the
on_conversation_item_added
event fires for the user before the agent—is totally expected. Here’s why: the system quickly processes and adds the user’s transcript to the conversation history as soon as the STT system finalizes it. Then, the agent’s response gets generated and added right after, based on the user’s input. When using manual VAD, the system doesn’t automatically rely on end-of-utterance signals to decide when to respond, but it still processes audio and commits the user’s transcripts immediately once finalized. This helps keep the conversation flowing smoothly. If you’d prefer the agent’s transcript to show up first in these cases, you might want to add some custom logic to reorder or delay how these events are handled in your app. Just let me know if you’d like a hand with that—I’m happy to help! Sources: Turn detection and interruptions | LiveKit Docs | Events and error handling | LiveKit Docs | tests/test_agent_session.py
f
Is there a way to fire
on_conversation_item_added
for the agent as soon as we have received a response from the llm instead of waiting for the tts?
t
Just to give you a quick overview: the
on_conversation_item_added
event for the agent currently fires after the TTS (Text-to-Speech) processing finishes. This happens because the system commits conversation items to the chat history when they're being presented to users via TTS. Unfortunately, there isn’t a built-in way to change this so the event triggers right after receiving the LLM response. But don’t worry! Here are a few alternative ideas you might find helpful: • Use the
speech_created
event:
This one happens earlier in the process when new agent speech is generated. It comes with a
speech_handle
property you can use to keep track. • Listen to LLM completion events: If your setup supports it, you could listen for events that signal the LLM response is done and use those to trigger what you need. • Custom implementation: You might consider extending the agent session or building custom event handling to emit your own events right when the LLM response arrives. It would be great to know more about what you’re aiming to do! Are you trying to update a UI, log responses, or maybe trigger other actions? The more details you share, the better I can help suggest the perfect approach for you. Sources: examples/other/text_only.py | Events and error handling | LiveKit Docs