Skip to content

Commit 83a0e58

Browse files
committed
fix review comments
1 parent a588bf7 commit 83a0e58

2 files changed

Lines changed: 52 additions & 5 deletions

File tree

src/agents/run_internal/tool_actions.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,10 @@ def _filter_supported_kwargs(
338338

339339
@staticmethod
340340
def _supported_keyword_arguments(method: Any) -> set[str | None]:
341-
signature = inspect.signature(method)
341+
try:
342+
signature = inspect.signature(method)
343+
except (TypeError, ValueError):
344+
return set()
342345
supported: set[str | None] = {
343346
parameter.name
344347
for parameter in signature.parameters.values()

tests/test_computer_action.py

Lines changed: 48 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,50 @@ def click(self, x: int, y: int, button: str) -> None:
397397
assert "does not accept keyword argument(s) keys" in caplog.text
398398

399399

400+
@pytest.mark.asyncio
401+
async def test_get_screenshot_drops_modifier_keys_for_non_introspectable_driver_with_warning(
402+
caplog: pytest.LogCaptureFixture,
403+
) -> None:
404+
class NonIntrospectableClick:
405+
def __init__(self, calls: list[tuple[str, tuple[Any, ...]]]) -> None:
406+
self._calls = calls
407+
408+
@property
409+
def __signature__(self) -> Any:
410+
raise ValueError("signature unavailable")
411+
412+
def __call__(self, x: int, y: int, button: str) -> None:
413+
self._calls.append(("click", (x, y, button)))
414+
415+
class NonIntrospectableDriver:
416+
def __init__(self) -> None:
417+
self.calls: list[tuple[str, tuple[Any, ...]]] = []
418+
self.click = NonIntrospectableClick(self.calls)
419+
420+
def screenshot(self) -> str:
421+
self.calls.append(("screenshot", ()))
422+
return "non_introspectable"
423+
424+
tool_call = ResponseComputerToolCall(
425+
id="c8",
426+
type="computer_call",
427+
action=_action_with_keys(
428+
ActionClick, type="click", x=2, y=5, button="left", keys=["shift"]
429+
),
430+
call_id="c8",
431+
pending_safety_checks=[],
432+
status="completed",
433+
)
434+
435+
driver = NonIntrospectableDriver()
436+
with caplog.at_level(logging.WARNING, logger="openai.agents"):
437+
screenshot_output = await ComputerAction._execute_action_and_capture(driver, tool_call)
438+
439+
assert driver.calls == [("click", (2, 5, "left")), ("screenshot", ())]
440+
assert screenshot_output == "non_introspectable"
441+
assert "does not accept keyword argument(s) keys" in caplog.text
442+
443+
400444
@pytest.mark.asyncio
401445
async def test_get_screenshot_preserves_modifier_keys_for_kwargs_driver() -> None:
402446
class KwargsDriver:
@@ -411,10 +455,10 @@ def move(self, x: int, y: int, **kwargs: Any) -> None:
411455
self.calls.append(("move", (x, y), kwargs))
412456

413457
tool_call = ResponseComputerToolCall(
414-
id="c8",
458+
id="c9",
415459
type="computer_call",
416460
action=_action_with_keys(ActionMove, type="move", x=10, y=12, keys=["meta"]),
417-
call_id="c8",
461+
call_id="c9",
418462
pending_safety_checks=[],
419463
status="completed",
420464
)
@@ -433,12 +477,12 @@ def move(self, x: int, y: int, **kwargs: Any) -> None:
433477
async def test_get_screenshot_preserves_modifier_keys_for_batched_actions() -> None:
434478
computer = LoggingComputer(screenshot_return="batched_keys")
435479
tool_call = ResponseComputerToolCall(
436-
id="c9",
480+
id="c10",
437481
type="computer_call",
438482
actions=[
439483
_action_with_keys(BatchedClick, type="click", x=11, y=12, button="left", keys=["ctrl"])
440484
],
441-
call_id="c9",
485+
call_id="c10",
442486
pending_safety_checks=[],
443487
status="completed",
444488
)

0 commit comments

Comments
 (0)