~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: Handle sections without subsections in report generation
LearningCircuit40d7220a54d7
diff --git a/src/local_deep_research/report_generator.py b/src/local_deep_research/report_generator.pyindex 599073232e..dea33b9710 100644--- a/src/local_deep_research/report_generator.py+++ b/src/local_deep_research/report_generator.py@@ -108,12 +108,20 @@ class IntegratedReportGenerator:current_section = {"name": section_name, "subsections": []}structure.append(current_section)elif line.strip().startswith("-") and current_section:- # Subsection with purpose+ # Subsection with or without purposeparts = line.strip("- ").split("|")if len(parts) == 2:current_section["subsections"].append({"name": parts[0].strip(), "purpose": parts[1].strip()})+ elif len(parts) == 1 and parts[0].strip():+ # Subsection without purpose - add default+ current_section["subsections"].append(+ {+ "name": parts[0].strip(),+ "purpose": f"Provide detailed information about {parts[0].strip()}",+ }+ )return structure@@ -151,82 +159,31 @@ class IntegratedReportGenerator:logger.info(f"Processing section: {section['name']}")section_content = []- # Extract clean section name if it contains purpose after |- section_display_name = section["name"]- if "|" in section["name"] and not section["subsections"]:- section_display_name = section["name"].split("|", 1)[0].strip()-- section_content.append(f"# {section_display_name}\n")+ section_content.append(f"# {section['name']}\n")- # Check if section has subsections+ # If section has no subsections, create one from the section itselfif not section["subsections"]:- # Handle sections without subsections (like Conclusion)- # The section name itself contains the purpose after the |- section_name_for_display = section["name"]+ # Parse section name for purposeif "|" in section["name"]:- section_title, section_purpose = section["name"].split(- "|", 1- )- section_name_for_display = section_title.strip()- section_purpose = section_purpose.strip()- else:- section_purpose = f"Provide content for {section['name']}"-- # Get all other sections for context- other_sections = [- f"- {s['name']}"- for s in structure- if s["name"] != section["name"]- ]- other_sections_text = (- "\n".join(other_sections) if other_sections else "None"- )-- # Generate query for this section- section_query = (- f"Research task: Create content for section '{section_name_for_display}' in a report about '{query}'. "- f"This section's purpose: {section_purpose} "- f"\n"- f"Other sections in the report:\n{other_sections_text}\n"- f"\n"- f"Focus on providing comprehensive content for this section's specific purpose. "- f"Include unique insights, specific examples, and concrete information. "- f"Use tables to organize information where applicable. "- f"IMPORTANT: Avoid repeating information covered in other sections - focus on what makes this section unique. "- f"Build upon the previous research findings to provide a cohesive conclusion or exploration of the topic."- )-- logger.info(- f"Researching section without subsections: {section_name_for_display} with query: {section_query}"- )-- # Configure search system for focused search- original_max_iterations = self.search_system.max_iterations- self.search_system.max_iterations = 1 # Keep search focused-- # Perform search for this section- section_results = self.search_system.analyze_topic(- section_query- )-- # Restore original iterations setting- self.search_system.max_iterations = original_max_iterations-- # Add the researched content- if section_results.get("current_knowledge"):- section_content.append(section_results["current_knowledge"])+ parts = section["name"].split("|", 1)+ section["subsections"] = [+ {"name": parts[0].strip(), "purpose": parts[1].strip()}+ ]else:- section_content.append(- "*Limited information was found for this section.*\n"- )-- section_content.append("\n\n")+ # No purpose provided - use section name as subsection+ section["subsections"] = [+ {+ "name": section["name"],+ "purpose": f"Provide comprehensive content for {section['name']}",+ }+ ]# Process each subsection by directly researching itfor subsection in section["subsections"]:- # Add subsection header- section_content.append(f"## {subsection['name']}\n")- section_content.append(f"_{subsection['purpose']}_\n\n")+ # Only add subsection header if there are multiple subsections+ if len(section["subsections"]) > 1:+ section_content.append(f"## {subsection['name']}\n")+ section_content.append(f"_{subsection['purpose']}_\n\n")# Get other subsections in this section for contextother_subsections = [@@ -250,23 +207,42 @@ class IntegratedReportGenerator:"\n".join(other_sections) if other_sections else "None")- # Generate a specific search query for this subsection- # Create a more focused and directive query to avoid repetition- subsection_query = (- f"Research task: Create content for subsection '{subsection['name']}' in a report about '{query}'. "- f"This subsection's purpose: {subsection['purpose']} "- f"Part of section: '{section['name']}' "- f"\n"- f"Other sections in the report:\n{other_sections_text}\n"- f"\n"- f"Other subsections in this section will cover:\n{other_subsections_text}\n"- f"\n"- f"Focus ONLY on information specific to your subsection's purpose. "- f"Include unique details, specific examples, and concrete data. "- f"Use tables to organize information where applicable. "- f"IMPORTANT: Avoid repeating information that would logically be covered in other sections - focus on what makes this subsection unique. "- f"Previous research exists - find specific angles for this subsection."- )+ # Check if this is actually a section-level content (only one subsection, likely auto-created)+ is_section_level = len(section["subsections"]) == 1++ # Generate appropriate search query+ if is_section_level:+ # Section-level prompt - more comprehensive+ subsection_query = (+ f"Research task: Create comprehensive content for the '{subsection['name']}' section in a report about '{query}'. "+ f"Section purpose: {subsection['purpose']} "+ f"\n"+ f"Other sections in the report:\n{other_sections_text}\n"+ f"\n"+ f"This is a standalone section requiring comprehensive coverage of its topic. "+ f"Provide a thorough exploration that may include synthesis of information from previous sections where relevant. "+ f"Include unique insights, specific examples, and concrete data. "+ f"Use tables to organize information where applicable. "+ f"For conclusion sections: synthesize key findings and provide forward-looking insights. "+ f"Build upon the research findings from earlier sections to create a cohesive narrative."+ )+ else:+ # Subsection-level prompt - more focused+ subsection_query = (+ f"Research task: Create content for subsection '{subsection['name']}' in a report about '{query}'. "+ f"This subsection's purpose: {subsection['purpose']} "+ f"Part of section: '{section['name']}' "+ f"\n"+ f"Other sections in the report:\n{other_sections_text}\n"+ f"\n"+ f"Other subsections in this section will cover:\n{other_subsections_text}\n"+ f"\n"+ f"Focus ONLY on information specific to your subsection's purpose. "+ f"Include unique details, specific examples, and concrete data. "+ f"Use tables to organize information where applicable. "+ f"IMPORTANT: Avoid repeating information that would logically be covered in other sections - focus on what makes this subsection unique. "+ f"Previous research exists - find specific angles for this subsection."+ )logger.info(f"Researching subsection: {subsection['name']} with query: {subsection_query}"