Skip to content

Remove module-scope langchain imports so the package imports without the langgraph extra #428

Description

@jeremymanning

Verified on main today.

Evidence

src/orchestrator/tools/auto_debugger.py:29:from langchain.tools import BaseTool
src/orchestrator/control_systems/research_control_system.py:516:from langchain.agents import create_react_agent
src/orchestrator/control_systems/research_control_system.py:517:from langchain.tools import Tool
src/orchestrator/control_systems/research_control_system.py:557:from langchain.agents import initialize_agent, AgentType
src/orchestrator/control_systems/research_control_system.py:558:from langchain.tools import DuckDuckGoSearchRun, WikipediaQueryRun

Impact

langchain is behind the [langgraph] extra, not a core dependency. Any import path reaching these modules fails outright without that extra, which defeats the lazy-import work that got import orchestrator down to ~5 ms with zero heavy modules.

auto_debugger.py is the harder case: it subclasses BaseTool, so it cannot be made lazy by moving the import into a function — the class body needs the symbol at definition time.

Proposed fix

  • research_control_system.py: move the imports into the functions that use them. Mechanical.
  • auto_debugger.py: needs restructuring — either invert the dependency (compose rather than subclass BaseTool, adapting at the boundary), or move the whole module behind the extra and register it conditionally.

Recommend composition: subclassing a third-party type to satisfy an optional integration is what created the coupling.

Acceptance criteria

  • grep -rn "^from langchain\|^import langchain" src/orchestrator/ returns nothing
  • In a venv without the [langgraph] extra, importing every module in orchestrator.__all__ succeeds

Metadata

Metadata

Assignees

No one assigned

    Labels

    architectureRelated to toolbox design/architecturebugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions