How to Transition a ChatGPT Managed Chat to a Human at the Right Moment

I’m working on API project where I’d like to have ChatGPT ask my leads basic questions and once the basics are collected, I want ChatGPT to return something like “I_AM_DONE_WITH_COLLECTING_ALL_THE_BASIC_INFO” so I can transition the conversation to a real human being in our office.

I’d be listening for my CRM events with webhooks and I could catch the I_AM_DONE_WITH_COLLECTING_ALL_THE_BASIC_INFO string in lead’s notes/communications and forward the conversation to a real human being relatively easily.

More details about the project:

  1. A lead comes into my CRM
  2. A conversation starts via SMS/text messaging. On my side, it would be ChatGPT asking the questions. In the other side, it’s the lead = the customer.
  3. I need to know what kind of problem they have - getting the information about the problem ifself is not straightfoward but so far the question’s I’ve been getting (while playing a fake lead) in the ChatGPT’s web interface were prety good.
  4. Where they live
  5. What’s their email etc.
  6. The point I’m struggling the most is how to make GhatGPT “realize” it has collected all the information so I can transition the chat to a real human being (if the lead is good). And by “realizing”, I want ChatGPT to return the I_AM_DONE_WITH_COLLECTING_ALL_THE_BASIC_INFO string.

Here are my problems:

Problem 1:
I tried to run a few chats where I instructed ChatGPT to return specific string when all the info is collected (the I_AM_DONE_WITH_COLLECTING_ALL_THE_BASIC_INFO) and it would sometimes work but sometimes it would just continue the conversation with the lead despite already having all the info needed. I literally said “once you have all the information collected, return I_AM_DONE_WITH_COLLECTING_ALL_THE_BASIC_INFO and do not engage in the chat anymore”.

Problem 2:
I am also struggling with making ChatGPT to ask just one question at a time. Again, I would intruct “you are only allowed to ask one question at a time” but it would sometimes work but sometimes I’d get 7 questions at once.

I’m wondering whether anyone has been facing the same challenge and was able to find any reasonable solution to these problems?

And yes, I do realize maintaing a conversation through API is not that easy because I will need to send all the previous replies for every new prompt API request but let’s say it can be done.