{"record":{"id":"fc9e714df1fd336c","repo":"microsoft/autogen","slug":"unexpected-error-while-importing-import-code-s","errorCode":null,"errorMessage":"Unexpected error while importing {import_code}: {str(e)}","messagePattern":"Unexpected error while importing (.+?): (.+?)","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"python/packages/autogen-core/src/autogen_core/tools/_function_tool.py","lineNumber":167,"sourceCode":"            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)}\")\n\n        return cls(func, name=config.name, description=config.description, global_imports=config.global_imports)\n","sourceCodeStart":149,"sourceCodeEnd":182,"githubUrl":"https://github.com/microsoft/autogen/blob/027ecf0a379bcc1d09956d46d12d44a3ad9cee14/python/packages/autogen-core/src/autogen_core/tools/_function_tool.py#L149-L182","documentation":"Error \"Unexpected error while importing {import_code}: {str(e)}\" thrown in microsoft/autogen.","triggerScenarios":"Thrown at python/packages/autogen-core/src/autogen_core/tools/_function_tool.py:167 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Review the exception details and environment"],"exampleFix":"Ensure the import path is valid and the environment has required packages","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"}