23
23
24
24
from agents import (
25
25
Agent ,
26
+ Action ,
26
27
AgentHooks ,
27
28
AsyncComputer ,
28
29
Computer ,
31
32
RunContextWrapper ,
32
33
RunHooks ,
33
34
)
34
- from agents ._run_impl import ComputerAction , ToolRunComputerAction
35
+ from agents ._run_impl import ComputerAction
36
+ from agents .tool import ToolRunComputerAction
35
37
from agents .items import ToolCallOutputItem
36
38
37
39
@@ -127,10 +129,18 @@ async def drag(self, path: list[tuple[int, int]]) -> None:
127
129
@pytest .mark .parametrize (
128
130
"action,expected_call" ,
129
131
[
130
- (ActionClick (type = "click" , x = 10 , y = 21 , button = "left" ), ("click" , (10 , 21 , "left" ))),
131
- (ActionDoubleClick (type = "double_click" , x = 42 , y = 47 ), ("double_click" , (42 , 47 ))),
132
132
(
133
- ActionDrag (type = "drag" , path = [ActionDragPath (x = 1 , y = 2 ), ActionDragPath (x = 3 , y = 4 )]),
133
+ ActionClick (type = "click" , x = 10 , y = 21 , button = "left" ),
134
+ ("click" , (10 , 21 , "left" )),
135
+ ),
136
+ (
137
+ ActionDoubleClick (type = "double_click" , x = 42 , y = 47 ),
138
+ ("double_click" , (42 , 47 )),
139
+ ),
140
+ (
141
+ ActionDrag (
142
+ type = "drag" , path = [ActionDragPath (x = 1 , y = 2 ), ActionDragPath (x = 3 , y = 4 )]
143
+ ),
134
144
("drag" , (((1 , 2 ), (3 , 4 )),)),
135
145
),
136
146
(ActionKeypress (type = "keypress" , keys = ["a" , "b" ]), ("keypress" , (["a" , "b" ],))),
@@ -172,13 +182,24 @@ async def test_get_screenshot_sync_executes_action_and_takes_screenshot(
172
182
@pytest .mark .parametrize (
173
183
"action,expected_call" ,
174
184
[
175
- (ActionClick (type = "click" , x = 2 , y = 3 , button = "right" ), ("click" , (2 , 3 , "right" ))),
176
- (ActionDoubleClick (type = "double_click" , x = 12 , y = 13 ), ("double_click" , (12 , 13 ))),
177
185
(
178
- ActionDrag (type = "drag" , path = [ActionDragPath (x = 5 , y = 6 ), ActionDragPath (x = 6 , y = 7 )]),
186
+ ActionClick (type = "click" , x = 2 , y = 3 , button = "right" ),
187
+ ("click" , (2 , 3 , "right" )),
188
+ ),
189
+ (
190
+ ActionDoubleClick (type = "double_click" , x = 12 , y = 13 ),
191
+ ("double_click" , (12 , 13 )),
192
+ ),
193
+ (
194
+ ActionDrag (
195
+ type = "drag" , path = [ActionDragPath (x = 5 , y = 6 ), ActionDragPath (x = 6 , y = 7 )]
196
+ ),
179
197
("drag" , (((5 , 6 ), (6 , 7 )),)),
180
198
),
181
- (ActionKeypress (type = "keypress" , keys = ["ctrl" , "c" ]), ("keypress" , (["ctrl" , "c" ],))),
199
+ (
200
+ ActionKeypress (type = "keypress" , keys = ["ctrl" , "c" ]),
201
+ ("keypress" , (["ctrl" , "c" ],)),
202
+ ),
182
203
(ActionMove (type = "move" , x = 8 , y = 9 ), ("move" , (8 , 9 ))),
183
204
(ActionScreenshot (type = "screenshot" ), ("screenshot" , ())),
184
205
(
@@ -222,9 +243,9 @@ def __init__(self) -> None:
222
243
self .ended : list [tuple [Agent [Any ], Any , str ]] = []
223
244
224
245
async def on_tool_start (
225
- self , context : RunContextWrapper [Any ], agent : Agent [Any ], tool : Any
246
+ self , context : RunContextWrapper [Any ], agent : Agent [Any ], action : Action ,
226
247
) -> None :
227
- self .started .append ((agent , tool ))
248
+ self .started .append ((agent , action . computer_tool ))
228
249
229
250
async def on_tool_end (
230
251
self , context : RunContextWrapper [Any ], agent : Agent [Any ], tool : Any , result : str
@@ -241,9 +262,9 @@ def __init__(self) -> None:
241
262
self .ended : list [tuple [Agent [Any ], Any , str ]] = []
242
263
243
264
async def on_tool_start (
244
- self , context : RunContextWrapper [Any ], agent : Agent [Any ], tool : Any
265
+ self , context : RunContextWrapper [Any ], agent : Agent [Any ], action : Action ,
245
266
) -> None :
246
- self .started .append ((agent , tool ))
267
+ self .started .append ((agent , action . computer_tool ))
247
268
248
269
async def on_tool_end (
249
270
self , context : RunContextWrapper [Any ], agent : Agent [Any ], tool : Any , result : str
0 commit comments