Spaces:
Sleeping
Sleeping
Pawan Mane commited on
Commit Β·
f3c75c2
1
Parent(s): 4cc24b5
LLM Changes
Browse files- app/nodes/router.py +20 -12
app/nodes/router.py
CHANGED
|
@@ -14,23 +14,31 @@ def router_node(state: AgentState) -> AgentState:
|
|
| 14 |
tool_descriptions = "\n".join(
|
| 15 |
f'- "{t.name}": {t.description}' for t in ALL_TOOLS
|
| 16 |
)
|
| 17 |
-
router_prompt = f"""You are a query router
|
| 18 |
|
| 19 |
-
|
| 20 |
-
{tool_descriptions}
|
| 21 |
|
| 22 |
-
|
| 23 |
-
|
|
|
|
|
|
|
| 24 |
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
β’ "general" β for everything else (chit-chat, opinions, open-ended questions)
|
| 29 |
|
| 30 |
-
|
| 31 |
-
{{"route": "<tool|rag|general>", "reason": "<one sentence why>"}}
|
| 32 |
|
| 33 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 34 |
|
| 35 |
try:
|
| 36 |
response = llm.invoke([HumanMessage(content=router_prompt)])
|
|
|
|
| 14 |
tool_descriptions = "\n".join(
|
| 15 |
f'- "{t.name}": {t.description}' for t in ALL_TOOLS
|
| 16 |
)
|
| 17 |
+
router_prompt = f"""You are a query router. Your ONLY job is to pick the correct route.
|
| 18 |
|
| 19 |
+
ROUTE RULES β follow strictly in this order:
|
|
|
|
| 20 |
|
| 21 |
+
1. "tool" β the query needs LIVE or REAL-TIME data that only a tool can provide.
|
| 22 |
+
Use this if the query mentions: weather, temperature, forecast, calculate, math, arithmetic.
|
| 23 |
+
Available tools:
|
| 24 |
+
{tool_descriptions}
|
| 25 |
|
| 26 |
+
2. "rag" β the query asks about AI/ML concepts that exist in the knowledge base.
|
| 27 |
+
RAG topics: LangGraph, LangChain, RAG, Guardrails, HITL, Memory, Conditional routing.
|
| 28 |
+
Do NOT use rag for weather or calculations β those always go to tool.
|
|
|
|
| 29 |
|
| 30 |
+
3. "general" β everything else (greetings, opinions, open-ended questions).
|
|
|
|
| 31 |
|
| 32 |
+
EXAMPLES:
|
| 33 |
+
"What is the weather in Mumbai?" β tool (needs live weather data)
|
| 34 |
+
"Calculate 25 * 48" β tool (needs calculator)
|
| 35 |
+
"What is LangGraph?" β rag (AI concept in knowledge base)
|
| 36 |
+
"Tell me a joke" β general
|
| 37 |
+
|
| 38 |
+
Respond ONLY with valid JSON, no markdown:
|
| 39 |
+
{{"route": "<tool|rag|general>", "reason": "<one sentence why>"}}
|
| 40 |
+
|
| 41 |
+
User query: {state["query"]}"""
|
| 42 |
|
| 43 |
try:
|
| 44 |
response = llm.invoke([HumanMessage(content=router_prompt)])
|