microsoft/autogen · error · ValueError
Functions failed to load: {exec_result.output}
Error message
Functions failed to load: {exec_result.output} What it means
Raised after a successful pip install during LocalCommandLineCodeExecutor setup: the generated functions module is executed once as a smoke test (_execute_code_dont_check_setup), and if that execution returns a nonzero exit code (syntax error, failing import, exception at import time), the ValueError embeds the captured output.
Source
Thrown at python/packages/autogen-ext/src/autogen_ext/code_executors/local/__init__.py:320
cancellation_token.link_future(task)
try:
proc = await task
stdout, stderr = await asyncio.wait_for(proc.communicate(), self._timeout)
except asyncio.TimeoutError as e:
raise ValueError("Pip install timed out") from e
except asyncio.CancelledError as e:
raise ValueError("Pip install was cancelled") from e
if proc.returncode is not None and proc.returncode != 0:
raise ValueError(f"Pip install failed. {stdout.decode()}, {stderr.decode()}")
# 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 execute_code_blocks(
self, code_blocks: List[CodeBlock], cancellation_token: CancellationToken
) -> CommandLineCodeResult:
"""(Experimental) Execute the code blocks and return the result.
Args:
code_blocks (List[CodeBlock]): The code blocks to execute.
cancellation_token (CancellationToken): a token to cancel the operation
Returns:
CommandLineCodeResult: The result of the code execution."""
if not self._setup_functions_complete:
await self._setup_functions(cancellation_token)
View on GitHub (pinned to 027ecf0a37)
Solutions
- Read the exec output embedded in the message - it contains the Python traceback of the failed import/exec; fix the function code accordingly.
- Make function modules import-safe: move I/O and side effects inside the function body, not at module top level.
- Ensure the dependency is importable in the interpreter the executor uses (same venv); add the missing package to the function's imports so pip installs it.
Example fix
# before
@register_function
def load_config() -> dict:
import json, os
return json.load(open(os.environ.get("CONFIG", "/etc/app/config.json"))) # fails during smoke test
# after
@register_function
def load_config(path: str) -> dict:
import json
return json.load(open(path)) Defensive patterns
Strategy: try-catch
Validate before calling
import ast
def functions_module_valid(module_src: str) -> bool:
try:
ast.parse(module_src)
return True
except SyntaxError:
return False Try / catch
try:
await executor.execute_code_blocks(blocks, token)
except ValueError as e:
if "Functions failed to load" in str(e):
log.error("function module smoke test failed:\n%s", str(e))
raise # output contains the traceback; fix the function body
raise Prevention
- Keep registered functions import-safe: no top-level I/O or env access.
- Unit-test function modules by importing them directly before registering.
- Ensure the executor's interpreter (virtual_env_context) has the function's dependencies.
When it happens
Trigger: A registered function's module has a syntax error, or its top-level/import code raises (missing optional dependency not captured by pip, file/network access at import time), so the smoke-test execution fails.
Common situations: Functions that read files or env vars at import time which do not exist in the executor's working directory, syntax errors in hand-written function bodies, imports of packages installed in a different interpreter than the executor's virtual_env_context.
Related errors
- Pip install timed out
- Pip install failed. {stdout.decode()}, {stderr.decode()}
- Invalid message type
- Could not compile function: {e}
- Packages unavailable in environment: {missing_pkgs}
AI-assisted analysis of microsoft/autogen@027ecf0a37 (2026-08-15).
Data as JSON: /api/errors/18af1f30ea0e8495.
Report an issue: GitHub.