2727 CodeInterpreterTool ,
2828 ImageGenerationTool ,
2929)
30+ from agents .computer import Computer , AsyncComputer
31+
32+ try :
33+ from agents .tool import ShellTool # type: ignore[attr-defined]
34+ except ImportError :
35+ ShellTool = None # type: ignore[assignment,misc]
3036from agents .usage import Usage , InputTokensDetails , OutputTokensDetails # type: ignore[attr-defined]
3137from agents .model_settings import MCPToolChoice
3238from openai .types .responses import (
@@ -303,11 +309,28 @@ def _convert_tools(self, tools: list[Tool], handoffs: list[Handoff]) -> tuple[Li
303309 tool_includes .append ("file_search_call.results" )
304310
305311 elif isinstance (tool , ComputerTool ):
312+ # In newer openai-agents, tool.computer may be a factory
313+ # (ComputerCreate/ComputerProvider). Only concrete Computer
314+ # / AsyncComputer instances expose environment/dimensions.
315+ computer = tool .computer
316+ if not isinstance (computer , (Computer , AsyncComputer )):
317+ raise ValueError (
318+ "ComputerTool.computer must be a Computer or AsyncComputer "
319+ "instance for Responses API serialization; got "
320+ f"{ type (computer ).__name__ } "
321+ )
322+ environment = computer .environment
323+ dimensions = computer .dimensions
324+ if environment is None or dimensions is None :
325+ raise ValueError (
326+ "ComputerTool requires `environment` and `dimensions` on the "
327+ "Computer/AsyncComputer implementation."
328+ )
306329 response_tools .append ({
307330 "type" : "computer_use_preview" ,
308- "environment" : tool . computer . environment ,
309- "display_width" : tool . computer . dimensions [0 ],
310- "display_height" : tool . computer . dimensions [1 ],
331+ "environment" : environment ,
332+ "display_width" : dimensions [0 ],
333+ "display_height" : dimensions [1 ],
311334 })
312335
313336 elif isinstance (tool , HostedMCPTool ):
@@ -326,6 +349,13 @@ def _convert_tools(self, tools: list[Tool], handoffs: list[Handoff]) -> tuple[Li
326349 "type" : "local_shell" ,
327350 })
328351
352+ elif ShellTool is not None and isinstance (tool , ShellTool ):
353+ environment = dict (tool .environment ) if tool .environment else {"type" : "local" }
354+ response_tools .append ({
355+ "type" : "shell" ,
356+ "environment" : environment ,
357+ })
358+
329359 else :
330360 logger .warning (f"Unknown tool type: { type (tool ).__name__ } , skipping" )
331361
0 commit comments