HI, is there a way to get the latest message of th...
# ask-ai
m
HI, is there a way to get the latest message of the conversation in Livekit when there is parallel tool calling
t
Thanks for reaching out, Shataxi. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Thanks — I’m responding to your question about whether you can get the latest message in a LiveKit conversation when multiple tools are being called in parallel. Yes — you can access the latest message even with parallel tool calls. Two straightforward ways to get it: • Use `session.history`:
session.history
is a chronological list of all conversation items (user messages, tool calls, and tool outputs). The latest message is the last item in that list, so read the final element of
session.history
. • Use `on_user_turn_completed`: inside an agent, the
on_user_turn_completed
lifecycle method receives a
new_message
parameter that represents the user’s most recent message. This method runs before the agent generates a response, so it’s a convenient place to access the latest input. If you need to access the conversation state from inside tool execution, the tool’s
RunContext
provides access to the session (and therefore
session.history
) so you can inspect the latest item there as well. Would you like a short code example showing: 1) how to read the last item from
session.history
, or 2) how to use
on_user_turn_completed
or
RunContext
inside a tool? Sources: External data and RAG | LiveKit Documentation | Pipeline nodes and hooks | LiveKit Documentation | Building multi-agent architectures with LiveKit agents | LiveKit
m
how is update_chat_context useful
t
I don't have the answer you're looking for. You could also try asking your question: • in one of the other Slack channels or • to https://deepwiki.com/livekit/livekit_composite which is trained on all LiveKit source code If you find the answer, please post it here to help others!