I made a Candy AI Clone, but I'm stuck with a weird problem

Hey everyone,
I’m working in Triple Minds and i have a project So, I’ve been working on a Candy AI Clone project for the past few days — basically building my own version of Candy AI with custom data and character responses. Everything’s going great so far, but I’m stuck on one issue.

Whenever I try to save the chat history and reload it, the AI starts repeating old messages instead of continuing the conversation naturally. I’m using a Python + FastAPI backend with OpenAI API integration and a React frontend.

Here’s what I’ve tried so far:

  • Added unique session IDs for every chat

  • Stored conversation in MongoDB

  • Tried clearing context after every 10 messages

  • Still, it loops back to the same responses when reloaded

Has anyone faced a similar issue while making a Candy AI or any chatbot clone?
Would love some advice or code suggestions to handle this properly.

Thanks in advance :folded_hands: