Skip to content

Commit 4c26908

Browse files
danielmillerpclaude
andcommitted
Narrow ComputerTool.computer union for Responses API serialization
openai-agents 0.14 widened ComputerTool.computer to accept factory types (ComputerCreate/ComputerProvider) that don't expose environment or dimensions. Match the upstream pattern: narrow to Computer / AsyncComputer before reading those attributes, and validate that environment/dimensions are set. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 17490c4 commit 4c26908

1 file changed

Lines changed: 21 additions & 3 deletions

File tree

src/agentex/lib/core/temporal/plugins/openai_agents/models/temporal_streaming_model.py

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
CodeInterpreterTool,
2828
ImageGenerationTool,
2929
)
30+
from agents.computer import Computer, AsyncComputer
3031

3132
try:
3233
from agents.tool import ShellTool # type: ignore[attr-defined]
@@ -308,11 +309,28 @@ def _convert_tools(self, tools: list[Tool], handoffs: list[Handoff]) -> tuple[Li
308309
tool_includes.append("file_search_call.results")
309310

310311
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+
)
311329
response_tools.append({
312330
"type": "computer_use_preview",
313-
"environment": tool.computer.environment,
314-
"display_width": tool.computer.dimensions[0],
315-
"display_height": tool.computer.dimensions[1],
331+
"environment": environment,
332+
"display_width": dimensions[0],
333+
"display_height": dimensions[1],
316334
})
317335

318336
elif isinstance(tool, HostedMCPTool):

0 commit comments

Comments
 (0)