Best way to get full conversation history
# 🤝help
b
Hello ! I am building a bot that uses the chat history to determine questions to ask the user and possible answer to their problem. At the moment I am using this snippet: workflow.transcript = event.state.session.history.map((a) => a.sender + ':' + a.preview).join('\n') I have 1 question and 1 problem about this: From my understanding, this snippet should gather the entire chat history no matter what workflow I am in right? My problem is that at some point, the variable where I store the history gets filled with the latest chat history, but the first dialogues are deleted. I guess this could come from either the variable size limit or even the history size limit ? So I wondered if there was a better way to do this ? Just to be clear at the end of the discussion I need to get back the entire chat history, no matter how long it is. Thank you !
a
Hey @bulky-dusk-45106 , you're on the right track! A couple things to help you with the next steps: 1.
event.state.session.history
is a windowed memory that only saves the last 6 messages sent. This could mean 3 user messages and 3 bot messages, or 5 bot messages and 1 user message, depending on your flow. Your code snippet should first see if the message is already saved in
workflow.transcript
and, if not, append it rather than overriding it. 2. There's a new agent, summary agent, that will use GPT to summarize the conversation and save it to a variable. This is a summarized memory that can be more condensed by less detailed, if that's what you're looking for. 3. Your code as it is now needs to be run inside a flow after each conversational turn- that's a pain! You can make it run automatically by putting it inside of an
after_incoming_middleware
hook. If you're looking for a deeper dive into chatbot memory, this post from Pinecone is really thorough. It's about Langchain, not Botpress, but the concepts for different memory types transfer well. https://www.pinecone.io/learn/langchain-conversational-memory/
b
Wow that's awesome ! Thanks a lot for your answer, especially the hook part, I had no idea that was a thing. It will help me a lot !
684 Views