Hi all - architecture question about message persi...
# agents
n
Hi all - architecture question about message persistence. I have a simple LiveKit agent and would like for it to have a frontend UI/UX with similar behavior to ChatGPT, i.e. conversations are persisted and can be resumed after long delays. The user can toggle between chat and voice modes. I’m curious if there are documented best practices, or examples, of integrating a message persistence layer. Assume I have the messages stored in a database somewhere, and I store new messages on
conversation_item_added
. My question is around handling the case where the user wants to resume that conversation, potentially days or weeks later. Can I somehow load those existing messages into the chat context of a new Livekit session/room? Ideally I would be able to take advantage of LiveKit’s SDKs to implement the frontend and show message history (e.g.
useChat
from the React SDK) rather than building something from scratch and having to manually merge “old” messages with “live” messages.
p
Yep. There is a method to add messages to the chat context. You can preload the agent with the history from your persistence layer
n
Cool - I ended up finding that bit. Only question then is if I do that, and then I use something like
useChat
or the
Chat
React component, will it load those messages, or do those components/hooks only render messages that were literally added to the session while they were mounted? I can work around this limitation easily enough if necessary but it would be nice to avoid stitching things together if I can avoid it. https://docs.livekit.io/reference/components/react/component/chat/#remarks
Message history is not persisted and will be lost if the component is refreshed. You may want to persist message history in the browser, a cache or a database.
https://docs.livekit.io/reference/components/react/hook/usechat/#remarks
Only users who are in the room at the time of dispatch will receive messages - Message history is not persisted between sessions