Chapter 3: The Agent and Routing System
With the knowledge base ready, it is time to build the main flow that will interact with the user.
1. The Intent Classifier: The Orchestrating Brain
This is the first and most important part of the flow.
- Add Components: Place a
Chat Input, anAgent(rename it to “Intent Detector”), and aGemini. - Connections:
- Connect the
messageoutput ofChat Inputto theinput_valueinput of theIntent Detector. - Connect the
model_outputoutput ofGeminito thellminput of theIntent Detector.
- Connect the
Intent DetectorConfiguration:- System Prompt:
You are an intent classifier for customer service.Analyze the user's message and respond with ONE SINGLE word: "nivel1", "nivel2", or "nivel3".Classification Criteria:- "nivel1": Inquiries about company information.- "nivel2": Inquiries about order status or system information such as products.- "nivel3": Requests for product returns or need for human intervention as requested by the client.Only respond with the corresponding word, without additional explanations.
- System Prompt:
2. The Decision Hub: Configuring the Routers
Unlike a chained system, we will connect three Conditional Routers in parallel to create an efficient decision hub.
- Add Components: Place three
Conditional Routercomponents. - Parallel Connections:
- Connect the
responseoutput of theIntent Detectorto theinput_textinput of ALL THREE routers. - Connect the
messageoutput of the originalChat Inputto themessageinput of ALL THREE routers. (This is crucial for the original question to reach the final agent).
- Connect the
- Configuration of Each Router:
- Router 1:
Match Text->nivel1. Thetrue_resultoutput will activate the Level 1 Agent. - Router 2:
Match Text->nivel2. Thetrue_resultoutput will activate the Level 2 Agent. - Router 3:
Match Text->nivel3. Thetrue_resultoutput will activate the Level 3 Agent.
- Router 1:
3. The AI Departments: Specialized Agents
Finally, build a branch for each level, connecting the true_result output of the corresponding router.
-
Agente Nivel 1 (Knowledge Department - RAG):
- Components: An
Agent, aGemini, aRAG Agentas a tool, and aChroma DB. - Connections: The
true_resultoutput ofRouter 1connects to theinput_valueinput of theAgent. This agent uses theRAG Agentas a tool, which in turn uses aChroma DBconfigured inRetrievermode. Chroma DBConfiguration: Use the sameCollection Name(ecommerce_policies) as in Chapter 2.- Agent’s System Prompt:
Answer the user's question based solely on the information provided by your search tool.
- Components: An
-
Agente Nivel 2 (Systems Department - API):
- Components: An
Agent, aGemini, and anAPI Requestas a tool. - Connections: The
true_resultoutput ofRouter 2connects to theinput_valueinput of theAgent. TheAPI Requestconnects to itstoolsinput. - Agent’s System Prompt:
Your sole function is to use the API tool to query the order status and communicate the result clearly to the user.
- Components: An
-
Agente Nivel 3 (Human Support Department - Escalation):
- Components: An
Agent, aGemini, and aTelegram Messageas a tool. - Connections: The
true_resultoutput ofRouter 3connects to theinput_valueinput of theAgent. TheTelegram Messageconnects to itstoolsinput. - Agent’s System Prompt:
Use your Telegram tool to notify the support team about the customer request. Then, inform the user that their case has been escalated and that they will be contacted shortly.
- Components: An