34
34
)
35
35
36
36
37
+ def _dummy_ctx () -> RunContextWrapper [None ]:
38
+ return RunContextWrapper (context = None )
39
+
40
+
37
41
def test_empty_response ():
38
42
agent = Agent (name = "test" )
39
43
response = ModelResponse (
@@ -83,7 +87,7 @@ async def test_single_tool_call():
83
87
response = response ,
84
88
output_schema = None ,
85
89
handoffs = [],
86
- all_tools = await agent .get_all_tools (),
90
+ all_tools = await agent .get_all_tools (_dummy_ctx () ),
87
91
)
88
92
assert not result .handoffs
89
93
assert result .functions and len (result .functions ) == 1
@@ -111,7 +115,7 @@ async def test_missing_tool_call_raises_error():
111
115
response = response ,
112
116
output_schema = None ,
113
117
handoffs = [],
114
- all_tools = await agent .get_all_tools (),
118
+ all_tools = await agent .get_all_tools (_dummy_ctx () ),
115
119
)
116
120
117
121
@@ -140,7 +144,7 @@ async def test_multiple_tool_calls():
140
144
response = response ,
141
145
output_schema = None ,
142
146
handoffs = [],
143
- all_tools = await agent .get_all_tools (),
147
+ all_tools = await agent .get_all_tools (_dummy_ctx () ),
144
148
)
145
149
assert not result .handoffs
146
150
assert result .functions and len (result .functions ) == 2
@@ -169,7 +173,7 @@ async def test_handoffs_parsed_correctly():
169
173
response = response ,
170
174
output_schema = None ,
171
175
handoffs = [],
172
- all_tools = await agent_3 .get_all_tools (),
176
+ all_tools = await agent_3 .get_all_tools (_dummy_ctx () ),
173
177
)
174
178
assert not result .handoffs , "Shouldn't have a handoff here"
175
179
@@ -183,7 +187,7 @@ async def test_handoffs_parsed_correctly():
183
187
response = response ,
184
188
output_schema = None ,
185
189
handoffs = Runner ._get_handoffs (agent_3 ),
186
- all_tools = await agent_3 .get_all_tools (),
190
+ all_tools = await agent_3 .get_all_tools (_dummy_ctx () ),
187
191
)
188
192
assert len (result .handoffs ) == 1 , "Should have a handoff here"
189
193
handoff = result .handoffs [0 ]
@@ -213,7 +217,7 @@ async def test_missing_handoff_fails():
213
217
response = response ,
214
218
output_schema = None ,
215
219
handoffs = Runner ._get_handoffs (agent_3 ),
216
- all_tools = await agent_3 .get_all_tools (),
220
+ all_tools = await agent_3 .get_all_tools (_dummy_ctx () ),
217
221
)
218
222
219
223
@@ -236,7 +240,7 @@ async def test_multiple_handoffs_doesnt_error():
236
240
response = response ,
237
241
output_schema = None ,
238
242
handoffs = Runner ._get_handoffs (agent_3 ),
239
- all_tools = await agent_3 .get_all_tools (),
243
+ all_tools = await agent_3 .get_all_tools (_dummy_ctx () ),
240
244
)
241
245
assert len (result .handoffs ) == 2 , "Should have multiple handoffs here"
242
246
@@ -262,7 +266,7 @@ async def test_final_output_parsed_correctly():
262
266
response = response ,
263
267
output_schema = Runner ._get_output_schema (agent ),
264
268
handoffs = [],
265
- all_tools = await agent .get_all_tools (),
269
+ all_tools = await agent .get_all_tools (_dummy_ctx () ),
266
270
)
267
271
268
272
@@ -288,7 +292,7 @@ async def test_file_search_tool_call_parsed_correctly():
288
292
response = response ,
289
293
output_schema = None ,
290
294
handoffs = [],
291
- all_tools = await agent .get_all_tools (),
295
+ all_tools = await agent .get_all_tools (_dummy_ctx () ),
292
296
)
293
297
# The final item should be a ToolCallItem for the file search call
294
298
assert any (
@@ -313,7 +317,7 @@ async def test_function_web_search_tool_call_parsed_correctly():
313
317
response = response ,
314
318
output_schema = None ,
315
319
handoffs = [],
316
- all_tools = await agent .get_all_tools (),
320
+ all_tools = await agent .get_all_tools (_dummy_ctx () ),
317
321
)
318
322
assert any (
319
323
isinstance (item , ToolCallItem ) and item .raw_item is web_search_call
@@ -340,7 +344,7 @@ async def test_reasoning_item_parsed_correctly():
340
344
response = response ,
341
345
output_schema = None ,
342
346
handoffs = [],
343
- all_tools = await Agent (name = "test" ).get_all_tools (),
347
+ all_tools = await Agent (name = "test" ).get_all_tools (_dummy_ctx () ),
344
348
)
345
349
assert any (
346
350
isinstance (item , ReasoningItem ) and item .raw_item is reasoning for item in result .new_items
@@ -409,7 +413,7 @@ async def test_computer_tool_call_without_computer_tool_raises_error():
409
413
response = response ,
410
414
output_schema = None ,
411
415
handoffs = [],
412
- all_tools = await Agent (name = "test" ).get_all_tools (),
416
+ all_tools = await Agent (name = "test" ).get_all_tools (_dummy_ctx () ),
413
417
)
414
418
415
419
@@ -437,7 +441,7 @@ async def test_computer_tool_call_with_computer_tool_parsed_correctly():
437
441
response = response ,
438
442
output_schema = None ,
439
443
handoffs = [],
440
- all_tools = await agent .get_all_tools (),
444
+ all_tools = await agent .get_all_tools (_dummy_ctx () ),
441
445
)
442
446
assert any (
443
447
isinstance (item , ToolCallItem ) and item .raw_item is computer_call
@@ -468,7 +472,7 @@ async def test_tool_and_handoff_parsed_correctly():
468
472
response = response ,
469
473
output_schema = None ,
470
474
handoffs = Runner ._get_handoffs (agent_3 ),
471
- all_tools = await agent_3 .get_all_tools (),
475
+ all_tools = await agent_3 .get_all_tools (_dummy_ctx () ),
472
476
)
473
477
assert result .functions and len (result .functions ) == 1
474
478
assert len (result .handoffs ) == 1 , "Should have a handoff here"
0 commit comments