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 InputLanggraphReactAgent(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
- Add Components: Place a
Chat Input, aLanggraphReactAgent(rename it to “Intent Detector”), and aGeminicomponent. - Connections:
- Connect
Chat Input(message) toIntent Detector(input). - Connect
Gemini(model) toIntent Detector(llm).
- Connect
Intent DetectorConfiguration:- 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.
- System Prompt:
2. Building the Routers
- Add Components: Place two
Conditional Routercomponents. - Connections:
- Connect
Intent Detector(response) toConditional Router 1(input_text). - Connect
Conditional Router 1(false) toConditional Router 2(message). - Connect
Intent Detector(response) toConditional Router 2(input_text).
- Connect
- Configuration:
- Router 1:
Match Text->nivel1. Thetrueoutput will go to the Level 1 Agent. - Router 2:
Match Text->nivel2. Thetruoutput will go to the Level 2 Agent. Thefalsewill go to the Level 3 Agent.
- Router 1:
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. ConnectGeminiandChroma DB(inRetrievermode) to the agent’sllmandtoolsinputs. The agent’s output goes to aChat Output. - System Prompt:
Respond based solely on the information from your tool.
- Components:
-
Level 2 Agent (API):
- Components:
LanggraphReactAgent(Level 2 Agent),Gemini,API Request. - Connections: Connect
Router 2(true) to the agent’s input. ConnectGeminiandAPI Requestto thellmandtoolsinputs. The agent’s output goes to aChat Output. - System Prompt:
Search for the order status using your tool and communicate it.
- Components:
-
Level 3 Agent (Escalation):
- Components:
LanggraphReactAgent(Level 3 Agent),Gemini,Telegram Message. - Connections: Connect
Router 2(false_result) to the agent’s input. ConnectGeminiandTelegram Messageto thellmandtoolsinputs. The agent’s output goes to aChat Output. - System Prompt:
Notify the human team via Telegram and confirm to the user that their request has been submitted.
- Components: