Best way to build an AI companion chatbot using Gemini API with memory and safety controls?

Hi everyone,

I’m exploring how to build an AI companion-style chatbot using the Gemini API. My goal is to create a conversational assistant that can maintain context, remember user preferences during a session, and respond in a natural way while still following safety and content policies.

I’m trying to understand the best approach for:

  1. Managing short-term and long-term conversation memory

  2. Keeping character/personality consistency across chats

  3. Handling safety filters and blocked responses properly

  4. Structuring prompts so the assistant feels natural but does not produce unsafe or policy-violating content

  5. Choosing the right Gemini model for a production chatbot experience

Has anyone here built a similar chatbot with the Gemini API?
What architecture, prompt structure, or memory setup would you recommend?

Thanks in advance.