Skip to content

Commit 3f3547a

Browse files
balogh.adam@icloud.combalogh.adam@icloud.com
authored andcommitted
rm routing logic
1 parent e9173cc commit 3f3547a

6 files changed

Lines changed: 7 additions & 124 deletions

File tree

CLAUDE.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ python3.13 -m pytest path/to/test_file.py -v
2828

2929
### Request Flow
3030
```
31-
User Query → FastAPI (/api/v2/agent/run) → Firebase Auth → Query Router (Gemini)
31+
User Query → FastAPI (/api/v2/agent/run) → Firebase Auth → Agent Selection (client-specified, defaults to analytics)
3232
3333
├→ Analytics Agent: portfolio analysis, token research, market trends
3434
└→ Investor Agent: DeFi opportunity finding, yield optimization
@@ -41,7 +41,7 @@ Agent executes tools → LLM inference → Post-process response → Return Agen
4141
- **agent/**: Agent orchestration - `agent_executors.py` creates LangGraph ReAct agents, `tools.py` defines agent tools, `prompts.py` loads Jinja2 templates
4242
- **server/**: FastAPI app in `fastapi_server.py`, auth, validation, activity tracking
4343
- **onchain/**: Blockchain data layer - `pools/` for DeFi protocol abstraction, `tokens/` for metadata, `portfolio/` for wallet analysis, `analytics/` for metrics
44-
- **templates/**: Jinja2 prompt templates for agents (`analyst_agent.jinja2`, `investor_agent.jinja2`, `router.jinja2`)
44+
- **templates/**: Jinja2 prompt templates for agents (`analyst_agent.jinja2`, `investor_agent.jinja2`)
4545
- **api/api_types.py**: All Pydantic models (Token, Pool, Portfolio, Message types)
4646

4747
### Protocol System

agent/agent_executors.py

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,6 @@
4040
GOOGLE_GEMINI_20_FLASH_MODEL = (
4141
"gemini-2.0-flash" # $0.1/M input tokens; $0.4/M output tokens
4242
)
43-
GOOGLE_GEMINI_FLASH_15_8B_MODEL = (
44-
"gemini-2.5-flash-lite" # $0.0375/M input tokens; $0.15/M output tokens
45-
)
4643
LLAMA_3_1_405B_MODEL = (
4744
"meta-llama/llama-3.1-405b-instruct" # $0.8/M input tokens; $0.8/M output tokens
4845
)
@@ -63,25 +60,11 @@
6360

6461
# Select model based on configuration
6562
SUGGESTIONS_MODEL = GOOGLE_GEMINI_20_FLASH_MODEL
66-
ROUTING_MODEL = GOOGLE_GEMINI_FLASH_15_8B_MODEL
6763
REASONING_MODEL = GOOGLE_GEMINI_20_FLASH_MODEL
6864
BASE_URL = "https://generativelanguage.googleapis.com/v1beta/"
6965
API_KEY = os.getenv("GEMINI_API_KEY")
7066

7167

72-
def create_routing_model() -> BaseChatModel:
73-
return ChatOpenAI(
74-
model=ROUTING_MODEL,
75-
temperature=0.0,
76-
max_tokens=500,
77-
api_key=config.DUMMY_X402_API_KEY,
78-
http_async_client=x402_http_client,
79-
stream_usage=True,
80-
streaming=True,
81-
base_url=config.LLM_SERVER_URL,
82-
)
83-
84-
8568
def create_suggestions_model() -> BaseChatModel:
8669
return ChatOpenAI(
8770
model=SUGGESTIONS_MODEL,

agent/prompts.py

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
investor_agent_template = env.get_template("investor_agent.jinja2")
1515
analytics_agent_template = env.get_template("analytics_agent.jinja2")
1616
suggestions_template = env.get_template("suggestions.jinja2")
17-
router_template = env.get_template("router.jinja2")
1817

1918

2019
# We ignore token holdings with a total value of less than $1
@@ -108,27 +107,3 @@ def get_analytics_prompt(
108107
return analytics_agent_prompt
109108

110109

111-
def get_router_prompt(message_history: List[Message], current_message: str) -> str:
112-
"""Get the router prompt to determine which agent should handle the request."""
113-
114-
MAX_AGENT_MESSAGE_LENGTH = 400
115-
116-
# Truncate assistant response to 400 characters, also include the message type
117-
message_history = [
118-
{
119-
"type": message.type,
120-
"message": (
121-
message.message[:MAX_AGENT_MESSAGE_LENGTH] + "..."
122-
if message.type == "assistant"
123-
and len(message.message) > MAX_AGENT_MESSAGE_LENGTH
124-
else message.message
125-
),
126-
}
127-
for message in message_history
128-
]
129-
130-
router_prompt = router_template.render(
131-
message_history=message_history,
132-
current_message=current_message,
133-
)
134-
return router_prompt

api/api_types.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ class Context(BaseModel):
123123
class AgentChatRequest(BaseModel):
124124
context: Context
125125
message: UserMessage
126-
agent: Optional[AgentType] = None
126+
agent: AgentType = AgentType.ANALYTICS
127127
captchaToken: Optional[str] = None
128128

129129

server/fastapi_server.py

Lines changed: 4 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,11 @@
3636
create_investor_executor,
3737
create_suggestions_model,
3838
create_analytics_executor,
39-
create_routing_model,
4039
)
4140
from agent.prompts import (
4241
get_investor_agent_prompt,
4342
get_suggestions_prompt,
4443
get_analytics_prompt,
45-
get_router_prompt,
4644
)
4745
from agent.tools import (
4846
create_investor_agent_toolkit,
@@ -138,7 +136,6 @@ async def shutdown_event():
138136
await cow_validator.close()
139137

140138
# Initialize agents
141-
router_model = create_routing_model()
142139
suggestions_model = create_suggestions_model()
143140
analytics_agent = create_analytics_executor(token_metadata_repo)
144141
investor_agent = create_investor_executor()
@@ -150,7 +147,6 @@ async def shutdown_event():
150147
protocol_registry.register_protocol(KaminoProtocol())
151148

152149
# Store agents in app state
153-
app.state.router_model = router_model
154150
app.state.suggestions_model = suggestions_model
155151
app.state.analytics_agent = analytics_agent
156152
app.state.investor_agent = investor_agent
@@ -320,7 +316,6 @@ async def run_agent(
320316
portfolio=portfolio,
321317
investor_agent=investor_agent,
322318
analytics_agent=analytics_agent,
323-
router_model=router_model,
324319
)
325320

326321
return (
@@ -536,49 +531,15 @@ async def handle_agent_chat_request(
536531
token_metadata_repo: TokenMetadataRepo,
537532
investor_agent: any,
538533
analytics_agent: any,
539-
router_model: ChatOpenAI,
540534
) -> AgentMessage:
541-
# If agent is explicitly specified, bypass router
542-
if request.agent is not None:
543-
if request.agent == AgentType.ANALYTICS:
544-
return await handle_analytics_chat_request(
545-
request, token_metadata_repo, portfolio, analytics_agent
546-
)
547-
elif request.agent == AgentType.INVESTOR:
548-
return await handle_investor_chat_request(
549-
request, portfolio, investor_agent, protocol_registry
550-
)
551-
else:
552-
raise ValueError(f"Invalid agent type specified: {request.agent}")
553-
554-
# Otherwise use router to determine agent
555-
router_prompt = get_router_prompt(
556-
message_history=request.context.conversationHistory[-NUM_MESSAGES_TO_KEEP:],
557-
current_message=request.message.message,
558-
)
559-
560-
router_response = await router_model.ainvoke(router_prompt)
561-
selected_agent = router_response.content.strip().lower()
562-
563-
# Extract agent type from response if it contains additional text
564-
if "yield_agent" in selected_agent:
565-
selected_agent = AgentType.YIELD
566-
elif "analytics_agent" in selected_agent:
567-
selected_agent = AgentType.ANALYTICS
568-
else:
569-
# Default to analytics agent if no clear choice
570-
selected_agent = AgentType.ANALYTICS
571-
572-
if selected_agent == AgentType.ANALYTICS:
573-
return await handle_analytics_chat_request(
574-
request, token_metadata_repo, portfolio, analytics_agent
575-
)
576-
elif selected_agent == AgentType.YIELD:
535+
if request.agent == AgentType.YIELD:
577536
return await handle_investor_chat_request(
578537
request, portfolio, investor_agent, protocol_registry
579538
)
580539
else:
581-
raise ValueError(f"Invalid agent selection from router: {selected_agent}")
540+
return await handle_analytics_chat_request(
541+
request, token_metadata_repo, portfolio, analytics_agent
542+
)
582543

583544

584545
async def handle_investor_chat_request(

templates/router.jinja2

Lines changed: 0 additions & 36 deletions
This file was deleted.

0 commit comments

Comments
 (0)