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
8 changes: 6 additions & 2 deletions packages/yugos-evals/src/yugos_evals/harnessed.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

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