Designing a Deterministic Intent Flow for a Reservation Chatbot

Hello everyone, I’m new to the world of agent-based systems and AI. I am currently building an AI chatbot for restaurant table reservations via WhatsApp. To do this, I have developed a CrewAI Router Intent Flow to orchestrate the application’s flow as deterministically as possible.

Below is the current state of my flow:

class ChatbotState(BaseModel):
conversation_history: List[Dict[str, str]] =
latest_message: str = “”
phone_number: str = “”
intent: Optional[str] = None

Here’s how I’ve structured the flow:

  1. start() – This function takes the user’s latest message and analyzes its intent, updating the intent field in the current state.
  2. router() – Based on the detected intent, it routes the execution to the appropriate Crew.
  3. listen(“create_reservation”) – In this case, if the detected intent is "create_reservation", the flow continues here.

Currently, I’ve defined only this route.

The problem I’m facing is more about how to structure the flow. For example, to create a table reservation, the user needs to provide the following fields to correctly invoke the reservation tool:

  1. reservation_date
  2. start_time
  3. client_name
  4. party_size
  5. phone_number

My issue is that I don’t know how to retrieve these necessary parameters to correctly invoke the tool, since every time the user sends a new message, the process restarts from start(). Initially, I thought about creating a loop within listen(“create_reservation”), but I’m not sure if that’s the correct approach. Additionally, I’m uncertain where to store the parameters as they are extracted from the user’s messages.

I appreciate any insights or suggestions on how to better manage and store the conversation state and parameters throughout the flow.

1 Like

The loop on the create_reservation method is probably what you need. A variation of a form filling agent. I created lead generation chatbot that uses the concepts you want and you can adapt it to you needs.

The chatbot asks the user questions until it has all the information it needs to proceed.

Blog post: Building a Lead Qualification Chatbot with CrewAI and Gradio

Github: GitHub - zinyando/crewai_lead_qualification_chatbot: A lead qualification demo chatbot using CrewAI and Gradio

Feel free to reach out to me if you need help.

3 Likes