{"record":{"id":"1f40f62310d508b7","repo":"langchain-ai/deepagents","slug":"could-not-import-extension-source-path","errorCode":null,"errorMessage":"Could not import extension {source.path}","messagePattern":"Could not import extension (.+?)","errorType":"exception","errorClass":"ExtensionError","httpStatus":null,"severity":"error","filePath":"libs/code/deepagents_code/extensions/loader.py","lineNumber":40,"sourceCode":"def _extension_module_name(path: Path) -> str:\n    digest = hashlib.sha256(str(path.resolve()).encode()).hexdigest()[:16]\n    return f\"deepagents_code_extension_{digest}\"\n\n\ndef _import_factory(\n    source: SourceInfo,\n) -> tuple[str, Callable[[ExtensionAPI], Awaitable[None]]]:\n    name = _extension_module_name(source.path)\n    spec = importlib.util.spec_from_file_location(\n        name,\n        source.path,\n        submodule_search_locations=[str(source.path.parent)]\n        if source.is_package\n        else None,\n    )\n    if spec is None or spec.loader is None:\n        msg = f\"Could not import extension {source.path}\"\n        raise ExtensionError(msg)\n    module = importlib.util.module_from_spec(spec)\n    sys.modules[name] = module\n    try:\n        spec.loader.exec_module(module)\n    except (KeyboardInterrupt, SystemExit, Exception) as exc:\n        sys.modules.pop(name, None)\n        if isinstance(exc, KeyboardInterrupt):\n            raise\n        msg = (\n            f\"Extension import in {source.path} attempted to exit: {exc}\"\n            if isinstance(exc, SystemExit)\n            else f\"Failed to import {source.path}: {exc}\"\n        )\n        raise ExtensionError(msg) from exc\n    factory = getattr(module, \"extension\", None)\n    if not callable(factory):\n        sys.modules.pop(name, None)\n        msg = f\"{source.path} does not define a callable 'extension' factory\"","sourceCodeStart":22,"sourceCodeEnd":58,"githubUrl":"https://github.com/langchain-ai/deepagents/blob/a1af029e6e73cb17c36bff823d227747b28e91e1/libs/code/deepagents_code/extensions/loader.py#L22-L58","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","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"],"exampleFix":"// before\n~/.deepagents/extensions/old_name.py   # deleted\n\n// after\nmv new_name.py ~/.deepagents/extensions/old_name.py  # or update config to new path","handlingStrategy":"validation","validationCode":"from pathlib import Path\n\ndef extension_file_loadable(path: str | Path) -> bool:\n    p = Path(path)\n    return p.is_file() and p.suffix == \".py\" and p.stat().st_size > 0 and os.access(p, os.R_OK)","typeGuard":null,"tryCatchPattern":"try:\n    load_extension(source)\nexcept ExtensionError as exc:\n    logger.error(\"cannot load extension at %s: %s\", source.path, exc)","preventionTips":["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"],"tags":["extensions","loader","import","file-not-found"],"backgroundTag":"module-import-failed","analyzedSha":"a1af029e6e73cb17c36bff823d227747b28e91e1","analyzedAt":"2026-08-29T11:43:24.718Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}