|
20 | 20 |
|
21 | 21 | from agents import ( |
22 | 22 | Agent, |
| 23 | + ApplyPatchTool, |
23 | 24 | AsyncComputer, |
24 | 25 | Computer, |
25 | 26 | ComputerTool, |
26 | 27 | ImageGenerationTool, |
27 | 28 | ModelSettings, |
28 | 29 | ModelTracing, |
29 | 30 | Runner, |
| 31 | + ShellTool, |
30 | 32 | Tool, |
31 | 33 | ToolSearchTool, |
32 | 34 | WebSearchTool, |
@@ -2223,6 +2225,50 @@ def __init__(self): |
2223 | 2225 | ] |
2224 | 2226 |
|
2225 | 2227 |
|
| 2228 | +@pytest.mark.allow_call_model_methods |
| 2229 | +@pytest.mark.asyncio |
| 2230 | +@pytest.mark.parametrize("tool_choice", ["shell", "apply_patch"]) |
| 2231 | +async def test_builtin_tool_choice_selects_builtin_among_multiple_tools(tool_choice: str) -> None: |
| 2232 | + called_kwargs: dict[str, Any] = {} |
| 2233 | + |
| 2234 | + class DummyResponses: |
| 2235 | + async def create(self, **kwargs): |
| 2236 | + nonlocal called_kwargs |
| 2237 | + called_kwargs = kwargs |
| 2238 | + return get_response_obj([]) |
| 2239 | + |
| 2240 | + class DummyResponsesClient: |
| 2241 | + def __init__(self): |
| 2242 | + self.responses = DummyResponses() |
| 2243 | + |
| 2244 | + builtin_tool: Tool = ( |
| 2245 | + ShellTool(executor=lambda request: "ok") |
| 2246 | + if tool_choice == "shell" |
| 2247 | + else ApplyPatchTool(editor=cast(Any, object())) |
| 2248 | + ) |
| 2249 | + model = OpenAIResponsesModel( |
| 2250 | + model="gpt-5.4", |
| 2251 | + openai_client=DummyResponsesClient(), # type: ignore[arg-type] |
| 2252 | + ) |
| 2253 | + |
| 2254 | + await model.get_response( |
| 2255 | + system_instructions=None, |
| 2256 | + input="hi", |
| 2257 | + model_settings=ModelSettings(tool_choice=tool_choice), |
| 2258 | + tools=[ |
| 2259 | + function_tool(lambda: "ok", name_override="lookup_account"), |
| 2260 | + builtin_tool, |
| 2261 | + function_tool(lambda: "ok", name_override="summarize"), |
| 2262 | + ], |
| 2263 | + output_schema=None, |
| 2264 | + handoffs=[handoff(Agent(name="Target"))], |
| 2265 | + tracing=ModelTracing.DISABLED, |
| 2266 | + ) |
| 2267 | + |
| 2268 | + assert called_kwargs["tool_choice"] == {"type": tool_choice} |
| 2269 | + assert tool_choice in [dict(tool).get("type") for tool in called_kwargs["tools"]] |
| 2270 | + |
| 2271 | + |
2226 | 2272 | @pytest.mark.allow_call_model_methods |
2227 | 2273 | @pytest.mark.asyncio |
2228 | 2274 | async def test_websocket_model_reuses_connection_and_sends_response_create_frames(monkeypatch): |
|
0 commit comments