microsoft/autogen · error · ValueError

Functions failed to load: {exec_result.output}

Error message

Functions failed to load: {exec_result.output}

What it means

Docker executor counterpart of the Azure 'Functions failed to load' error: during _setup_functions, the executor writes the generated functions module into the container and executes it; a non-zero exit raises this with the execution output. It surfaces syntax errors, bad imports, and runtime errors at module level in the provided functions.

Source

Thrown at python/packages/autogen-ext/src/autogen_ext/code_executors/docker/_docker_code_executor.py:283

            packages = shlex.join(required_packages)

            result = await self._execute_code_dont_check_setup(
                [CodeBlock(code=f"python -m pip install {packages}", language="sh")], cancellation_token
            )

            if result.exit_code != 0:
                stdout = result.output
                stderr = result.output
                raise ValueError(f"Pip install failed. {stdout}, {stderr}")

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

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

        self._setup_functions_complete = True

    async def _kill_running_command(self, command: List[str]) -> None:
        if self._container is None or not self._running:
            return
        await asyncio.to_thread(self._container.exec_run, ["pkill", "-f", " ".join(command)])

    async def _execute_command(self, command: List[str], cancellation_token: CancellationToken) -> Tuple[str, int]:
        if self._container is None or not self._running:
            raise ValueError("Container is not running. Must first be started with either start or a context manager.")

        exec_task = asyncio.create_task(asyncio.to_thread(self._container.exec_run, command))
        cancellation_token.link_future(exec_task)

        # Wait for the exec task to finish.
        try:
            result = await exec_task

View on GitHub (pinned to 027ecf0a37)

Solutions

  1. Read exec_result.output in the message — it is the traceback from inside the container
  2. Declare the missing imports in the function's required_packages, or use an image that already has them
  3. For binary wheels failing on slim images, switch the image (e.g. python:3 full) or apt-install system libs into a custom image
  4. Test the generated functions module locally in a clean venv mirroring the image

Example fix

# before
executor = DockerCommandLineCodeExecutor(functions=[load_csv])  # load_csv imports pandas undeclared

# after
executor = DockerCommandLineCodeExecutor(functions=[(load_csv, ["pandas"])])
Defensive patterns

Strategy: validation

Validate before calling

import ast, sys

def check_function_imports(fn, declared: list[str]) -> list[str]:
    tree = ast.parse(inspect.getsource(fn))
    roots = set()
    for node in ast.walk(tree):
        if isinstance(node, ast.Import):
            roots |= {a.name.split(".")[0] for a in node.names}
        elif isinstance(node, ast.ImportFrom) and node.module:
            roots.add(node.module.split(".")[0])
    return sorted(roots - set(declared) - set(sys.stdlib_module_names))  # non-empty = will fail

Type guard

null

Try / catch

try:
    await executor.execute_code_blocks(blocks, ct)
except ValueError as e:
    if "Functions failed to load" in str(e):
        log.error("container traceback: %s", e)
        raise

Prevention

When it happens

Trigger: Constructing DockerCommandLineCodeExecutor(functions=[...]) and calling execute_code_blocks (setup runs lazily on first call, or after restart). Any function with a syntax error, an import of a package not listed in required_packages (or not in the image), or code with import-time side effects that fails will trigger it.

Common situations: Same as Azure: undeclared third-party imports; functions relying on host-only state (env vars, files) at import time; a package that installed but its binary import fails in the slim image (missing system libs like libgomp for numpy/opencv on python:3-slim).

Related errors


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