diff --git a/deeptutor/agents/loop/pipeline.py b/deeptutor/agents/loop/pipeline.py index f418ab29b..f4e2779e3 100644 --- a/deeptutor/agents/loop/pipeline.py +++ b/deeptutor/agents/loop/pipeline.py @@ -1224,15 +1224,21 @@ class AgenticLoopPipeline: loader = self._deferred_loader loaded = loader.loaded_names if loader is not None else set() notes: list[str] = list(getattr(self, "_eager_guides", [])) - from deeptutor.tools.research_tools import SCIENTIFIC_TOOL_NAMES, scientific_context + from deeptutor.modules.catalog import module_enabled - research = [n for n in SCIENTIFIC_TOOL_NAMES if n in local_deferred and n not in loaded] - if research and scientific_context(context.user_message): - notes.append( - self._t("notices.research_tools_hint").format( - tools=", ".join(f"`{name}`" for name in research) + # The research module may not be installed (a minimal install ships + # without ``deeptutor.tools.research_tools``); then there is nothing to + # point at, and the setup tools alone must not pull it in. + if module_enabled("research"): + from deeptutor.tools.research_tools import SCIENTIFIC_TOOL_NAMES, scientific_context + + research = [n for n in SCIENTIFIC_TOOL_NAMES if n in local_deferred and n not in loaded] + if research and scientific_context(context.user_message): + notes.append( + self._t("notices.research_tools_hint").format( + tools=", ".join(f"`{name}`" for name in research) + ) ) - ) from deeptutor.capabilities import all_loop_capabilities for cap in all_loop_capabilities(context): diff --git a/tests/agents/chat/test_chat_tool_surface_stability.py b/tests/agents/chat/test_chat_tool_surface_stability.py index 88d345c08..393914af2 100644 --- a/tests/agents/chat/test_chat_tool_surface_stability.py +++ b/tests/agents/chat/test_chat_tool_surface_stability.py @@ -211,3 +211,34 @@ async def test_unchanged_toggles_give_byte_identical_tools( assert "reason" not in third["names"] fourth = await chat.turn("hi again", enabled_tools=["web_search"]) assert json.dumps(fourth["tools"]) == json.dumps(third["tools"]) + + +@pytest.mark.asyncio +async def test_a_turn_without_the_research_module_never_imports_it( + _isolated_runtime: dict[str, bool], monkeypatch: pytest.MonkeyPatch +) -> None: + """A minimal install has no ``deeptutor.tools.research_tools``. + + The setup tools alone are deferred there, and building the turn's notes for + them must not reach for the research module. + """ + import sys + + from deeptutor.modules import catalog + + real_enabled = catalog.module_enabled + + def enabled(name: str, *args: Any, **kwargs: Any) -> bool: + return name != "research" and real_enabled(name, *args, **kwargs) + + monkeypatch.setattr(catalog, "module_enabled", enabled) + # ``None`` in sys.modules makes any import of the module raise ImportError. + monkeypatch.setitem(sys.modules, "deeptutor.tools.research_tools", None) + + chat = _Conversation() + first = await chat.turn("请帮我找一篇关于导数教学的论文") + assert "load_tools" in first["names"] + assert not set(SCIENTIFIC_TOOL_NAMES) & set(first["names"]) + # The setup tools are still offered on demand, the research hint is not. + assert "inspect_setup" in first["manifest"] + assert "preprint" not in first["note"]