Skip to content
Python

run: --no-web-tools keeps web_search and web_fetch out of the tool list (OPE-226)

Devika Vermaa952d5463be3
diff --git a/coworker/agent.py b/coworker/agent.py
index 3dc8833a..78920e1c 100644
--- a/coworker/agent.py
+++ b/coworker/agent.py
@@ -259,6 +259,11 @@ def build_engine(
memory_saving_enabled: Optional[Any] = None,
messages: Optional[list[dict[str, Any]]] = None,
extra_tools: Optional[list[Any]] = None,
+ # False withholds web_search and web_fetch from the registry altogether. For sealed
+ # evaluation runs and air-gapped work, where "the tool was never offered" is the
+ # property that matters: a network block only stops the call, the model still sees
+ # the tool and may spend turns on it. Default True keeps every existing caller as is.
+ web_tools: bool = True,
secrets: Optional[SecretStore] = None,
task_store: Optional[Any] = None,
wake_store: Optional[Any] = None,
@@ -433,9 +438,11 @@ def build_engine(
roots=root_list or None,
)
)
- # Web search + fetch: research tools for every agent (keyless DuckDuckGo default).
- registry.register(make_web_search_tool(secrets))
- registry.register(make_web_fetch_tool())
+ # Web search + fetch: research tools for every agent (keyless DuckDuckGo default),
+ # unless the caller withheld them (`openworker run --no-web-tools`).
+ if web_tools:
+ registry.register(make_web_search_tool(secrets))
+ registry.register(make_web_fetch_tool())
# ask_user: the universal human-in-the-loop Q&A primitive (every agent; engine-intercepted).
if question_asker is not None:
registry.register(ask_user_tool())
diff --git a/coworker/headless/runner.py b/coworker/headless/runner.py
index d69c886b..5d32873d 100644
--- a/coworker/headless/runner.py
+++ b/coworker/headless/runner.py
@@ -119,6 +119,12 @@ def parse_args(argv: Optional[list[str]] = None) -> argparse.Namespace:
p.add_argument(
"--max-iterations", type=int, default=None, help="default: OpenWorker config (150)"
)
+ p.add_argument(
+ "--no-web-tools", action="store_true",
+ help="do not offer the web_search and web_fetch tools at all. For sealed evaluation "
+ "runs and air-gapped work: a network block only refuses the call, this keeps the "
+ "tools out of the model's menu, and the record says so.",
+ )
p.add_argument(
"--provider-order",
default=None,
@@ -864,6 +870,7 @@ def _run(args: argparse.Namespace) -> int:
provider=provider,
audit_sink=audit_sink,
max_iterations=args.max_iterations,
+ web_tools=not args.no_web_tools,
# The model's saved settings (model_config.py) first; the run's own flags win.
# An isolated run reads nothing from the computer.
model_settings=_merged_model_settings(args, model),
@@ -1387,6 +1394,8 @@ def _write_records(
"auto_answer": args.attendance == "auto",
"isolated": bool(args.isolated),
"max_iterations": args.max_iterations,
+ # False = web_search / web_fetch were never in the tool list (--no-web-tools).
+ "web_tools": not args.no_web_tools,
"max_output_tokens": args.max_output_tokens,
"reasoning_effort": args.reasoning_effort,
"compaction_cap_tokens": args.compaction_cap_tokens,
@@ -1445,6 +1454,7 @@ def _write_records(
"approval_mode": args.approval_mode,
# Questions were answered by rule (--auto-answer, or no terminal to ask on).
"auto_answer": args.attendance == "auto",
+ "web_tools": not args.no_web_tools,
"reasoning_effort": effort["label"],
"reasoning_effort_detail": effort["detail"],
},
diff --git a/docs/headless.md b/docs/headless.md
index 2de97d53..61035ea1 100644
--- a/docs/headless.md
+++ b/docs/headless.md
@@ -130,6 +130,7 @@ terminal and installed by rule otherwise.
| `--isolated` | read nothing from this computer; see below |
| `--reasoning-effort` | `low` … `max`, sent to the provider; unset = provider default, recorded |
| `--max-output-tokens`, `--max-iterations`, `--timeout-seconds` | ceilings; `--timeout-seconds 0` when an outer runner enforces its own |
+| `--no-web-tools` | never offer `web_search` / `web_fetch`; for sealed evaluation runs and air-gapped work (a firewall only refuses the call, this removes the tool, and `summary.json` records `web_tools: false`) |
| `--tool-result-max-bytes` | bound each tool result (default 10,000; 0 = off); full text spilled under `out/tool-output/` |
| `--provider-order` | OpenRouter only: pin the upstream host, no fallback |
| `--trajectory-atif PATH` | also write the trajectory here |
diff --git a/tests/test_headless_run.py b/tests/test_headless_run.py
index 241ddb3d..3c2de354 100644
--- a/tests/test_headless_run.py
+++ b/tests/test_headless_run.py
@@ -504,3 +504,39 @@ def test_ask_is_the_default_and_the_engine_gets_its_own_name_for_it(tmp_path: Pa
assert parse_args([*base, "--approval-mode", "auto-approve"]).mode == "auto-approve"
with pytest.raises(SystemExit):
parse_args([*base, "--approval-mode", "plan"])
+
+
+# -- --no-web-tools ------------------------------------------------------------------------
+
+WEB_SCRIPT = [
+ {"text": "Let me look that up.", "tool_calls": [{"name": "web_fetch", "arguments": {"url": "not-a-url"}}]},
+ {"text": "And search.", "tool_calls": [{"name": "web_search", "arguments": {"query": "anything"}}]},
+ {"text": "Done.", "usage": {"input": 100, "output": 10}},
+]
+
+
+def _tool_results(out: Path) -> list[str]:
+ return [str(m.get("content")) for m in _messages(out) if m["role"] == "tool"]
+
+
+def test_no_web_tools_withholds_web_search_and_web_fetch(tmp_path: Path) -> None:
+ proc, _ws, out = _run(tmp_path, "bypass-approvals", WEB_SCRIPT, extra=["--no-web-tools"])
+ assert proc.returncode == 0, proc.stdout + proc.stderr
+ # Both calls meet the engine's unknown-tool answer: the tools were never registered.
+ results = _tool_results(out)
+ assert sum("unknown tool" in r for r in results) == 2, results
+ # The record says so, in both places a reader looks.
+ assert _summary(out)["args"]["web_tools"] is False
+ traj = json.loads((tmp_path / "logs" / "trajectory.json").read_text(encoding="utf-8"))
+ assert json.dumps(traj).count('"web_tools": false') >= 1
+
+
+def test_web_tools_are_offered_unless_withheld(tmp_path: Path) -> None:
+ # web_fetch rejects a non-URL before any network I/O, which proves the tool is present
+ # without the test reaching the internet.
+ proc, _ws, out = _run(tmp_path, "bypass-approvals", WEB_SCRIPT[:1] + WEB_SCRIPT[2:])
+ assert proc.returncode == 0, proc.stdout + proc.stderr
+ results = _tool_results(out)
+ assert not any("unknown tool" in r for r in results), results
+ assert any("http://" in r for r in results), results
+ assert _summary(out)["args"]["web_tools"] is True