~95% on SimpleQA (e.g. Qwen3.6-27B on a 3090). Supports all local and cloud LLMs (llama.cpp, Ollama, Google, ...). 10+ search engines - arXiv, PubMed, your private documents. Everything Local & Encrypted.
Python academiaanthropicarxivbravedeep-researchencryptionhome-automationhomeserverlocallocal-deep-researchlocal-llmmistralollamaopenaipubmedresearchresearch-toolretrieval-augmented-generationsearxngself-hosted
fix(langgraph): report preserved citation markers (#5393)
Ziyang Guocdda663cb5e0
diff --git a/changelog.d/5297.bugfix.md b/changelog.d/5297.bugfix.mdnew file mode 100644index 0000000000..71c3698533--- /dev/null+++ b/changelog.d/5297.bugfix.md@@ -0,0 +1 @@+Report whether a skipped LangGraph citation pass preserved existing inline citation markers instead of always warning that the answer has none.diff --git a/src/local_deep_research/advanced_search_system/strategies/langgraph_agent_strategy.py b/src/local_deep_research/advanced_search_system/strategies/langgraph_agent_strategy.pyindex 9863e2c474..0c085542b3 100644--- a/src/local_deep_research/advanced_search_system/strategies/langgraph_agent_strategy.py+++ b/src/local_deep_research/advanced_search_system/strategies/langgraph_agent_strategy.py@@ -1898,25 +1898,37 @@ class LangGraphAgentStrategy(BaseSearchStrategy):# from previously-written sections without running new searches,# leaving the per-call collector empty. The citation pass below# is then skipped and the section is saved as raw agent prose- # with no inline [N] markers even though ## Sources renders the- # full accumulated bibliography (#4969). Running the pass against- # all_links_of_system instead is NOT safe as-is: the widened- # prompt overflows default local-model context windows, the- # rewrite has no structure-preservation guarantees, and the- # empty-collector condition is also reachable from chat- # follow-ups. Until that is redesigned, make the skip loud so- # affected runs are diagnosable from the server log.+ # even though ## Sources renders the full accumulated bibliography+ # (#4969). Running the pass against all_links_of_system instead is+ # NOT safe as-is: the widened prompt overflows default local-model+ # context windows, the rewrite has no structure-preservation+ # guarantees, and the empty-collector condition is also reachable+ # from chat follow-ups. Until that is redesigned, make the skip+ # loud and report whether the raw answer already contains markers.if (not all_search_resultsand self.all_links_of_systemand final_answer != NO_RESULTS_MESSAGE):- logger.warning(- f"Citation pass skipped: no new sources collected in this "- f"call although {len(self.all_links_of_system)} are "- f"accumulated — this answer will have no inline [N] "- f"citations (#4969, query '{query[:80]}')"+ existing_markers = re.findall(+ r"\[\d+(?:\s*,\s*\d+)*\]", final_answer or "")+ if existing_markers:+ logger.warning(+ f"Citation pass skipped: no new sources collected in "+ f"this call although {len(self.all_links_of_system)} "+ f"are accumulated; the raw answer already contains "+ f"{len(existing_markers)} inline [N] marker(s) and "+ f"will be preserved as-is (#4969, query "+ f"'{query[:80]}')"+ )+ else:+ logger.warning(+ f"Citation pass skipped: no new sources collected in "+ f"this call although {len(self.all_links_of_system)} "+ f"are accumulated, and the raw answer contains no "+ f"inline [N] markers (#4969, query '{query[:80]}')"+ )# Emit synthesis milestone if it is not an agent failureif final_answer != NO_RESULTS_MESSAGE:diff --git a/tests/strategies/test_langgraph_agent_strategy.py b/tests/strategies/test_langgraph_agent_strategy.pyindex 4a5fd90e55..6b4a915621 100644--- a/tests/strategies/test_langgraph_agent_strategy.py+++ b/tests/strategies/test_langgraph_agent_strategy.py@@ -2794,7 +2794,35 @@ class TestFinalizeCitationLogging:handler.analyze_followup.assert_not_called()assert result["current_knowledge"] == "Uncited raw answer."assert any(- "Citation pass skipped" in w for w in self._warnings(mock_logger)+ "raw answer contains no inline [N] markers" in warning+ for warning in self._warnings(mock_logger)+ )++ def test_empty_collector_reports_existing_markers(self):+ """A raw answer that already cites prior context must not be+ diagnosed as having no inline citations."""+ handler = MagicMock()+ links = [self._link(1, "https://a.example/x")]+ strategy = self._make_strategy(+ all_links=links, citation_handler=handler+ )++ with patch(self._LOGGER_PATH) as mock_logger:+ result = strategy._finalize(+ "q", "Prior evidence [1] remains relevant [2, 3].", 1, 0, []+ )++ handler.analyze_followup.assert_not_called()+ assert result["current_knowledge"] == (+ "Prior evidence [1] remains relevant [2, 3]."+ )+ warnings = self._warnings(mock_logger)+ assert any(+ "already contains 2 inline [N] marker(s)" in warning+ for warning in warnings+ )+ assert not any(+ "will have no inline [N]" in warning for warning in warnings)def test_no_results_sentinel_does_not_warn_about_skip(self):