fix: lazy-import anthropic SDK; tolerate LLM adapter failure in dry-run mode
--dry-run was crashing with ModuleNotFoundError because: 1. adapters/llm/anthropic.py imported 'anthropic' at module level 2. TeamRunner.__init__ always built the LLM adapter regardless of dry_run flag Fixes: - Move 'import anthropic' inside AnthropicAdapter.__init__ (lazy import) so the module loads cleanly without the SDK installed - In TeamRunner.__init__, wrap _build_llm in a try/except when dry_run=True so missing adapter deps are logged as warnings, not fatal errors dry-run now works with no third-party packages installed.
This commit is contained in:
@@ -177,7 +177,18 @@ class TeamRunner:
|
||||
adapter_cfg: dict = self._config.get("adapters", {})
|
||||
runtime_cfg: dict = self._config.get("runtime", {})
|
||||
|
||||
self._llm: LLMAdapter = self._build_llm(adapter_cfg.get("llm", "anthropic"))
|
||||
if dry_run:
|
||||
# In dry-run mode the LLM adapter is never actually called, so we
|
||||
# tolerate missing dependencies (e.g. 'anthropic' SDK not installed).
|
||||
try:
|
||||
self._llm: LLMAdapter = self._build_llm(adapter_cfg.get("llm", "anthropic"))
|
||||
except (ImportError, ValueError) as exc:
|
||||
logger.warning(
|
||||
"LLM adapter unavailable in dry-run mode (%s) — continuing.", exc
|
||||
)
|
||||
self._llm = None # type: ignore[assignment]
|
||||
else:
|
||||
self._llm = self._build_llm(adapter_cfg.get("llm", "anthropic"))
|
||||
self._vcs: Optional[VCSAdapter] = self._build_optional( # type: ignore[assignment]
|
||||
_VCS_ADAPTERS, adapter_cfg.get("vcs"), "VCS"
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user