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:
2026-03-16 01:03:17 -04:00
parent 7b1cf7315c
commit 45e3b7663e
2 changed files with 21 additions and 4 deletions

View File

@@ -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)