OpenBMB/ChatDev · error · ValueError

Function {name} not found

Error message

Function {name} not found

What it means

FunctionManager.call_function resolves the name via get_function (which lazily loads functions) and raises ValueError when no function with that name was loaded from the functions directory. Indicates an unregistered name, not a failure inside the function itself.

Source

Thrown at utils/function_manager.py:106

        return f"{_MODULE_PREFIX}.{parts}_{unique_suffix}"

    def get_function(self, name: str) -> Optional[Callable]:
        """Get a function by name."""
        if not self._loaded:
            self.load_functions()
        return self.functions.get(name)

    def has_function(self, name: str) -> bool:
        """Check if a function exists."""
        if not self._loaded:
            self.load_functions()
        return name in self.functions

    def call_function(self, name: str, *args, **kwargs) -> Any:
        """Call a function by name with given arguments."""
        func = self.get_function(name)
        if func is None:
            raise ValueError(f"Function {name} not found")
        return func(*args, **kwargs)

    def list_functions(self) -> Dict[str, Callable]:
        """List all available functions."""
        if not self._loaded:
            self.load_functions()
        return self.functions.copy()

    def reload_functions(self) -> None:
        """Reload all functions from the functions directory."""
        self.functions.clear()
        self._loaded = False
        self.load_functions()


# Global function manager registry keyed by directory
_function_managers: Dict[Path, FunctionManager] = {}

View on GitHub (pinned to 4fb2db0ea9)

Solutions

  1. Verify with fm.list_functions() / fm.has_function(name) that the function is loaded
  2. Fix the name spelling/case to match the loaded registry
  3. Ensure the defining .py file doesn't start with '_' and the function is defined at module level, then call fm.refresh()
  4. Check for import errors inside the function file preventing registration

Example fix

# before
result = fm.call_function(name, *args)
# after
if not fm.has_function(name):
    raise UnknownFunction(name)
result = fm.call_function(name, *args)
Defensive patterns

Strategy: validation

Validate before calling

fm.load_functions()
if not fm.has_function(name):
    raise UnknownFunction(name)

Type guard

def is_known_function(fm, name: str) -> bool:
    fm.load_functions()
    return fm.has_function(name)

Try / catch

try:
    result = fm.call_function(name, *args)
except ValueError as e:
    if 'not found' in str(e):
        handle_unknown_tool(name)  # e.g. refresh + retry once, or reject

Prevention

When it happens

Trigger: Calling call_function('my_func') when my_func.py is missing, starts with '_', sits under __pycache__, failed to import earlier, or the function is defined but named differently; also when functions were never loaded because load_functions raised earlier.

Common situations: LLM/tool layer hallucinates or mis-cases a function name; file added but server not restarted (in-memory registry stale); function file shadowed by a module-level import error that was swallowed.

Related errors


AI-assisted analysis of OpenBMB/ChatDev@4fb2db0ea9 (2026-08-27). Data as JSON: /api/errors/4a354c960eb30598. Report an issue: GitHub.