1- """
2- Routing service implementation.
3-
4- This service manages query routing to appropriate agents using an LLM-based
5- analysis. It defaults to a small, low-cost model for routing to minimize
6- overhead while maintaining quality.
7- """
8-
91import logging
102from typing import Dict , List , Optional , Any
113from solana_agent .interfaces .services .routing import (
@@ -81,17 +73,18 @@ async def _analyze_query(self, query: str) -> Dict[str, Any]:
8173
8274 USER QUERY: { query }
8375
76+ ROUTING RULES:
77+ - Match the user query to the agent whose specialization best fits the user's intent
78+ - Return the EXACT agent name that matches best
79+
8480 INSTRUCTIONS:
85- - Look at the user query and match it to the most appropriate agent from the list above
86- - If the user mentions a specific topic or need that matches an agent's specialization, choose that agent
87- - Return the EXACT agent name (not the specialization description)
88-
89- Please determine:
90- 1. primary_agent: The exact name of the best matching agent (e.g., "onboarding", "support")
91- 2. secondary_agents: Names of other agents that might help (empty list if none)
92- 3. complexity_level: 1-5 (5 being most complex)
93- 4. topics: Key topics mentioned
94- 5. confidence: 0.0-1.0 (how confident you are in this routing decision)
81+ - primary_agent: The exact name of the best matching agent (e.g., "onboarding", "event_feedback")
82+ - secondary_agents: Other agents that might help (usually empty)
83+ - complexity_level: 1-5 (5 being most complex)
84+ - topics: Key topics mentioned
85+ - confidence: 0.0-1.0 (how confident you are in this routing decision)
86+
87+ For the query "{ query } ", which agent should handle it?
9588 """
9689
9790 try :
@@ -114,12 +107,14 @@ async def _analyze_query(self, query: str) -> Dict[str, Any]:
114107 "confidence" : analysis .confidence ,
115108 }
116109 except Exception as e :
117- logger .error (f"Error analyzing query: { e } " ) # Use logger.error
110+ logger .error (f"Error analyzing query: { e } " )
111+ logger .debug (f"Query that failed: { query } " )
112+ logger .debug (f"Available agents: { list (agents .keys ())} " )
118113 # Return default analysis on error
114+ first_agent = list (agents .keys ())[0 ] if agents else "general"
115+ logger .debug (f"Defaulting to first agent: { first_agent } " )
119116 return {
120- "primary_specialization" : list (agents .keys ())[0 ]
121- if agents
122- else "general" ,
117+ "primary_specialization" : first_agent ,
123118 "secondary_specializations" : [],
124119 "complexity_level" : 1 ,
125120 "topics" : [],
0 commit comments