{"record":{"id":"5fa31f2dfa2c9ae3","repo":"langchain-ai/deepagents","slug":"failed-to-import-source-path-exc","errorCode":null,"errorMessage":"Failed to import {source.path}: {exc}","messagePattern":"Failed to import (.+?): (.+?)","errorType":"exception","errorClass":"ExtensionError","httpStatus":null,"severity":"error","filePath":"libs/code/deepagents_code/extensions/loader.py","lineNumber":54,"sourceCode":"        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\"\n        raise ExtensionError(msg)\n    if not inspect.iscoroutinefunction(factory):\n        sys.modules.pop(name, None)\n        msg = f\"Extension factory in {source.path} must be declared with 'async def'\"\n        raise ExtensionError(msg)\n    return name, factory\n\n\nasync def load_extension(\n    source: SourceInfo,\n    registry: ExtensionRegistry,\n    *,\n    cwd: Path,\n    mode: ExtensionMode,","sourceCodeStart":36,"sourceCodeEnd":72,"githubUrl":"https://github.com/langchain-ai/deepagents/blob/a1af029e6e73cb17c36bff823d227747b28e91e1/libs/code/deepagents_code/extensions/loader.py#L36-L72","documentation":"Raised by _import_factory when executing the extension module raises any other exception (other than KeyboardInterrupt, which is re-raised). The original exception is chained as __cause__ so the real import-time failure is visible. The message includes the failing path and the underlying error text.","triggerScenarios":"Any uncaught exception while running the extension module's top-level code: a missing third-party import, a syntax error surfacing at exec, failing module-level initialization (bad config, network call at import), etc.","commonSituations":"Extension imports a dependency that is not installed in the current environment; module-level code reads a config file that is missing; Python version incompatibility; syntax errors after an edit; network calls at import time failing.","solutions":["Read the chained __cause__ traceback for the actual root-cause error","Install the missing dependency the extension imports (check its requirements)","Fix syntax/runtime errors in the extension file; test with `python <path>` or `python -c \"import ...\"`","Remove import-time side effects (network, file access) and defer them into the extension factory","Verify the extension runs under the same Python interpreter/environment the agent uses"],"exampleFix":"// before\nimport requests  # not installed\nresp = requests.get(\"https://example.com\")  # import-time network call\n\n// after\n# do imports/side effects lazily\ndef extension(api):\n    import requests\n    resp = requests.get(\"https://example.com\")","handlingStrategy":"try-catch","validationCode":"import subprocess, sys\nresult = subprocess.run([sys.executable, \"-c\", f\"import runpy; runpy.run_path({path!r})\"], capture_output=True)\nassert result.returncode == 0, result.stderr.decode()","typeGuard":null,"tryCatchPattern":"try:\n    load_extension(source)\nexcept ExtensionError as exc:\n    logger.error(\"import of %s failed: %s\", source.path, exc.__cause__)","preventionTips":["Pin and install all extension dependencies in the agent's environment","Test `python -c \"import <extension_module>\"` in CI before shipping","Avoid import-time side effects (network, file I/O, config reads); defer to the factory","Run a smoke import of every extension in the extensions directory at startup and log failures"],"tags":["extensions","loader","import","dependency"],"backgroundTag":"module-import-failed","analyzedSha":"a1af029e6e73cb17c36bff823d227747b28e91e1","analyzedAt":"2026-08-29T11:43:24.718Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}