microsoft/autogen · error · ImportError
Failed to import {import_code}: {str(e)}
Error message
Failed to import {import_code}: {str(e)} What it means
Error "Failed to import {import_code}: {str(e)}" thrown in microsoft/autogen.
Source
Thrown at python/packages/autogen-core/src/autogen_core/tools/_function_tool.py:165
"Loading a FunctionTool from config will execute code to import the provided global imports and and function code.\n"
"Only load configs from TRUSTED sources to prevent arbitrary code execution.",
UserWarning,
stacklevel=2,
)
exec_globals: dict[str, Any] = {}
# Execute imports first
for import_stmt in config.global_imports:
import_code = import_to_str(import_stmt)
try:
exec(import_code, exec_globals)
except ModuleNotFoundError as e:
raise ModuleNotFoundError(
f"Failed to import {import_code}: Module not found. Please ensure the module is installed."
) from e
except ImportError as e:
raise ImportError(f"Failed to import {import_code}: {str(e)}") from e
except Exception as e:
raise RuntimeError(f"Unexpected error while importing {import_code}: {str(e)}") from e
# Execute function code
try:
exec(config.source_code, exec_globals)
func_name = config.source_code.split("def ")[1].split("(")[0]
except Exception as e:
raise ValueError(f"Could not compile and load function: {e}") from e
# Get function and verify it's callable
func: Callable[..., Any] = exec_globals[func_name]
if not callable(func):
raise TypeError(f"Expected function but got {type(func)}")
return cls(func, name=config.name, description=config.description, global_imports=config.global_imports)
View on GitHub (pinned to 027ecf0a37)
Solutions
- Fix the import error reported in the message
Example fix
Check the module path and dependencies, then retry the import
When it happens
Trigger: Thrown at python/packages/autogen-core/src/autogen_core/tools/_function_tool.py:165 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of microsoft/autogen@027ecf0a37 (2026-08-15).
Data as JSON: /api/errors/20aa8e7247097461.
Report an issue: GitHub.