microsoft/autogen · error · ValueError

Failed to get list of available packages

Error message

Failed to get list of available packages: {ret.output.strip()}

What it means

AzureContainerCodeExecutor.get_available_packages() runs `import pkg_resources; [d.project_name for d in pkg_resources.working_set]` inside the ACA container to enumerate installed packages; if that probe exits non-zero, the captured stdout/stderr is wrapped in ValueError. The executor container is therefore up but the Python probe failed — commonly pkg_resources (setuptools) missing in the image, an OOM/killed probe, or the container image lacking the expected Python environment.

Solutions

  1. Ensure setuptools is installed in the execution container image (RUN pip install setuptools)
  2. Use the default autogen-created container image, which includes pkg_resources
  3. Inspect ret.output in the exception to see the in-container traceback and fix the image accordingly
  4. Recreate the container pool if the image was updated but the pool still runs the old one

Example fix

# before (Dockerfile for custom execution image)
FROM python:3.12-slim
RUN pip install numpy pandas
# probe fails: no pkg_resources

# after
FROM python:3.12-slim
RUN pip install setuptools numpy pandas
Defensive patterns

Strategy: try-catch

Validate before calling

# no in-container probe can be run from the caller; validate the image instead at build time
# docker run --rm my-exec-image python -c "import pkg_resources; print('ok')"

Try / catch

try:
    await executor.execute_code(blocks, token)
except ValueError as e:
    if 'Failed to get list of available packages' in str(e):
        raise RuntimeError('execution image lacks setuptools/pkg_resources; rebuild image') from e
    raise

Prevention

When it happens

Trigger: The first function-execution call triggers _populate_available_packages -> get_available_packages; the in-container python process exits non-zero, e.g. ModuleNotFoundError: No module named 'pkg_resources' on images without setuptools, or a container that crashed mid-probe.

Common situations: Custom container images based on slim/python:3.12+ where setuptools is absent, images where the default ENTRYPOINT interferes, resource limits killing the job, or a stale pool whose image was rebuilt without build tools.

Related errors


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

Appendix: source

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

    def _construct_url(self, path: str) -> str:
        endpoint = self._pool_management_endpoint
        if not endpoint.endswith("/"):
            endpoint += "/"
        url = endpoint + f"{path}?api-version={self._AZURE_API_VER}&identifier={self._session_id}"
        return url

    async def get_available_packages(self, cancellation_token: CancellationToken) -> set[str]:
        if self._available_packages is not None:
            return self._available_packages
        avail_pkgs = """
import pkg_resources\n[d.project_name for d in pkg_resources.working_set]
"""
        ret = await self._execute_code_dont_check_setup(
            [CodeBlock(code=avail_pkgs, language="python")], cancellation_token
        )
        if ret.exit_code != 0:
            raise ValueError(f"Failed to get list of available packages: {ret.output.strip()}")
        pkgs = ret.output.strip("[]")
        pkglist = pkgs.split(",\n")
        return {pkg.strip(" '") for pkg in pkglist}

    async def _populate_available_packages(self, cancellation_token: CancellationToken) -> None:
        self._available_packages = await self.get_available_packages(cancellation_token)

    async def _setup_functions(self, cancellation_token: CancellationToken) -> None:
        if not self._func_code:
            self._func_code = build_python_functions_file(self._functions)

            # Check required function imports and packages
            lists_of_packages = [x.python_packages for x in self._functions if isinstance(x, FunctionWithRequirements)]
            # Should we also be checking the imports?

            flattened_packages = [item for sublist in lists_of_packages for item in sublist]
            required_packages = set(flattened_packages)

View on GitHub (pinned to 027ecf0a37)