feat: add LLM-based query router for RAG, MCP search, and MCP analysis - #142
GovindhKishore wants to merge 4 commits into
Conversation
…ient, mcp_tools, and query router
|
Closing this one, and I want to be clear about which part is the problem — because the idea is right and it is going into the design. What is right: questions genuinely do split three ways. A general pathway question, a lookup of a specific identifier, and "analyse this gene list" want different machinery, and your three-way split with the rule that What is the problem: That is a second model call on every question. Spec 001's retriever rewrite cut this pipeline from 21 model calls to 1, and adding one back per question gives up a meaningful part of that for a decision the existing classifier is already positioned to make. So the destination set you designed here is what we want; it should arrive as extra options on The other files in this PR are #137's, which is the one still open for the MCP client and tool wrappers. One thing worth carrying over whichever way this lands: the package name Thank you — the classification design here is being used, with credit. |
Summary
Adds LLM-based query routing to
ReactToMeGraphBuilderso questions are directed to the correct retrieval path before any tool calls are made.Closes #141
Context
PR #127 and #137 introduced MCP tools into the agent. Without routing, every question goes through the tool calling loop even when the vector database already has the answer. This PR adds a lightweight classification step that runs before retrieval and directs each question to the right path.
What Changed
src/mcp/query_router.py(new)create_query_router(llm)returns an asyncroute()functionrag,mcp_search, ormcp_analysisragon unexpected outputgpt-4o-mini)src/agent/profiles/react_to_me.py(modified)llm_with_search_toolsand
llm_with_analysis_tools- each bound to the relevant tool subset onlycall_modelnow calls the router first and branches accordingly:rag- existing RAG path, no MCP involvedmcp_search- LLM with search/lookup tools onlymcp_analysis- LLM withanalyze_identifiersonlyMCP_SERVER_PATHis not set, routing is skipped entirely and existingRAG behaviour is unchanged
Routing Logic
Testing
Manual testing against a running MCP server is pending.
The routing logic has been reviewed against the prompt criteria for the following question types:
ragmcp_searchmcp_analysisragfallbackNotes
gpt-4o-miniseparately from the main generation model to keepclassification cost low
bind_tools- no rebindingper message
MCP_SERVER_PATHis set - zero impact ondeployments without MCP
AI assistance was used in drafting and implementation. All changes reviewed and verified
by me.