Skip to content

Commit ffd2fd2

Browse files
Routing upgrade (#133)
* update * wip * wip
1 parent 7b24ab9 commit ffd2fd2

File tree

4 files changed

+33
-32
lines changed

4 files changed

+33
-32
lines changed

poetry.lock

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "solana-agent"
3-
version = "31.2.5"
3+
version = "31.2.6"
44
description = "AI Agents for Solana"
55
authors = ["Bevan Hunt <bevan@bevanhunt.com>"]
66
license = "MIT"
@@ -30,7 +30,7 @@ pymongo = "4.15.0"
3030
zep-cloud = "3.4.3"
3131
instructor = "1.11.3"
3232
pinecone = { version = "7.3.0", extras = ["asyncio"] }
33-
llama-index-core = "0.14.0"
33+
llama-index-core = "0.14.1"
3434
llama-index-embeddings-openai = "0.5.1"
3535
pypdf = "6.0.0"
3636
scrubadub = "2.0.1"

solana_agent/domains/routing.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,15 @@ class QueryAnalysis(BaseModel):
1010
description="Name of the primary agent that should handle this query (must be one of the available agent names)",
1111
)
1212
secondary_agents: List[str] = Field(
13-
...,
13+
default_factory=list,
1414
description="Names of secondary agents that might be helpful (must be from the available agent names)",
1515
)
16-
complexity_level: int = Field(..., description="Complexity level (1-5)")
17-
topics: List[str] = Field(..., description="Key topics in the query")
18-
confidence: float = Field(..., description="Confidence in the analysis")
16+
complexity_level: int = Field(
17+
default=1, description="Complexity level (1-5)", ge=1, le=5
18+
)
19+
topics: List[str] = Field(
20+
default_factory=list, description="Key topics in the query"
21+
)
22+
confidence: float = Field(
23+
default=0.5, description="Confidence in the analysis", ge=0.0, le=1.0
24+
)

solana_agent/services/routing.py

Lines changed: 17 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,3 @@
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-
91
import logging
102
from typing import Dict, List, Optional, Any
113
from 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

Comments
 (0)