Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions packages/yugos-evals/src/yugos_evals/harnessed.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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"
Comment on lines +50 to +51

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Reset required tool choice when all tools are filtered out

When a harness request requires a tool with tool_choice="any" and offers only provider-run tools, filtering removes every tool but leaves the required choice unchanged. ModelInput.valid_request in packages/yugos/src/yugos/inference/chat.py explicitly rejects this combination with required tool choice needs tool definitions, so the request fails instead of receiving the intended tool-free answer. Normalize "any" to "none" when no tools survive, alongside the existing named-tool handling.

Useful? React with 👍 / 👎.

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):
Expand Down
23 changes: 23 additions & 0 deletions packages/yugos-evals/tests/test_harnessed.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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