Resolve Issue #113: Agentic decision trace + Root node channel fix - #114
Merged
Merged
Conversation
…d pre-pass LLM grouping for hierarchical merging.
…er generation - Updated retrieval architecture to prioritize evidence_text as the primary output, with answer_text now deprecated and always empty. - Revised documentation and code comments to reflect the new evidence-centric approach. - Removed legacy components related to answer synthesis and streamlined retrieval processes. - Added tests for new evidence rendering and discovery selection functionalities.
…teps to return structured NavigateStepResult
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.
Closes #113
Summary
This PR implements two improvements to the agentic retrieval pipeline:
1. Navigation Decision Trace (decision_trace)
Adds a structured
decision_tracefield to the retrieval API response and MCP tool output, giving downstream agents full visibility into every significant LLM decision in the pipeline.New response field:
{ "decision_trace": [ {"phase": "kg_select", "action": "select", "selected_documents": [{"name": "doc.docx", "confidence": 1.0, "source": "kg_llm_select"}]}, {"phase": "navigate", "document": "doc.docx", "action": "NAVIGATE", "reason": "...", "selected_paths": ["四、 市场分析"]}, {"phase": "navigate", "document": "doc.docx", "action": "STOP", "reason": "...", "stop_type": "no_relevant_child"}, {"phase": "discovery_select", "document": "doc.docx", "action": "skip"} ] }Files changed:
core/types.py— AddedNavigateStepResultdataclass,decision_tracefield onAgenticResultnavigation/tools.py— ReturnsNavigateStepResultwith reason/stop_typenavigation/document.py— Collects_decision_stepsper documentorchestrator.py— Assembleskg_select+ navigation steps intodecision_trace(fixed overwrite bug: assignment replaced with.extend())workflow/types.py,step_runner.py,execution/routes.py,response_projection.py— Propagates trace through the stackapps/api/app/api/v1/routes/retrieval.py— Exposesdecision_tracein API response schemaapps/api/app/mcp/retrieval_server.py— Exposesdecision_trace+stop_reasonin MCP output2. Root Node Channel Fix
Previously, the
Rootsection (document cover page) was routed through the wrong channel:split_section_path("Root") → []→depth=0→ filtered bydepth < 1path="Root"label with no context, giving the LLM no actionable informationFix:
navigation/section_tree.py— TreatsRootas a virtual L1 node so it appears in the navigation tree with its top-level summary (document outline)orchestrator.py— Filterssection_path == "Root"rows fromdiscovery_by_doc; Root content is now accessible exclusively through hierarchical navigationResult in navigation prompt:
Backward Compatibility
All changes are 100% backward-compatible. No request parameters changed. The
decision_tracefield isnullin non-agentic mode (legacy BM25 route).Testing
E2E verified with
debug_agentic_e2e.pyagainst real DB data and live LLM calls:decision_tracecontains 5 entries:kg_select → navigate → navigate → discovery_select × 2top_summarymake lintpasses (ruff, all checks passed)