~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
feat: add iteration history tracking to TopicOrganizationStrategy
LearningCircuita213416212be
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.pyindex cf74f5c482..44ce1a1890 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@@ -64,6 +64,7 @@ class TopicOrganizationStrategy(BaseSearchStrategy):self.enable_refinement = enable_refinementself.max_refinement_iterations = max_refinement_iterationsself.refinement_questions = [] # Track all questions asked+ self.iteration_history = [] # Track what happened in each iterationself.generate_text = generate_text# Create a no-op citation handler to skip text generation@@ -740,6 +741,23 @@ Otherwise, respond with only the follow-up question, nothing else.# Extract topics from sourcestopics = self._extract_topics_from_sources(all_sources, query)+ # Track initial state (not included in LLM context)+ self.iteration_history.append(+ {+ "iteration": 0,+ "type": "initial",+ "question": query,+ "topics_count": len(topics),+ "sources_count": len(all_sources),+ "topics": [+ {"title": t.title, "sources": len(t.get_all_sources())}+ for t in topics+ ]+ if topics+ else [],+ }+ )+if not topics:logger.warning("Could not extract topics from sources")return {@@ -870,6 +888,26 @@ Otherwise, respond with only the follow-up question, nothing else.new_sources, query, existing_topics=relevant_topics)+ # Track this refinement iteration (not included in LLM context)+ self.iteration_history.append(+ {+ "iteration": len(self.refinement_questions),+ "type": "refinement",+ "question": refinement_question,+ "new_sources": len(new_sources),+ "total_sources": len(self.all_links_of_system),+ "topics_before": len(relevant_topics),+ "topics_after": len(updated_topics),+ "topics": [+ {+ "title": t.title,+ "sources": len(t.get_all_sources()),+ }+ for t in updated_topics+ ],+ }+ )+# Re-select lead sources after adding new sourceslogger.info("Re-evaluating lead sources for all topics")self._reselect_lead_sources(updated_topics)@@ -975,7 +1013,8 @@ Otherwise, respond with only the follow-up question, nothing else.return {# Standard fields expected by the system"findings": findings,- "iterations": source_results.get("iterations", 0),+ "iterations": source_results.get("iterations", 0)+ + len(self.refinement_questions),"questions_by_iteration": source_results.get("questions_by_iteration", {}),@@ -986,6 +1025,9 @@ Otherwise, respond with only the follow-up question, nothing else."topics": [topic.to_dict() for topic in relevant_topics],"topic_graph": self.topic_graph.to_dict(),"source_count": len(topic_sources),+ # Iteration history (not included in LLM context, just for display)+ "iteration_history": self.iteration_history,+ "refinement_questions": self.refinement_questions,}def _format_single_topic_with_sources(self, topic: Topic) -> str:@@ -1137,6 +1179,23 @@ Otherwise, respond with only the follow-up question, nothing else.total_sources = sum(len(topic.get_all_sources()) for topic in topics)lines.append(f"\n---\n**Total Sources Organized:** {total_sources}")+ # Add iteration history if we have refinements+ if self.iteration_history and len(self.iteration_history) > 1:+ lines.append("\n## Research Refinement History")+ for hist in self.iteration_history:+ if hist["type"] == "initial":+ lines.append(+ f"\n**Initial Search:** {hist['sources_count']} sources → {hist['topics_count']} topics"+ )+ else:+ lines.append(+ f'\n**Refinement {hist["iteration"]}:** "{hist["question"]}"'+ )+ lines.append(f" - Added {hist['new_sources']} new sources")+ lines.append(+ f" - Topics: {hist['topics_before']} → {hist['topics_after']}"+ )+return "\n".join(lines)def _generate_topic_based_text(