Skip to content

WRITING stage fails with ImportError: cannot import name 'get_style_files' from nanoresearch.templates #3

Open

Description

@cqyzc99

Summary

The WRITING stage fails during PDF compilation because latex_bib_figures.py imports get_style_files from nanoresearch.templates, but nanoresearch/templates/__init__.py does not define or export that symbol.

Error

ImportError: cannot import name 'get_style_files' from 'nanoresearch.templates' (D:\NanoResearch\nanoresearch\templates\__init__.py)

Stack trace

Traceback (most recent call last):
  File "D:\NanoResearch\nanoresearch\pipeline\base_orchestrator.py", line 289, in _run_stage_with_retry
    result = await agent.run(**inputs)
  File "D:\NanoResearch\nanoresearch\agents\writing\writing_agent.py", line 373, in run
    pdf_result = await self._compile_pdf(tex_path, template_format=template_format)
  File "D:\NanoResearch\nanoresearch\agents\writing\latex_assembler.py", line 129, in _compile_pdf
    self._copy_style_files(template_format)
  File "D:\NanoResearch\nanoresearch\agents\writing\latex_bib_figures.py", line 467, in _copy_style_files
    from nanoresearch.templates import get_style_files
ImportError: cannot import name 'get_style_files' from 'nanoresearch.templates' (D:\NanoResearch\nanoresearch\templates\__init__.py)

Root cause

nanoresearch/agents/writing/latex_bib_figures.py calls:

from nanoresearch.templates import get_style_files

but nanoresearch/templates/__init__.py currently only exposes get_available_formats() and get_template_path().

In the current checkout, there are also no bundled .sty, .cls, or .bst files under nanoresearch/templates/, so the helper may have been removed or never implemented while the writing pipeline still expects it.

Steps to reproduce

  1. Run a research job that reaches the WRITING stage.
  2. Let the pipeline attempt PDF compilation.
  3. The run fails when _copy_style_files() executes.

Expected behavior

The WRITING stage should either:

  • provide a get_style_files() helper in nanoresearch.templates, or
  • skip style-file copying when the selected template has no extra style resources.

Environment

  • Repo: OpenRaiser/NanoResearch
  • Local checkout commit: b7bdd0afb6d1cfb2fd460a561a8aefcba148d2cb
  • OS: Windows

Activity

  1. YujunWu03 commented on Mar 23, 2026

    @YujunWu03
    Collaborator

    Hi @cqyzc99, thanks for the detailed report!

    Root cause: get_style_files() was referenced in latex_bib_figures.py but never implemented in nanoresearch/templates/__init__.py.

    Fix: Added get_style_files(format_name) to nanoresearch/templates/__init__.py. It scans the template directory for .sty, .cls, and .bst files and returns them as a list. When no style files are bundled (which is currently the case for all templates), it returns an empty list — so _copy_style_files() becomes a no-op instead of crashing.

    def get_style_files(format_name: str) -> list[Path]:
        templates_dir = Path(__file__).parent
        template_path = templates_dir / format_name
        if not template_path.is_dir():
            return []
        style_exts = {".sty", ".cls", ".bst"}
        return sorted(
            f for f in template_path.iterdir()
            if f.is_file() and f.suffix.lower() in style_exts
        )

    Will be pushed to main shortly. Please pull latest and verify. Thanks for catching this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions