Pawan Mane commited on
Commit
f3c75c2
Β·
1 Parent(s): 4cc24b5

LLM Changes

Browse files
Files changed (1) hide show
  1. 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 for an AI assistant.
18
 
19
- Available tools:
20
- {tool_descriptions}
21
 
22
- Knowledge base topics (for RAG):
23
- - LangGraph, RAG, Guardrails, HITL, Memory in AI agents, Tool calling, Conditional routing
 
 
24
 
25
- Given the user query below, decide the best route:
26
- β€’ "tool" β€” if any available tool can directly answer or act on this query
27
- β€’ "rag" β€” if the query asks for information that exists in the knowledge base
28
- β€’ "general" β€” for everything else (chit-chat, opinions, open-ended questions)
29
 
30
- Respond ONLY with valid JSON β€” no explanation, no markdown fences:
31
- {{"route": "<tool|rag|general>", "reason": "<one sentence why>"}}
32
 
33
- User query: {state["query"]}"""
 
 
 
 
 
 
 
 
 
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)])