feat: add LLM-based query router for RAG, MCP search, and MCP analysis#142
Open
GovindhKishore wants to merge 4 commits intoreactome:mainfrom
Open
feat: add LLM-based query router for RAG, MCP search, and MCP analysis#142GovindhKishore wants to merge 4 commits intoreactome:mainfrom
GovindhKishore wants to merge 4 commits intoreactome:mainfrom
Conversation
…ient, mcp_tools, and query router
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.