langchain-ai/deepagents · error · ModelConfigError
Could not import module '{module_path}' for provider '{provi
Error message
Could not import module '{module_path}' for provider '{provider}': {e} What it means
Raised when the module portion of a configured `class_path` cannot be imported; the ImportError is wrapped as `ModelConfigError` with the original exception chained via `from e`, preserving the root cause. A module that itself raises ImportError during import also lands here.
Source
Thrown at libs/code/deepagents_code/config.py:5386
BaseChatModel as _BaseChatModel, # Runtime import; module level is typing only
)
from deepagents_code.model_config import ModelConfigError
if ":" not in class_path:
msg = (
f"Invalid class_path '{class_path}' for provider '{provider}': "
"must be in module.path:ClassName format"
)
raise ModelConfigError(msg)
module_path, class_name = class_path.rsplit(":", 1)
try:
module = importlib.import_module(module_path)
except ImportError as e:
msg = f"Could not import module '{module_path}' for provider '{provider}': {e}"
raise ModelConfigError(msg) from e
cls = getattr(module, class_name, None)
if cls is None:
msg = (
f"Class '{class_name}' not found in module '{module_path}' "
f"for provider '{provider}'"
)
raise ModelConfigError(msg)
if not (isinstance(cls, type) and issubclass(cls, _BaseChatModel)):
msg = (
f"'{class_path}' is not a BaseChatModel subclass (got {type(cls).__name__})"
)
raise ModelConfigError(msg)
try:
return cls(model=model_name, **kwargs)
except Exception as e:View on GitHub (pinned to a1af029e6e)
Solutions
- Read the chained ImportError in the message — it names the real cause
- Install the module's package into the same environment dcode runs in (`pip install my_pkg` or `uv pip install -e ./my_pkg`)
- Fix the module path in config.toml or the missing transitive dependency
Example fix
// before (config.toml) class_path = "my_pkd.models:MyChatModel" # typo // after class_path = "my_pkg.models:MyChatModel" $ pip install -e ./my_pkg
Defensive patterns
Strategy: try-catch
Validate before calling
import importlib.util
def module_importable(module_path: str) -> bool:
try:
return importlib.util.find_spec(module_path) is not None
except (ImportError, ValueError):
return False Try / catch
from deepagents_code.model_config import ModelConfigError
try:
model = create_model(spec, class_path=class_path)
except ModelConfigError as e:
if "Could not import module" in str(e):
print(f"Install the package defining {class_path.split(':')[0]}")
raise SystemExit(1)
raise Prevention
- Install custom model packages into the same venv dcode uses
- Test `importlib.import_module(module_path)` in CI before deploying config
- Avoid renaming modules without checking config.toml references
When it happens
Trigger: `_create_from_class` calls `importlib.import_module(module_path)` which raises ImportError — the package is not installed in the active environment, the module name is misspelled, or a transitive import inside the module fails (config.py:5382-5386).
Common situations: Custom model package installed in a different virtualenv than dcode's; typo in the module path (`my_pkd.models`); a dependency of the module missing after an upgrade; editable install stale after a rename.
Related errors
- Missing dependencies for '{provider}' sandbox. {install_hint
- Class '{class_name}' not found in module '{module_path}'
- Package {package_root} is not installed
- modes can only be provided when agent is a factory
- models can only be provided when agent is a factory
AI-assisted analysis of langchain-ai/deepagents@a1af029e6e (2026-08-29).
Data as JSON: /api/errors/11da187a7f05d814.
Report an issue: GitHub.