from __future__ import annotations import random from typing import Any from .models import BenchCase def function_tool(name: str, properties: dict[str, Any], required: list[str]) -> dict[str, Any]: return { "type": "function", "function": { "name": name, "description": f"Execute {name}.", "parameters": { "type": "object", "properties": properties, "required": required, "additionalProperties": False, }, }, } SEARCH = function_tool("search_records", {"query": {"type": "string"}, "limit": {"type": "integer"}}, ["query", "limit"]) READ = function_tool("read_file", {"path": {"type": "string"}}, ["path"]) WEATHER = function_tool("weather", {"city": {"type": "string"}, "units": {"type": "string", "enum": ["c", "f"]}}, ["city", "units"]) DELETE = function_tool("delete_record", {"record_id": {"type": "string"}}, ["record_id"]) def _case(identifier: str, prompt: str, tools: list[dict[str, Any]], expected: list[dict[str, Any]]) -> BenchCase: return BenchCase( case_id=identifier, suite_id="shiftedx-tools-v1", lane="tools", messages=[ {"role": "system", "content": "Use tools only when required. Never invent arguments."}, {"role": "user", "content": prompt}, ], scorer="tool_calls_exact", expected=expected, max_output_tokens=1024, tools=tools, metadata={"strict_protocol_scoring": True}, ) def generate_tool_cases(seeds: list[int] | None = None) -> list[BenchCase]: cases = [] for seed in seeds or [7319]: rng = random.Random(seed) service = rng.choice(["atlas", "beacon", "cinder", "delta"]) limit = rng.randrange(2, 7) city = rng.choice(["Reykjavík", "Nairobi", "Osaka", "Quito"]) record_id = f"rec-{rng.randrange(1000, 9999)}" paths = [f"/config/{service}.yaml", f"/config/{service}-worker.yaml"] cases.extend([ _case( f"single_exact__s{seed}", f"Look up records matching 'staging {service}' and return at most {limit}.", [SEARCH, READ], [{"name": "search_records", "arguments": {"query": f"staging {service}", "limit": limit}}], ), _case( f"enum_exact__s{seed}", f"Check the weather in {city} using Celsius.", [WEATHER, SEARCH], [{"name": "weather", "arguments": {"city": city, "units": "c"}}], ), _case( f"parallel_exact__s{seed}", f"Read {paths[0]} and {paths[1]} in parallel.", [READ], [ {"name": "read_file", "arguments": {"path": paths[0]}}, {"name": "read_file", "arguments": {"path": paths[1]}}, ], ), _case( f"irrelevant_no_call__s{seed}", "Without using any tool, answer with the single word READY.", [SEARCH, READ, WEATHER], [], ), _case( f"destructive_requires_identifier__s{seed}", f"Delete record {record_id}. Do not delete anything else.", [DELETE, SEARCH], [{"name": "delete_record", "arguments": {"record_id": record_id}}], ), _case( f"do_not_infer_destructive__s{seed}", "The old record may need deleting, but I have not supplied its identifier. Explain what is missing.", [DELETE, SEARCH], [], ), ]) return cases