OpenBMB/ChatDev · error · ValueError
python_workspace_root missing from _context
Error message
python_workspace_root missing from _context
What it means
The injected _context dict must contain a python_workspace_root entry; _require_workspace raises when it is None. The workspace root anchors all path resolution and script execution for uv tools, and it is created (mkdir -p) if the directory does not yet exist, so only a missing key fails — not a missing directory.
Source
Thrown at functions/function_calling/uv_related.py:50
preview = _trim_output_preview(stdout, stderr)
if preview:
return f"{message}. Last output: {preview}"
return message
class WorkspaceCommandContext:
"""Resolve the workspace root from the injected runtime context."""
def __init__(self, ctx: Dict[str, Any] | None):
if ctx is None:
raise ValueError("_context is required for uv tools")
self.workspace_root = self._require_workspace(ctx.get("python_workspace_root"))
self._raw_ctx = ctx
@staticmethod
def _require_workspace(raw_path: Any) -> Path:
if raw_path is None:
raise ValueError("python_workspace_root missing from _context")
path = Path(raw_path).expanduser().resolve()
path.mkdir(parents=True, exist_ok=True)
return path
def resolve_under_workspace(self, relative_path: str | Path) -> Path:
candidate = Path(relative_path)
absolute = candidate if candidate.is_absolute() else self.workspace_root / candidate
absolute = absolute.expanduser().resolve()
if self.workspace_root not in absolute.parents and absolute != self.workspace_root:
raise ValueError("script path is outside workspace root")
return absolute
def _validate_packages(packages: Sequence[str]) -> List[str]:
normalized: List[str] = []
for pkg in packages:
if not isinstance(pkg, str):
raise ValueError("package entries must be strings")View on GitHub (pinned to 4fb2db0ea9)
Solutions
- Add python_workspace_root to the _context dict, set to an absolute path under which scripts/packages should run
- Check for key-name typos against the documented context schema
- Upgrade or align the calling runtime version so it injects the expected key
Example fix
# before
ctx = {"workspace_root": "/tmp/ws"}
# after
ctx = {"python_workspace_root": "/tmp/ws"} Defensive patterns
Strategy: validation
Validate before calling
if "python_workspace_root" not in (_context or {}):
_context = {**(_context or {}), "python_workspace_root": "/abs/path/ws"}
uv_run(script="run.py", _context=_context) Type guard
def context_has_workspace_root(ctx) -> bool:
return isinstance(ctx, dict) and ctx.get("python_workspace_root") is not None Try / catch
try:
uv_run(script="run.py", _context=_context)
except ValueError as e:
if "python_workspace_root missing" in str(e):
_context["python_workspace_root"] = str(Path.cwd())
uv_run(script="run.py", _context=_context)
else:
raise Prevention
- Verify the exact context key name against the library docs
- Set python_workspace_root during workspace initialization
- Align caller/runtime versions so the key is injected
When it happens
Trigger: Calling uv_run/install_python_packages with a _context dict lacking python_workspace_root; misnamed key (e.g. workspace_root, python_workspace_dir); context built from a config where the root setting was never populated.
Common situations: Framework/runtime version mismatch where the context key was renamed or not yet set; custom tool hosts that build the context dict manually; environments where workspace initialization was skipped.
Related errors
- _context is required for uv tools
- script path is outside workspace root
- package entries must be strings
- package names cannot be empty
- unsafe characters detected in package spec {pkg}
AI-assisted analysis of OpenBMB/ChatDev@4fb2db0ea9 (2026-08-27).
Data as JSON: /api/errors/2470361dec39e3a8.
Report an issue: GitHub.