diff --git a/packages/yugos-evals/src/yugos_evals/harnessed.py b/packages/yugos-evals/src/yugos_evals/harnessed.py index 09f6bb1..9f76b80 100644 --- a/packages/yugos-evals/src/yugos_evals/harnessed.py +++ b/packages/yugos-evals/src/yugos_evals/harnessed.py @@ -13,6 +13,7 @@ from inspect_ai import Task, task_with from inspect_ai.model import GenerateInput +from inspect_ai.tool import ToolFunction, internal_tool_type from yugos.inspect_engine.frozen import _task_builder @@ -32,15 +33,24 @@ def _check(harness: str, version: str) -> None: async def portable_request(model, messages, tools, tool_choice, config): - """Drop the provider-private headers and body fields a harness adds to its requests. + """Keep a harness's request to what any routed model can do inside the sandbox. - They carry session and cache hints for the harness's own provider; the routed - model may be any provider, and the router protocol refuses them. + Provider-private headers and body fields are dropped: they carry session and cache + hints for the harness's own provider, the routed model may be any provider, and + the router protocol refuses them. + + Tools the provider runs itself, such as web search, are dropped too. They run on + the provider's side with the network access the sandbox denies, and only for the + providers that offer them. The harness's own tools are untouched: one that needs + the network is still offered and fails as it would on a machine without it. """ - if config.extra_body is None and config.extra_headers is None: + local = [tool for tool in tools if internal_tool_type(tool) is None] + if len(local) == len(tools) and config.extra_body is None and config.extra_headers is None: return None + if isinstance(tool_choice, ToolFunction) and tool_choice.name not in {t.name for t in local}: + tool_choice = "auto" if local else "none" portable = config.model_copy(update={"extra_body": None, "extra_headers": None}) - return GenerateInput(messages, tools, tool_choice, portable) + return GenerateInput(messages, local, tool_choice, portable) def harness_agent(harness: str, version: str): diff --git a/packages/yugos-evals/tests/test_harnessed.py b/packages/yugos-evals/tests/test_harnessed.py index ea354b7..31cc47f 100644 --- a/packages/yugos-evals/tests/test_harnessed.py +++ b/packages/yugos-evals/tests/test_harnessed.py @@ -7,6 +7,7 @@ import pytest from inspect_ai.dataset import MemoryDataset, Sample from inspect_ai.model import ChatMessageUser, GenerateConfig +from inspect_ai.tool import INTERNAL_TOOL_TYPE, ToolFunction, ToolInfo from yugos.evaluation import Question from yugos.inference.chat import ModelInput @@ -128,3 +129,25 @@ def test_harness_requests_become_acceptable_to_the_router_protocol(): assert request.config.extra_body is None and request.config.extra_headers is None plain = GenerateConfig(temperature=0) assert asyncio.run(portable_request(None, messages, [], "auto", plain)) is None + + +def test_a_harness_request_keeps_only_tools_that_run_in_the_sandbox(): + # Codex CLI declares web search as a tool its provider runs; Claude Code's own + # WebSearch tool asks for one in a request of its own. A provider that offers it + # would search the live web from a sandbox that has no network. + messages = [ChatMessageUser(content="fix the bug")] + shell = ToolInfo(name="exec_command", description="Run a command in the sandbox.") + search = ToolInfo( + name="web_search", description="Search the web.", options={INTERNAL_TOOL_TYPE: "web_search"} + ) + plain = GenerateConfig(temperature=0) + + _, tools, choice, _ = asyncio.run( + portable_request(None, messages, [shell, search], "auto", plain) + ) + assert tools == [shell] and choice == "auto" + # A request that exists only to search is answered without a tool. + forced = ToolFunction(name="web_search") + _, tools, choice, _ = asyncio.run(portable_request(None, messages, [search], forced, plain)) + assert tools == [] and choice == "none" + assert asyncio.run(portable_request(None, messages, [shell], "auto", plain)) is None