Skip to content

Chapter 3: Building the Routing Flow

With the knowledge base ready, it is time to build the main flow that will interact with the user.

Required Components

  • Chat Input
  • LanggraphReactAgent (x4 - one for classifying, three for the levels)
  • Conditional Router (x2)
  • Chroma DB (for Level 1)
  • API Request (for Level 2)
  • Telegram Message (for Level 3)
  • Chat Output (x3 - one for each level)
  • Gemini (x4 - one for each agent)

1. Building the Intent Classifier

  1. Add Components: Place a Chat Input, a LanggraphReactAgent (rename it to “Intent Detector”), and a Gemini component.
  2. Connections:
    • Connect Chat Input (message) to Intent Detector (input).
    • Connect Gemini (model) to Intent Detector (llm).
  3. Intent Detector Configuration:
    • System Prompt:
      You are an intention classifier. Respond with ONE SINGLE word: "nivel1", "nivel2", or "nivel3".
      - "nivel1": Inquiries about company information.
      - "nivel2": Inquiries about order status.
      - "nivel3": Requests for returns or human intervention.

2. Building the Routers

  1. Add Components: Place two Conditional Router components.
  2. Connections:
    • Connect Intent Detector (response) to Conditional Router 1 (input_text).
    • Connect Conditional Router 1 (false) to Conditional Router 2 (message).
    • Connect Intent Detector (response) to Conditional Router 2 (input_text).
  3. Configuration:
    • Router 1: Match Text -> nivel1. The true output will go to the Level 1 Agent.
    • Router 2: Match Text -> nivel2. The tru output will go to the Level 2 Agent. The false will go to the Level 3 Agent.

3. Building the Specialized Agents

For each level, create the following set of components and connect them:

  • Level 1 Agent (RAG):

    • Components: LanggraphReactAgent (Level 1 Agent), Gemini, Chroma DB.
    • Connections: Connect Router 1 (true) to the agent’s input. Connect Gemini and Chroma DB (in Retriever mode) to the agent’s llm and tools inputs. The agent’s output goes to a Chat Output.
    • System Prompt: Respond based solely on the information from your tool.
  • Level 2 Agent (API):

    • Components: LanggraphReactAgent (Level 2 Agent), Gemini, API Request.
    • Connections: Connect Router 2 (true) to the agent’s input. Connect Gemini and API Request to the llm and tools inputs. The agent’s output goes to a Chat Output.
    • System Prompt: Search for the order status using your tool and communicate it.
  • Level 3 Agent (Escalation):

    • Components: LanggraphReactAgent (Level 3 Agent), Gemini, Telegram Message.
    • Connections: Connect Router 2 (false_result) to the agent’s input. Connect Gemini and Telegram Message to the llm and tools inputs. The agent’s output goes to a Chat Output.
    • System Prompt: Notify the human team via Telegram and confirm to the user that their request has been submitted.