In the latest version of the agents sdk `livekit-a...
# agents
p
In the latest version of the agents sdk
livekit-agents@1.2.2
. I noticed there are changes around the chat context timestamps and the order of messages added: 1. It seems like the user transcript is added to agent session's chat ctx and
conversation_item_added
event is emitted after the LLM inference is invoked. a. This is causing issues in the custom plugin that I had written, any way to make the agent session's chat ctx keep in sync too with latest transcript? I am adding some custom items to the agent session chat ctx that I want the LLM to have context of. 2. The
created_at
timestamp seems to have been also updated because of 1 I guess (?) where the created_at timestamp is now different for
assistant
role and has the timestamp of when the LLM started responding and the
user
utterances have the
created_at
when the user completes speaking. a. Earlier in version
1.0.22
- the
created_at
for both assistant and user had timestamp when they completed their turn, this helped us infer the start timestamp to create a utterance level start and end timestamps from the transcript b. In the newer version - we have the assistant's start timestamp and user's end timestamp which is harder to infer for utterance level start and end timestamps now. c. I am unsure if we can do anything about this here? I believe both these are being caused because of the older version - 1.0.22 had this change which is being updated in the new version with this change. @jolly-air-155 - would really appreciate if you can suggest what I can do here to resolve this? Any reason the order was changed. I can raise a PR to have the message added before the llm inference. Would that help go back to the prev state?
j
now the user message is added to the
agent.chat_ctx
after the llm inference starts, but the
created_at
of the user message is still the same as before, it’s the time user turn completed.
p
Thanks for replying. Yes - the user message has the
created_at
after the user turn completes. But the agent's
created_at
is when the agent starts speaking which is inconsistent behavior I feel. Also - do you feel we should emit the conversation_item_added event before running the llm inference? I am unsure why that was changed in the recent version. I am happy to raise a PR to keep it the old way
j
the change was made for preemptive generation that llm generate can be started right after user transcript received before confirming the user turn is done
so it cannot add user message to the
agent.chat_ctx
when llm generate starts, but after it confirms the user turn is done. for your case, I think we can customize the
llm_node
instead, and the chat ctx sent to the
llm_node
is always the version including the latest user message
or you can customize the
on_user_turn_completed
and add your custom messages to both turn_ctx and the
agent.chat_ctx
there
the user message has the
created_at
after the user turn completes. But the agent’s
created_at
is when the agent starts speaking which is inconsistent behavior I feel.
this is to fix the order when user interrupts the agent, so the order is (interrupted agent message, new user message), instead of (new user message, interrupted agent message)
p
> so it cannot add user message to the
agent.chat_ctx
when llm generate starts, but after it confirms the user turn is done. for your case, I think we can customize the
llm_node
instead, and the chat ctx sent to the
llm_node
is always the version including the latest user message I am merging the latest chat_ctx in the LLMStream class of the plugin and the agent ctx that I have which is resolving the issue of keeping the transcripts consistent before making LLM requests. > this is to fix the order when user interrupts the agent, so the order is (interrupted agent message, new user message), instead of (new user message, interrupted agent message) Understood on why this change was made. Thanks for explaining this. Any way you suggest us to do the start and end time calculations for the user and assistant utterances in the latest version of the SDK? The
created_at
field being different for both of them is not allowing to infer either the start and end time for both of them.
j
for the user turn and agent turn, we added the opentelemetry integration in the latest version you might be interested https://github.com/livekit/agents/releases/tag/livekit-agents%401.2.0
p
Yes - thanks for adding opentelemetry. We will use this too. But we want to infer the utterance start and end timestamps in the chat context for the transcript to be used for analytical purposes. Is there no way to get the utterance timestamps inferred from the chat ctx in the latest version? I am sorry if I am stretching this issue a bit here. But this is important for us - so thanks for bearing with me on the issue.
j
I don’t think so, in chat context you only have start/end time of the user input or agent reply, there it time both are silent. I think you can use
user_state_changed
and
agent_state_changed
event to monitor listening and speaking states.
perhaps we can add a start time and a end time to the chat message tho
p
perhaps we can add a start time and a end time to the chat message tho
Yes - will this be added soon? I am happy to help contribute too. This will help multiple folks. I see issues around word level timestamps being exposed in chat ctx is needed for multiple users
j
yeah that’s what I am thinking, feel free to create a pr, but we may think about what the timestamps attribute looks in ChatMessage
p
Understood - thanks. Will see if I can raise a PR here.