diff --git a/packages/yugos-evals/src/yugos_evals/harnessed.py b/packages/yugos-evals/src/yugos_evals/harnessed.py index 9f76b80..3500906 100644 --- a/packages/yugos-evals/src/yugos_evals/harnessed.py +++ b/packages/yugos-evals/src/yugos_evals/harnessed.py @@ -47,8 +47,12 @@ async def portable_request(model, messages, tools, tool_choice, config): 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" + named = isinstance(tool_choice, ToolFunction) + if not local and (named or tool_choice == "any"): + # The request required a tool and none is left: it is answered without one. + tool_choice = "none" + elif named and tool_choice.name not in {tool.name for tool in local}: + tool_choice = "auto" portable = config.model_copy(update={"extra_body": None, "extra_headers": None}) return GenerateInput(messages, local, tool_choice, portable) diff --git a/packages/yugos-evals/tests/test_harnessed.py b/packages/yugos-evals/tests/test_harnessed.py index 31cc47f..2bb8cea 100644 --- a/packages/yugos-evals/tests/test_harnessed.py +++ b/packages/yugos-evals/tests/test_harnessed.py @@ -150,4 +150,13 @@ def test_a_harness_request_keeps_only_tools_that_run_in_the_sandbox(): forced = ToolFunction(name="web_search") _, tools, choice, _ = asyncio.run(portable_request(None, messages, [search], forced, plain)) assert tools == [] and choice == "none" + # So is one that required some tool: the router protocol refuses a required + # choice with no tool to choose. + filtered = asyncio.run(portable_request(None, messages, [search], "any", plain)) + assert ModelInput.from_inspect(*filtered).tool_choice == "none" + # A forced tool that is gone leaves the choice among the tools that remain. + _, tools, choice, _ = asyncio.run( + portable_request(None, messages, [shell, search], forced, plain) + ) + assert tools == [shell] and choice == "auto" assert asyncio.run(portable_request(None, messages, [shell], "auto", plain)) is None