When using Agents in Retool Embed, the current chat history is lost after a page reload. Is there a way to retrieve past chat history so users can view previous conversations and continue from where they left off? Ideally, Iād like users to be able to see a list of their previous chats and select one to resume.
i store every message in a table. I also have a 2nd table to hold "conversation" data.
Conversation Table:
conversation_id (string)
just a suggestion, I concatenate `'user_id' + '-' + 'conversation_count'
so for a user with user_id = 792069 who creates a new conversation, i'd use '792069-1' as the conversation_id so I can shortcut certain searches later on
title (string)
created_by (int)
created_on (Date)
updated_on (Date)
this willl help you later on so you can use polling to notify anybody else in the conversation when there's a new message
joined_users (JSON - Array of ints for user_id's)
this is so you can get not just the conversations somebody has created but also the conversations of others they've joined
Message Table:
message_id (string)
again, just a suggestion but I use conversation_id + '-' + message_count
so using the above example the first message_id would be 792069-1-1
conversation_id (string - refers to table above)
content (str)
created_by (int)
created_on (Date)
update_message_id (string - refers to another row in this table, if the user edits their message we want to store the original and the edit while only displaying the newest update... or keep following update_message_id until it's null as that will be the last update. so if this column has a value we know we need to display the content from this updated message id)
we don't need updated_on in this table since if there is an update, we can just check the created_on date of the message with this id
type (Enum['user', 'ai'])
you could instead create a user_id specifically for the ai and use that anytime you process a response. in fact, this would let you have different AIs for different things or people and later on sort messages by the ai so you can monitor, analyze and start the foundations of a dataset you could use to fine-tune your model.... plus you save like 4 bytes per row by not having this. idk why i'm keeping it here lol.
now that you have the database design, you need to hook it up to the frontend so that when the user sends a message it adds a row to the Message Table and if they click a button it adds a row to the Conversation Table. after that, you just have to make some queries so that u can get all the conversations created by current_user's user_id, all the conversations a user_id has joined, all the messages for for a given conversation_id and then i think you should be good to go?
Thanks @bobthebear this is the approach I'd expect in terms of building my own conversation history. Thank you for the details on the two tables. I'd probably also store what agent or LLM that was used each convo.
I guess I was hoping there was something more native within Retool's AI agents that I didn't know about.
That you so much for an impressive DIY solution @bobthebear!
@mbertino We currently have feature request tickets to have this functionality native to the agent experience. Both for agents to be able to recognize the user and have user specific history as well as giving agents "long term" memory which ultimately means storing all the conversation data to be used as context and exposing some UI to allow users to pick and choose old conversations to resume, in the same manner that other tools such as ChatGPT current have.
We are moving fast and love the feedback! Will update this thread with any news I get on those feature requests
heh, yup I missed the model name good catch. keeping it in the convo table would work, but you could also keep it for every message generated.
you'll have null or empty values for this column on messages from users, but when you use the message history you could pull the model name used to generate each message and pass this along in a prompt that informs a model to check responses from different models before using it or to weigh the responses from different models based on if the model used is ideal for the task given.
if you want to avoid the null or empty values you'll want to create a new table named like "message_metadata" (ref message_id, model vendor, model name, ect) and possibly and 2nd for "converstation_settings" (can anybody join, is it public/private, themes, is convo open/closed, ect)
@mbertino Can you share a screenshot of what the Agent embedding looking like on your end? I am talking to the eng team about how we could include the same window of past agent chats that is displayed in Retool apps.