microsoft/autogen · error · ValueError

Functions failed to load: {exec_result.output.strip()}

Error message

Functions failed to load: {exec_result.output.strip()}

What it means

Thrown by AzureContainerCodeExecutor._setup_functions when the generated functions module (built from the `functions` passed to the constructor) fails to execute inside the Azure container with a non-zero exit code. The executor pre-executes the function file to surface syntax errors, bad imports, or missing dependencies before the first real code block runs. The full stdout/stderr of that failed execution is embedded in the message.

Source

Thrown at python/packages/autogen-ext/src/autogen_ext/code_executors/azure/_azure_container_code_executor.py:261

            if self._available_packages is None:
                await self._populate_available_packages(cancellation_token)

            if self._available_packages is not None:
                missing_pkgs = set(required_packages - self._available_packages)
                if len(missing_pkgs) > 0:
                    raise ValueError(f"Packages unavailable in environment: {missing_pkgs}")

        func_file = self.work_dir / f"{self._functions_module}.py"
        func_file.write_text(self._func_code)

        # Attempt to load the function file to check for syntax errors, imports etc.
        exec_result = await self._execute_code_dont_check_setup(
            [CodeBlock(code=self._func_code, language="python")], cancellation_token
        )

        if exec_result.exit_code != 0:
            raise ValueError(f"Functions failed to load: {exec_result.output.strip()}")

        self._setup_functions_complete = True

    async def _setup_cwd(self, cancellation_token: CancellationToken) -> None:
        # Change the cwd to /mnt/data to properly have access to uploaded files
        exec_result = await self._execute_code_dont_check_setup(
            [CodeBlock(code="import os; os.chdir('/mnt/data')", language="python")], cancellation_token
        )

        if exec_result.exit_code != 0:
            raise ValueError("Failed to set up Azure container working directory")
        self._setup_cwd_complete = True

    async def get_file_list(self, cancellation_token: CancellationToken) -> List[str]:
        self._ensure_access_token()
        timeout = aiohttp.ClientTimeout(total=float(self._timeout))
        headers = {
            "Authorization": f"Bearer {self._access_token}",

View on GitHub (pinned to 027ecf0a37)

Solutions

  1. Read the embedded exec_result.output: it is the actual Python traceback (SyntaxError / ImportError / ModuleNotFoundError) from the container
  2. Fix the offending function's code, or add missing imports to its `required_packages` list so the executor pip-installs them during setup
  3. Verify each function compiles locally: `python -c "import ast; ast.parse(open('functions.py').read())"` or run the module in a clean venv matching the container image
  4. If a package cannot install in the sandbox, vendor the dependency or use a custom container image that already includes it

Example fix

# before
from autogen_ext.code_executors.azure import AzureContainerCodeExecutor
executor = AzureContainerCodeExecutor(functions=[fn_that_imports_numpy])  # numpy never installed

# after
from autogen_ext.code_executors.azure import AzureContainerCodeExecutor
from autogen_core.tools import FunctionTool
executor = AzureContainerCodeExecutor(
    functions=[(numpy_fn, ["numpy"])]  # declare required_packages so setup pip-installs numpy
)
Defensive patterns

Strategy: validation

Validate before calling

import ast
from autogen_ext.code_executors.azure import AzureContainerCodeExecutor

def validate_functions(functions: list) -> None:
    for fn in functions:
        src = inspect.getsource(fn)
        ast.parse(src)  # raises SyntaxError locally before the container does
        imported = {n.split(".")[0] for node in ast.walk(ast.parse(src))
                    if isinstance(node, ast.Import) for n in node.names} \
                 | {node.module.split(".")[0] for node in ast.walk(ast.parse(src))
                    if isinstance(node, ast.ImportFrom) and node.module}
        undeclared = imported - {m for f in functions for m in getattr(f, "__required_packages__", [])} - set(sys.stdlib_module_names)
        if undeclared:
            raise ValueError(f"Declare required_packages for: {undeclared}")

Type guard

def is_loadable_function(fn: Callable) -> bool:
    try:
        ast.parse(inspect.getsource(fn))
        return True
    except SyntaxError:
        return False

Try / catch

try:
    await executor.execute_code_blocks(blocks, ct)
except ValueError as e:
    if "Functions failed to load" in str(e):
        # str(e) contains the container-side traceback; fix functions and rebuild executor
        ...

Prevention

When it happens

Trigger: Constructing AzureContainerCodeExecutor with `functions=[...]` (or functions whose imports reference packages not installed), then calling execute_code_blocks for the first time. Any Python syntax error in a function body, an import of a package missing from `required_packages`, or a package unavailable in the container image triggers it. Also re-triggered after restart() resets _setup_functions_complete=False.

Common situations: Passing plain callables that import third-party libs (numpy, pandas) without listing them in each function's required_packages; a typo/syntax error in a decorated function; a package listed but not installable in the ACA sandbox (missing_pkgs check passed via pip install but import still failed, e.g. binary wheels unavailable).

Related errors


AI-assisted analysis of microsoft/autogen@027ecf0a37 (2026-08-15). Data as JSON: /api/errors/21600079e8be8be9. Report an issue: GitHub.