How to keep graphs in chat_history

Hello everyone,
I’m trying to build a chatbot that generates matplotlib graphs.
I achieved it, but I am not able to show the graphs in the chat history.

This is my code:

msgs = StreamlitChatMessageHistory()
--- Agent creation
question = st.chat_input('Ask your question')

for msg in msgs.messages:
        if type(msg.content) == str:
            st.chat_message(msg.type).write(msg.content)
        else:
             st.chat_message(msg.type).pyplot(msg.content)

if question:
    answer = agent_executor.invoke({'input':question})['output']
    if ('Plot' or 'plot') not in question:
        st.chat_message('human').write(question)
        st.chat_message('ai').write(answer)
    else:
        st.chat_message('human').write(question)
        st.chat_message('ai').pyplot(answer)

It creates the graph when asked, but does not keep it in chat history. Why?
Many thanks for your help.

+1 same question for me!

Because you have not save it in message history.

Hi @ferdy , i’m new here.

can you provide any example or links about the solution that you suggest?
it will help me a lot.

or maybe @brio can help me if you already found the way to do it.

Thanks a lot!

@stheoz @kotte @brio could you show your code in github repository?

Hi @brio & @kotte , could you please let me know if you could find the solution?