{"record":{"id":"ba8e8ff82f179c94","repo":"microsoft/autogen","slug":"failed-to-import-import-code-module-not-found","errorCode":null,"errorMessage":"Failed to import {import_code}: Module not found. Please ensure the module is installed.","messagePattern":"Failed to import (.+?): Module not found\\. Please ensure the module is installed\\.","errorType":"exception","errorClass":"ModuleNotFoundError","httpStatus":null,"severity":"error","filePath":"python/packages/autogen-core/src/autogen_core/tools/_function_tool.py","lineNumber":161,"sourceCode":"    @classmethod\n    def _from_config(cls, config: FunctionToolConfig) -> Self:\n        warnings.warn(\n            \"\\n⚠️  SECURITY WARNING ⚠️\\n\"\n            \"Loading a FunctionTool from config will execute code to import the provided global imports and and function code.\\n\"\n            \"Only load configs from TRUSTED sources to prevent arbitrary code execution.\",\n            UserWarning,\n            stacklevel=2,\n        )\n\n        exec_globals: dict[str, Any] = {}\n\n        # Execute imports first\n        for import_stmt in config.global_imports:\n            import_code = import_to_str(import_stmt)\n            try:\n                exec(import_code, exec_globals)\n            except ModuleNotFoundError as e:\n                raise ModuleNotFoundError(\n                    f\"Failed to import {import_code}: Module not found. Please ensure the module is installed.\"\n                ) from e\n            except ImportError as e:\n                raise ImportError(f\"Failed to import {import_code}: {str(e)}\") from e\n            except Exception as e:\n                raise RuntimeError(f\"Unexpected error while importing {import_code}: {str(e)}\") from e\n\n        # Execute function code\n        try:\n            exec(config.source_code, exec_globals)\n            func_name = config.source_code.split(\"def \")[1].split(\"(\")[0]\n        except Exception as e:\n            raise ValueError(f\"Could not compile and load function: {e}\") from e\n\n        # Get function and verify it's callable\n        func: Callable[..., Any] = exec_globals[func_name]\n        if not callable(func):\n            raise TypeError(f\"Expected function but got {type(func)}\")","sourceCodeStart":143,"sourceCodeEnd":179,"githubUrl":"https://github.com/microsoft/autogen/blob/027ecf0a379bcc1d09956d46d12d44a3ad9cee14/python/packages/autogen-core/src/autogen_core/tools/_function_tool.py#L143-L179","documentation":"Error \"Failed to import {import_code}: Module not found. Please ensure the module is installed.\" thrown in microsoft/autogen.","triggerScenarios":"Thrown at python/packages/autogen-core/src/autogen_core/tools/_function_tool.py:161 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Install the missing module into the environment"],"exampleFix":"pip install <module> before loading the function tool","handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"027ecf0a379bcc1d09956d46d12d44a3ad9cee14","analyzedAt":"2026-08-15T03:38:00.719Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}