Skip to content

~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.

fix(llm-response): handle list-form content in news, GitHub search and topic organization (#5422)

Ehsand3ca82f96f6f
diff --git a/changelog.d/+finish-list-content-migration.bugfix.md b/changelog.d/+finish-list-content-migration.bugfix.md
new file mode 100644
index 0000000000..774ec834b2
--- /dev/null
+++ b/changelog.d/+finish-list-content-migration.bugfix.md
@@ -0,0 +1 @@
+Handle list-form LLM content blocks in news analysis, GitHub query optimisation and topic organisation. Topic text synthesis raised a TypeError, the GitHub search query became the block list's repr, and the news summaries came back empty. These call sites now also strip `<think>` reasoning tags from model output, matching the sibling call already in each file.
diff --git a/src/local_deep_research/advanced_search_system/strategies/topic_organization_strategy.py b/src/local_deep_research/advanced_search_system/strategies/topic_organization_strategy.py
index 9a59c8ecbd..64a2a8e8d4 100644
--- a/src/local_deep_research/advanced_search_system/strategies/topic_organization_strategy.py
+++ b/src/local_deep_research/advanced_search_system/strategies/topic_organization_strategy.py
@@ -314,11 +314,7 @@ Response:"""
try:
response = self.model.invoke(source_prompt)
- response_text = str(
- response.content
- if hasattr(response, "content")
- else response
- ).strip()
+ response_text = get_llm_response_text(response).strip()
# Parse the compact response format
is_potential_lead = False
@@ -514,9 +510,7 @@ Response (just the number):"""
try:
response = self.model.invoke(selection_prompt)
- response_text = str(
- response.content if hasattr(response, "content") else response
- ).strip()
+ response_text = get_llm_response_text(response).strip()
# Parse the number
new_lead_idx = int(response_text)
@@ -622,11 +616,7 @@ Respond with only "yes" or "no".
try:
# Call model directly with prompt
response = self.model.invoke(relevance_prompt)
- response_text = str(
- response.content
- if hasattr(response, "content")
- else response
- )
+ response_text = get_llm_response_text(response)
# Check if response indicates relevance
if "yes" in response_text.lower().strip():
@@ -700,11 +690,7 @@ Respond with only the number.
try:
response = self.model.invoke(selection_prompt)
- response_text = str(
- response.content
- if hasattr(response, "content")
- else response
- ).strip()
+ response_text = get_llm_response_text(response).strip()
# Parse the number
new_lead_idx = int(response_text)
@@ -949,9 +935,7 @@ Otherwise, respond with only the follow-up question, nothing else.
try:
response = self.model.invoke(refinement_prompt)
- response_text = str(
- response.content if hasattr(response, "content") else response
- ).strip()
+ response_text = get_llm_response_text(response).strip()
if "none" in response_text.lower() or not response_text:
logger.info("Model determined no refinement needed")
@@ -1718,11 +1702,7 @@ RESEARCH QUESTION TO ANSWER: {query}"""
try:
topic_response = self.model.invoke(topic_prompt)
- topic_text = (
- topic_response.content
- if hasattr(topic_response, "content")
- else str(topic_response)
- )
+ topic_text = get_llm_response_text(topic_response)
# Store section for summary generation
topic_sections.append(f"{topic.title}: {topic_text}")
@@ -1766,11 +1746,7 @@ RESEARCH QUESTION TO ANSWER: {query}"""
try:
summary_response = self.model.invoke(summary_prompt)
- summary_text = (
- summary_response.content
- if hasattr(summary_response, "content")
- else str(summary_response)
- )
+ summary_text = get_llm_response_text(summary_response)
# Insert summary at the beginning
generated_texts.insert(0, summary_text)
except Exception:
diff --git a/src/local_deep_research/news/core/news_analyzer.py b/src/local_deep_research/news/core/news_analyzer.py
index 61e352d56f..3e8f767d44 100644
--- a/src/local_deep_research/news/core/news_analyzer.py
+++ b/src/local_deep_research/news/core/news_analyzer.py
@@ -203,11 +203,7 @@ THE BIG PICTURE:"""
try:
response = self.llm_client.invoke(prompt)
- content = (
- response.content
- if hasattr(response, "content")
- else str(response)
- )
+ content = get_llm_response_text(response)
return content.strip()
except Exception:
logger.exception("Error generating big picture")
@@ -252,11 +248,7 @@ WATCH FOR:
try:
response = self.llm_client.invoke(prompt)
- content = (
- response.content
- if hasattr(response, "content")
- else str(response)
- )
+ content = get_llm_response_text(response)
# Parse bullet points
lines = content.strip().split("\n")
@@ -315,11 +307,7 @@ PATTERN RECOGNITION (1-2 sentences):"""
try:
response = self.llm_client.invoke(prompt)
- content = (
- response.content
- if hasattr(response, "content")
- else str(response)
- )
+ content = get_llm_response_text(response)
return content.strip()
except Exception:
logger.exception("Error generating patterns")
diff --git a/src/local_deep_research/web_search_engines/engines/search_engine_github.py b/src/local_deep_research/web_search_engines/engines/search_engine_github.py
index cd5807458c..b948afde39 100644
--- a/src/local_deep_research/web_search_engines/engines/search_engine_github.py
+++ b/src/local_deep_research/web_search_engines/engines/search_engine_github.py
@@ -163,12 +163,7 @@ class GitHubSearchEngine(BaseSearchEngine):
try:
response = self.llm.invoke(prompt)
- # Handle different response formats (string or object with content attribute)
- if hasattr(response, "content"):
- optimized_query = str(response.content).strip()
- else:
- # Handle string responses
- optimized_query = str(response).strip()
+ optimized_query = get_llm_response_text(response).strip()
# Validate the optimized query
if optimized_query and len(optimized_query) > 0:
diff --git a/tests/advanced_search_system/test_list_content_coercion.py b/tests/advanced_search_system/test_list_content_coercion.py
index 8c3b043300..5b38157e5b 100644
--- a/tests/advanced_search_system/test_list_content_coercion.py
+++ b/tests/advanced_search_system/test_list_content_coercion.py
@@ -14,6 +14,8 @@ return the expected string.
from unittest.mock import Mock
+import pytest
+
def _list_content_response(text):
"""Build a fake LLM response with Anthropic-style list content blocks."""
@@ -269,3 +271,123 @@ class TestCandidateQueryGenerationListContent:
"first query",
"second query",
]
+
+
+class TestTopicOrganizationStrategyListContent:
+ """topic_organization_strategy.py sites (issue #4615).
+
+ The file already imported ``get_llm_response_text`` and used it at one
+ site; the seven others still read ``.content`` directly.
+ """
+
+ @pytest.fixture(autouse=True)
+ def milestone_level(self):
+ # config_logger() registers MILESTONE at app startup; these tests call
+ # the strategy directly, so register it the same way it does.
+ from loguru import logger
+
+ try:
+ logger.level("MILESTONE", no=26, color="<magenta><bold>")
+ except ValueError:
+ pass
+
+ @staticmethod
+ def _strategy(blocks, **kwargs):
+ from local_deep_research.advanced_search_system.strategies.topic_organization_strategy import (
+ TopicOrganizationStrategy,
+ )
+
+ response = Mock()
+ response.content = blocks
+ model = Mock()
+ model.invoke.return_value = response
+ return TopicOrganizationStrategy(
+ search=Mock(), model=model, citation_handler=Mock(), **kwargs
+ )
+
+ @staticmethod
+ def _source(i=1):
+ return {
+ "title": f"T{i}",
+ "link": f"https://example.com/{i}",
+ "snippet": f"S{i}",
+ }
+
+ def _topic(self, sources=2):
+ from local_deep_research.advanced_search_system.findings.topic import (
+ Topic,
+ )
+
+ topic = Topic(id="t1", title="Topic1", lead_source=self._source(1))
+ for j in range(sources - 1):
+ topic.add_supporting_source(self._source(100 + j))
+ return topic
+
+ def test_extract_topics_honours_irrelevant_marker(self):
+ # "d" marks the source irrelevant. Reading the block list raw makes
+ # response_text the list's repr, which is neither "d" nor an int, so
+ # the source was kept as a topic instead of being skipped.
+ strategy = self._strategy([{"type": "text", "text": "d"}])
+
+ topics = strategy._extract_topics_from_sources(
+ [self._source(1)], "query"
+ )
+
+ assert topics == []
+
+ def test_reselect_lead_for_single_topic_parses_index(self):
+ strategy = self._strategy([{"type": "text", "text": "1"}])
+ topic = self._topic(sources=2)
+ original_lead = topic.lead_source["title"]
+
+ changed = strategy._reselect_lead_for_single_topic(topic, [topic])
+
+ assert changed is True
+ assert topic.lead_source["title"] != original_lead
+
+ def test_reselect_lead_sources_parses_index(self):
+ strategy = self._strategy([{"type": "text", "text": "1"}])
+ topic = self._topic(sources=2)
+ original_lead = topic.lead_source["title"]
+
+ strategy._reselect_lead_sources([topic])
+
+ assert topic.lead_source["title"] != original_lead
+
+ def test_filter_topics_by_relevance_ignores_thinking_blocks(self):
+ # Extended thinking puts the model's reasoning in a separate block.
+ # The raw read stringified every block, so "yes" appearing anywhere in
+ # the reasoning kept a topic the model had actually rejected.
+ strategy = self._strategy(
+ [
+ {
+ "type": "thinking",
+ "thinking": "Could be yes, but it is off topic.",
+ },
+ {"type": "text", "text": "no"},
+ ]
+ )
+
+ assert strategy._filter_topics_by_relevance([self._topic()], "q") == []
+
+ def test_generate_refinement_question_returns_text(self):
+ strategy = self._strategy(
+ [{"type": "text", "text": "What about funding?"}],
+ enable_refinement=True,
+ )
+
+ question = strategy._generate_refinement_question(
+ [self._topic()], "query"
+ )
+
+ assert question == "What about funding?"
+
+ def test_generate_topic_based_text_does_not_raise(self):
+ # These two sites did not wrap the value in str(), so the list reached
+ # "\n".join() and raised TypeError rather than degrading.
+ strategy = self._strategy([{"type": "text", "text": "Body text."}])
+
+ text = strategy._generate_topic_based_text([self._topic()], "query")
+
+ assert "Body text." in text
+ assert "'type'" not in text and "[{" not in text
diff --git a/tests/news/test_news_analyzer_list_content.py b/tests/news/test_news_analyzer_list_content.py
new file mode 100644
index 0000000000..df502cacbc
--- /dev/null
+++ b/tests/news/test_news_analyzer_list_content.py
@@ -0,0 +1,58 @@
+"""Regression tests for issue #4615 in news_analyzer.py.
+
+The file already imported ``get_llm_response_text`` and used it when parsing
+news items; the three narrative generators still read ``response.content``
+directly and called ``.strip()`` on it. With Anthropic-style list content that
+raised AttributeError inside a broad ``except``, so each generator returned an
+empty result instead of the model's text.
+"""
+
+from unittest.mock import Mock
+
+from local_deep_research.news.core.news_analyzer import NewsAnalyzer
+
+
+NEWS_ITEMS = [
+ {
+ "headline": "Headline one",
+ "summary": "Summary one",
+ "category": "tech",
+ "impact_level": "high",
+ "topics": ["agents"],
+ }
+]
+
+
+def _analyzer(text):
+ response = Mock()
+ response.content = [{"type": "text", "text": text}]
+ analyzer = NewsAnalyzer(llm_client=Mock())
+ analyzer.llm_client.invoke.return_value = response
+ return analyzer
+
+
+def test_generate_big_picture_returns_model_text():
+ analyzer = _analyzer("The broader trend is consolidation.")
+
+ assert (
+ analyzer.generate_big_picture(NEWS_ITEMS)
+ == "The broader trend is consolidation."
+ )
+
+
+def test_generate_watch_for_splits_lines():
+ analyzer = _analyzer("- First signal\n- Second signal")
+
+ watch_for = analyzer.generate_watch_for(NEWS_ITEMS)
+
+ assert any("First signal" in entry for entry in watch_for)
+ assert any("Second signal" in entry for entry in watch_for)
+
+
+def test_generate_patterns_returns_model_text():
+ analyzer = _analyzer("Two unrelated stories share a supply chain cause.")
+
+ assert (
+ analyzer.generate_patterns(NEWS_ITEMS)
+ == "Two unrelated stories share a supply chain cause."
+ )
diff --git a/tests/web_search_engines/test_search_engine_github_list_content.py b/tests/web_search_engines/test_search_engine_github_list_content.py
new file mode 100644
index 0000000000..17092c986d
--- /dev/null
+++ b/tests/web_search_engines/test_search_engine_github_list_content.py
@@ -0,0 +1,28 @@
+"""Regression test for issue #4615 in search_engine_github.py.
+
+The file already imported ``get_llm_response_text`` and used it in the
+relevance filter; query optimisation still called ``str(response.content)``.
+On list content that produced the block list's Python repr, which was then
+sent to GitHub's search API as the query.
+"""
+
+from unittest.mock import Mock
+
+from local_deep_research.web_search_engines.engines.search_engine_github import (
+ GitHubSearchEngine,
+)
+
+
+def test_optimize_github_query_extracts_text_from_content_blocks():
+ response = Mock()
+ response.content = [
+ {"type": "text", "text": "agents language:python stars:>100"}
+ ]
+ engine = GitHubSearchEngine.__new__(GitHubSearchEngine)
+ engine.llm = Mock()
+ engine.llm.invoke.return_value = response
+
+ optimized = engine._optimize_github_query("agents")
+
+ assert optimized == "agents language:python stars:>100"
+ assert "'type'" not in optimized and "[{" not in optimized