facing an issue with the conversation items gettin...
# ask-ai
p
facing an issue with the conversation items getting added to the current chat context. I am leveraging the
on_user_turn_completed
event for a manual turn detection, I stop the response using StopResponse() for no further agent actions. Here is a conversation timeline i.e Agent - Hello, how are you doing, please introduce yourself. User - Hey, this is uhhh (2 sec gap) I am harish so uhhh (2 sec gap) doing good and I wanted to ask that ... (2sec gap) are you doing good. So after this, my custom turn detection returns turn end and the agent action follows. But there after these converstaion, the chat context would only have the last sentence told i.e
are you doing good
. Rest of the sentences are not appended in the chat context. Is this an issue or am I missing something?
t
Thanks for reaching out, harish. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
I understand the issue you're facing happens because raising
StopResponse()
in the
on_user_turn_completed
event causes an early return, which means the logic that adds user messages to the chat context gets skipped. This is actually by design to stop any further processing, including updating the context. To make sure your user message still gets added to the chat context while stopping the agent's reply, you have a couple of options: • You can manually append the message to
self._agent._chat_ctx.items
before raising
StopResponse()
. • Or, you can use
self._agent.update_chat_ctx()
to save the message. If you'd like, I’m here to help you work through these changes—just let me know! Sources: livekit-agents/livekit/agents/voice/agent_activity.py | Pipeline nodes and hooks | LiveKit docs | Events and error handling | LiveKit docs | Agents v0.x migration guide - Node.js | LiveKit Docs