feat(agent): Add LangGraph intent router PoC for multi-source retrieval (#42)#43
Open
saurabhhhcodes wants to merge 2 commits intokubeflow:mainfrom
Open
feat(agent): Add LangGraph intent router PoC for multi-source retrieval (#42)#43saurabhhhcodes wants to merge 2 commits intokubeflow:mainfrom
saurabhhhcodes wants to merge 2 commits intokubeflow:mainfrom
Conversation
…al (kubeflow#42) Introduces server/agent_router.py, a LangGraph-powered routing layer that classifies user intent and dispatches queries to the correct Milvus partition (docs / issues / platform) rather than doing a blind full-collection vector search on every request. Key design decisions: - AgentState TypedDict tracks question, intent, context, citations, error, and retries across every graph node. - Intent classification uses ChatOpenAI.with_structured_output() with a strict Pydantic schema (RouteQuery) — invalid datasource values raise a ValueError so hallucinated routes are caught at the boundary. - Self-correction loop: if a partition returns an empty result set the graph increments a retry counter and routes back to intent_router (capped at MAX_RETRIES=2) so the LLM can reconsider which partition to try next instead of replying with empty context. - Graceful partition fallback: if the named Milvus partition does not yet exist (pre-PR kubeflow#12) the node falls back to a full-collection search, keeping the code runnable on the current main branch. Resolves kubeflow#42 Co-authored-by: saurabhhhcodes <saurabhhhcodes@users.noreply.github.com> Signed-off-by: Saurabh Kumar Bajpai <saurabhbajpai03@outlook.com>
…assing) Tests cover: - RouteQuery Pydantic schema validation (valid/invalid/case-sensitive) - AgentState structure and defaults - _format_hits: dedup, empty URL skip, score formatting - route_to_partition: all intents + empty/missing intent fallback - handle_empty_retrieval: retry logic and MAX_RETRIES boundary - increment_retries: counter increment, state immutability - build_graph: compile, node presence, topology, retry→router edge Also fixes route_to_partition to handle empty-string intent (use 'or' instead of .get default, which does not fire on falsy values) Signed-off-by: Saurabh Kumar Bajpai <saurabhbajpai03@outlook.com>
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
This was referenced Feb 20, 2026
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
Resolves #42.
This PR introduces
server/agent_router.py, a focused LangGraph routing layer that classifies user intent and dispatches queries to the correct Milvus partition (docs/issues/platform) — the logical next step once PR #12 (Milvus partitions) lands.Scoped strictly to agent logic — no Terraform, no KServe manifests, no ingestion pipelines. This keeps the PR small and fast to review.
Architecture
Key Design Decisions
with_structured_output(RouteQuery)+ Pydantic strict validation — invalid partition names raiseValueErrorintent_routeron empty retrieval (capped atMAX_RETRIES)main){**state, ...overrides}— no in-place mutationTests
36 real unit tests — zero mocks, all passing locally:
Coverage:
RouteQueryvalidation,AgentStatedefaults,_format_hits,route_to_partition,handle_empty_retrieval,increment_retries, and full graph topology viabuild_graph().Next Steps (post-review)
Once the routing architecture is validated here, the follow-up PR will wire the retrieval nodes into the actual Milvus partitions from PR #12.