3434)
3535
3636
37+ def _dummy_ctx () -> RunContextWrapper [None ]:
38+ return RunContextWrapper (context = None )
39+
40+
3741def test_empty_response ():
3842 agent = Agent (name = "test" )
3943 response = ModelResponse (
@@ -83,7 +87,7 @@ async def test_single_tool_call():
8387 response = response ,
8488 output_schema = None ,
8589 handoffs = [],
86- all_tools = await agent .get_all_tools (),
90+ all_tools = await agent .get_all_tools (_dummy_ctx () ),
8791 )
8892 assert not result .handoffs
8993 assert result .functions and len (result .functions ) == 1
@@ -111,7 +115,7 @@ async def test_missing_tool_call_raises_error():
111115 response = response ,
112116 output_schema = None ,
113117 handoffs = [],
114- all_tools = await agent .get_all_tools (),
118+ all_tools = await agent .get_all_tools (_dummy_ctx () ),
115119 )
116120
117121
@@ -140,7 +144,7 @@ async def test_multiple_tool_calls():
140144 response = response ,
141145 output_schema = None ,
142146 handoffs = [],
143- all_tools = await agent .get_all_tools (),
147+ all_tools = await agent .get_all_tools (_dummy_ctx () ),
144148 )
145149 assert not result .handoffs
146150 assert result .functions and len (result .functions ) == 2
@@ -169,7 +173,7 @@ async def test_handoffs_parsed_correctly():
169173 response = response ,
170174 output_schema = None ,
171175 handoffs = [],
172- all_tools = await agent_3 .get_all_tools (),
176+ all_tools = await agent_3 .get_all_tools (_dummy_ctx () ),
173177 )
174178 assert not result .handoffs , "Shouldn't have a handoff here"
175179
@@ -183,7 +187,7 @@ async def test_handoffs_parsed_correctly():
183187 response = response ,
184188 output_schema = None ,
185189 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 () ),
187191 )
188192 assert len (result .handoffs ) == 1 , "Should have a handoff here"
189193 handoff = result .handoffs [0 ]
@@ -213,7 +217,7 @@ async def test_missing_handoff_fails():
213217 response = response ,
214218 output_schema = None ,
215219 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 () ),
217221 )
218222
219223
@@ -236,7 +240,7 @@ async def test_multiple_handoffs_doesnt_error():
236240 response = response ,
237241 output_schema = None ,
238242 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 () ),
240244 )
241245 assert len (result .handoffs ) == 2 , "Should have multiple handoffs here"
242246
@@ -262,7 +266,7 @@ async def test_final_output_parsed_correctly():
262266 response = response ,
263267 output_schema = Runner ._get_output_schema (agent ),
264268 handoffs = [],
265- all_tools = await agent .get_all_tools (),
269+ all_tools = await agent .get_all_tools (_dummy_ctx () ),
266270 )
267271
268272
@@ -288,7 +292,7 @@ async def test_file_search_tool_call_parsed_correctly():
288292 response = response ,
289293 output_schema = None ,
290294 handoffs = [],
291- all_tools = await agent .get_all_tools (),
295+ all_tools = await agent .get_all_tools (_dummy_ctx () ),
292296 )
293297 # The final item should be a ToolCallItem for the file search call
294298 assert any (
@@ -313,7 +317,7 @@ async def test_function_web_search_tool_call_parsed_correctly():
313317 response = response ,
314318 output_schema = None ,
315319 handoffs = [],
316- all_tools = await agent .get_all_tools (),
320+ all_tools = await agent .get_all_tools (_dummy_ctx () ),
317321 )
318322 assert any (
319323 isinstance (item , ToolCallItem ) and item .raw_item is web_search_call
@@ -340,7 +344,7 @@ async def test_reasoning_item_parsed_correctly():
340344 response = response ,
341345 output_schema = None ,
342346 handoffs = [],
343- all_tools = await Agent (name = "test" ).get_all_tools (),
347+ all_tools = await Agent (name = "test" ).get_all_tools (_dummy_ctx () ),
344348 )
345349 assert any (
346350 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():
409413 response = response ,
410414 output_schema = None ,
411415 handoffs = [],
412- all_tools = await Agent (name = "test" ).get_all_tools (),
416+ all_tools = await Agent (name = "test" ).get_all_tools (_dummy_ctx () ),
413417 )
414418
415419
@@ -437,7 +441,7 @@ async def test_computer_tool_call_with_computer_tool_parsed_correctly():
437441 response = response ,
438442 output_schema = None ,
439443 handoffs = [],
440- all_tools = await agent .get_all_tools (),
444+ all_tools = await agent .get_all_tools (_dummy_ctx () ),
441445 )
442446 assert any (
443447 isinstance (item , ToolCallItem ) and item .raw_item is computer_call
@@ -468,7 +472,7 @@ async def test_tool_and_handoff_parsed_correctly():
468472 response = response ,
469473 output_schema = None ,
470474 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 () ),
472476 )
473477 assert result .functions and len (result .functions ) == 1
474478 assert len (result .handoffs ) == 1 , "Should have a handoff here"
0 commit comments