langchain-ai/deepagents · error · ExtensionError
Could not import extension {source.path}
Error message
Could not import extension {source.path} What it means
Raised by _import_factory in the extension loader when importlib cannot produce a module spec/loader for the extension file at source.path. The extension module could not even be loaded, so the extension fails to install.
Source
Thrown at libs/code/deepagents_code/extensions/loader.py:40
def _extension_module_name(path: Path) -> str:
digest = hashlib.sha256(str(path.resolve()).encode()).hexdigest()[:16]
return f"deepagents_code_extension_{digest}"
def _import_factory(
source: SourceInfo,
) -> tuple[str, Callable[[ExtensionAPI], Awaitable[None]]]:
name = _extension_module_name(source.path)
spec = importlib.util.spec_from_file_location(
name,
source.path,
submodule_search_locations=[str(source.path.parent)]
if source.is_package
else None,
)
if spec is None or spec.loader is None:
msg = f"Could not import extension {source.path}"
raise ExtensionError(msg)
module = importlib.util.module_from_spec(spec)
sys.modules[name] = module
try:
spec.loader.exec_module(module)
except (KeyboardInterrupt, SystemExit, Exception) as exc:
sys.modules.pop(name, None)
if isinstance(exc, KeyboardInterrupt):
raise
msg = (
f"Extension import in {source.path} attempted to exit: {exc}"
if isinstance(exc, SystemExit)
else f"Failed to import {source.path}: {exc}"
)
raise ExtensionError(msg) from exc
factory = getattr(module, "extension", None)
if not callable(factory):
sys.modules.pop(name, None)
msg = f"{source.path} does not define a callable 'extension' factory"View on GitHub (pinned to a1af029e6e)
Solutions
- Verify the file exists at the printed path and fix or remove the stale configuration entry
- Check file permissions so the loader can read the extension file
- Ensure the path points to a real .py file (or package directory) that Python can load
- Re-add the extension from its current location
Example fix
// before ~/.deepagents/extensions/old_name.py # deleted // after mv new_name.py ~/.deepagents/extensions/old_name.py # or update config to new path
Defensive patterns
Strategy: validation
Validate before calling
from pathlib import Path
def extension_file_loadable(path: str | Path) -> bool:
p = Path(path)
return p.is_file() and p.suffix == ".py" and p.stat().st_size > 0 and os.access(p, os.R_OK) Try / catch
try:
load_extension(source)
except ExtensionError as exc:
logger.error("cannot load extension at %s: %s", source.path, exc) Prevention
- Verify extension paths in configuration exist on startup
- Keep extension files in a stable directory and update config on renames
- Check read permissions for the user running the agent
When it happens
Trigger: Loading a file-based extension whose path does not exist, was deleted/moved, has a syntax-level unreadable layout, or whose spec cannot be constructed (e.g. bad extension of the file or missing parent directory).
Common situations: Configured an extensions directory path that no longer exists; renamed extension files without updating configuration; permissions preventing module creation; pointing the loader at non-Python files.
Related errors
- Extension import in {source.path} attempted to exit: {exc}
- Failed to import {source.path}: {exc}
- Entry point {entry.name!r} does not resolve to a Python modu
- Profile module not found: {profiles_path}
- Error: Source agent '{source_agent}' not found or has no AGE
AI-assisted analysis of langchain-ai/deepagents@a1af029e6e (2026-08-29).
Data as JSON: /api/errors/1f40f62310d508b7.
Report an issue: GitHub.