Skip to content

armgit / cua

Public Imported from GitHub
0

Scale computer-use 2.0 with open-source drivers, cross-OS sandboxes, and benchmarks for training, evaluation, and data generation.

feat(cua-bench): Add support for mounting local agent/cua-bench SDK (#1140)

ddupont0a5f8980a627
diff --git a/libs/cua-bench/cua_bench/cli/commands/run.py b/libs/cua-bench/cua_bench/cli/commands/run.py
index 1cc408e492..9b04510087 100644
--- a/libs/cua-bench/cua_bench/cli/commands/run.py
+++ b/libs/cua-bench/cua_bench/cli/commands/run.py
@@ -1069,6 +1069,7 @@ async def _cmd_run_task_async(args) -> int:
output_dir=session_output_dir, # Use the session output dir
stream_agent_logs=True, # Stream logs to run.log
provider_type=provider_type, # Pass detected provider type
+ dev_paths=getattr(args, "dev_paths", None),
)
if result.success:
@@ -1090,6 +1091,18 @@ async def _cmd_run_task_async(args) -> int:
if log_file.exists():
print(f"\n{GREY}Full logs saved to: {log_file}{RESET}")
+ # Summary
+ task_name = task_path.name
+ model_name = getattr(args, "model", None) or "default"
+ print("\n")
+ if result.success:
+ print(f"Task '{task_name}' completed successfully with model '{model_name}'.")
+ else:
+ print(
+ f"Task '{task_name}' failed (exit code {result.exit_code}) with model '{model_name}'."
+ )
+ print(f"Logs and artifacts: {session_output_dir}")
+
# Update session status before cleanup
try:
final_status = "completed" if result.success else "failed"
@@ -1561,6 +1574,7 @@ async def _cmd_run_dataset_async(args) -> int:
stream_agent_logs=True, # Stream agent logs to <task_output_dir>/run.log
cleanup_before=False,
provider_type=provider_type, # Pass detected provider type
+ dev_paths=getattr(args, "dev_paths", None),
)
# Extract reward from logs if available
@@ -1662,6 +1676,19 @@ async def _cmd_run_dataset_async(args) -> int:
log_print(summary)
+ # Summary
+ model_name = getattr(args, "model", None) or "default"
+ print("\n")
+ if failed_count == 0:
+ print(
+ f"All {len(results)} tasks in '{dataset_path.name}' passed with model '{model_name}'."
+ )
+ else:
+ print(
+ f"{failed_count}/{len(results)} tasks in '{dataset_path.name}' failed with model '{model_name}'."
+ )
+ print(f"Logs and artifacts: {output_dir}")
+
return 0 if failed_count == 0 else 1
else:
diff --git a/libs/cua-bench/cua_bench/cli/main.py b/libs/cua-bench/cua_bench/cli/main.py
index 519139a78b..15a4f93559 100644
--- a/libs/cua-bench/cua_bench/cli/main.py
+++ b/libs/cua-bench/cua_bench/cli/main.py
@@ -133,6 +133,13 @@ def main():
dest="provider_type",
help="Provider type (simulated, native) - usually auto-detected from task config",
)
+ parser.add_argument(
+ "--with",
+ dest="dev_paths",
+ action="append",
+ metavar="PATH",
+ help="Mount and pip install a local package into the agent container (can be repeated)",
+ )
# cb run task <path>
run_task_parser = run_subparsers.add_parser(
diff --git a/libs/cua-bench/cua_bench/runner/task_runner.py b/libs/cua-bench/cua_bench/runner/task_runner.py
index f0333acb1f..36a8657dc1 100644
--- a/libs/cua-bench/cua_bench/runner/task_runner.py
+++ b/libs/cua-bench/cua_bench/runner/task_runner.py
@@ -210,6 +210,8 @@ class TaskRunner:
remove_images_after: bool = False,
# Provider type
provider_type: Optional[str] = None,
+ # Dev mode: list of local package paths to mount and install
+ dev_paths: Optional[List[str]] = None,
) -> TaskResult:
"""Run a task with 2-container architecture.
@@ -319,6 +321,7 @@ class TaskRunner:
oracle=oracle,
output_dir=output_dir,
is_simulated=is_simulated,
+ dev_paths=dev_paths,
)
# 3.5. Start streaming agent logs to file if requested
@@ -781,6 +784,7 @@ class TaskRunner:
oracle: bool,
output_dir: Optional[str],
is_simulated: bool = False,
+ dev_paths: Optional[List[str]] = None,
) -> ContainerInfo:
"""Start the agent container.
@@ -869,6 +873,20 @@ class TaskRunner:
if cua_bench_path.exists() and (cua_bench_path / "computers").exists():
volumes.append(f"{cua_bench_path}:/app/cua_bench:ro")
+ # --with mode: mount and pip install local packages
+ dev_install_cmd = ""
+ if dev_paths:
+ install_parts = []
+ for i, dev_path in enumerate(dev_paths):
+ abs_path = Path(dev_path).absolute()
+ container_path = f"/app/dev_{i}"
+ volumes.append(f"{abs_path}:{container_path}:ro")
+ # Copy to tmp first since pip needs a writable source dir to build
+ install_parts.append(
+ f"(cp -r {container_path} /tmp/dev_{i} && pip install /tmp/dev_{i} 2>&1 | tail -1)"
+ )
+ dev_install_cmd = " && ".join(install_parts) + " && "
+
# Build command
if agent_command:
# Custom command for Docker image agents
@@ -891,6 +909,11 @@ class TaskRunner:
if max_steps:
command.extend(["--max-steps", str(max_steps)])
+ # In --with mode, wrap command to install local packages first
+ if dev_paths and dev_install_cmd:
+ original_cmd = " ".join(command)
+ command = ["bash", "-c", f"{dev_install_cmd}{original_cmd}"]
+
# Start container (not detached - we want to wait for it)
return await start_container(
image=image,
diff --git a/libs/python/agent/agent/agent.py b/libs/python/agent/agent/agent.py
index 47fc1658f6..2d790d2ed2 100644
--- a/libs/python/agent/agent/agent.py
+++ b/libs/python/agent/agent/agent.py
@@ -67,6 +67,10 @@ def get_json(obj: Any, max_depth: int = 10) -> Any:
if seen is None:
seen = set()
+ # Handle bytes early
+ if isinstance(o, bytes):
+ return f"<bytes:{len(o)}>"
+
# Use model_dump() if available
if hasattr(o, "model_dump"):
return o.model_dump()
diff --git a/libs/python/agent/agent/loops/gemini.py b/libs/python/agent/agent/loops/gemini.py
index 73c85465b1..9df2127b2d 100644
--- a/libs/python/agent/agent/loops/gemini.py
+++ b/libs/python/agent/agent/loops/gemini.py
@@ -74,8 +74,7 @@ def _sanitize_for_json(obj: Any) -> Any:
if obj is None:
return None
if isinstance(obj, bytes):
- # Convert bytes to base64 string for JSON serialization
- return f"<bytes:{base64.b64encode(obj).decode('ascii')}>"
+ return f"<bytes:{len(obj)}>"
if isinstance(obj, (str, int, float, bool)):
return obj
# Handle enums early — just use their value