This question originally came up in our Slack community and the thread has been consolidated here for long-term reference.
I have a LiveKit agent with a frontend UI similar to ChatGPT where conversations are persisted and can be resumed after long delays. Users can toggle between chat and voice modes.
I’m storing messages in a database and saving new messages on conversation_item_added.
My question is: when a user wants to resume a conversation days or weeks later, how can I load existing messages into the chat context of a new LiveKit session/room?
Ideally I’d like to use LiveKit’s React SDK components like useChat or the Chat component to display message history, rather than building a custom solution that manually merges old and live messages.
You can preload the agent with conversation history from your persistence layer using the method to add messages to the chat context.
However, the React components (useChat hook and Chat component) only render messages that are dispatched while the component is mounted. From the docs:
“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.”
“Only users who are in the room at the time of dispatch will receive messages - Message history is not persisted between sessions”
This means you’ll need to implement a custom solution to display historical messages alongside live messages from the session. The agent’s chat context will have the full history for context-aware responses, but the frontend display requires manual stitching of old and new messages.