Streamlit chat history

Hello everyone,
I am testing a chatbot using langchain and streamlit.
I was wondering if there is a way to save chat history as cached data on the browser, so in case i closed the browser or turned off my laptop, the next day i can still have access to the previous conversation, also the chatbot can still have access to chat history.

Yes it’s is possible with the help of st.session_state. For more information, here is the reference as follows:-

import streamlit as st

st.title("Echo Bot")

# Initialize chat history
if "messages" not in st.session_state:
    st.session_state.messages = []

# Display chat messages from history on app rerun
for message in st.session_state.messages:
    with st.chat_message(message["role"]):

# React to user input
if prompt := st.chat_input("What is up?"):
    # Display user message in chat message container
    # Add user message to chat history
    st.session_state.messages.append({"role": "user", "content": prompt})

    response = f"Echo: {prompt}"
    # Display assistant response in chat message container
    with st.chat_message("assistant"):
    # Add assistant response to chat history
    st.session_state.messages.append({"role": "assistant", "content": response})

Yes but this code only to append the previous messages to a list of messages and show all the chat history in the chat message container, but when the user turn of his browser or laptop all the chat history will be lost, am i correct ?, but i meant something permanent, like maybe a cookie or as i mentiond before like cached data on the browser, that it will always remember your browsing history, unless you clear the cache manually.

i dont know if you could solve your problem but i think this might help: