diff --git a/adapters/llm/anthropic.py b/adapters/llm/anthropic.py index 4b4a2ec..38b678f 100644 --- a/adapters/llm/anthropic.py +++ b/adapters/llm/anthropic.py @@ -10,8 +10,6 @@ from __future__ import annotations import os -import anthropic - from adapters.base.llm import LLMAdapter @@ -57,6 +55,14 @@ class AnthropicAdapter(LLMAdapter): ValueError If ANTHROPIC_API_KEY is not set in the environment. """ + try: + import anthropic as _anthropic + except ModuleNotFoundError as exc: + raise ImportError( + "The 'anthropic' package is required for AnthropicAdapter. " + "Install it with: pip install anthropic" + ) from exc + self._config = config api_key = os.environ.get("ANTHROPIC_API_KEY") if not api_key: @@ -64,7 +70,7 @@ class AnthropicAdapter(LLMAdapter): "ANTHROPIC_API_KEY environment variable is not set. " "Export it before running the-agency." ) - self._client = anthropic.Anthropic(api_key=api_key) + self._client = _anthropic.Anthropic(api_key=api_key) self._models_cfg: dict = config.get("models", {}) self._default_max_tokens: int = self._models_cfg.get("default_max_tokens", 4096) self._default_temperature: float = self._models_cfg.get("default_temperature", 0) diff --git a/core/team_runner.py b/core/team_runner.py index 1f3ee67..78e3fec 100644 --- a/core/team_runner.py +++ b/core/team_runner.py @@ -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" )