{"record":{"id":"958f677165b8c3b2","repo":"microsoft/autogen","slug":"could-not-compile-and-load-function-e","errorCode":null,"errorMessage":"Could not compile and load function: {e}","messagePattern":"Could not compile and load function: (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/packages/autogen-core/src/autogen_core/tools/_function_tool.py","lineNumber":174,"sourceCode":"        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":156,"sourceCodeEnd":182,"githubUrl":"https://github.com/microsoft/autogen/blob/027ecf0a379bcc1d09956d46d12d44a3ad9cee14/python/packages/autogen-core/src/autogen_core/tools/_function_tool.py#L156-L182","documentation":"Error \"Could not compile and load function: {e}\" thrown in microsoft/autogen.","triggerScenarios":"Thrown at python/packages/autogen-core/src/autogen_core/tools/_function_tool.py:174 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Fix syntax or dependency errors in the function code"],"exampleFix":"Validate the source compiles with exec() before loading","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-15T22:17:37.221Z"}