@@ -395,12 +395,11 @@ async def extractor(result) -> str:
395395
396396
397397@pytest .mark .asyncio
398- async def test_agent_as_tool_extractor_can_access_tool_context (
398+ async def test_agent_as_tool_extractor_can_access_agent_tool_invocation (
399399 monkeypatch : pytest .MonkeyPatch ,
400400) -> None :
401401 agent = Agent (name = "nested_agent" )
402-
403- real_run_result = RunResult (
402+ run_result = RunResult (
404403 input = "hello" ,
405404 new_items = [],
406405 raw_responses = [],
@@ -413,7 +412,7 @@ async def test_agent_as_tool_extractor_can_access_tool_context(
413412 context = None ,
414413 tool_name = "nested_tool" ,
415414 tool_call_id = "call_abc_123" ,
416- tool_arguments = "{}" ,
415+ tool_arguments = '{"input": "hello"}' ,
417416 ),
418417 _last_agent = agent ,
419418 )
@@ -433,16 +432,19 @@ async def fake_run(
433432 ):
434433 del cls , starting_agent , input , context , max_turns , hooks , run_config
435434 del previous_response_id , conversation_id , session
436- return real_run_result
435+ return run_result
437436
438437 monkeypatch .setattr (Runner , "run" , classmethod (fake_run ))
439438
440- received_call_id : str | None = None
439+ received_tool_call_id : str | None = None
441440
442441 async def extractor (result : RunResult | RunResultStreaming ) -> str :
443- nonlocal received_call_id
444- assert result .tool_context is not None
445- received_call_id = result .tool_context .tool_call_id
442+ nonlocal received_tool_call_id
443+ invocation = result .agent_tool_invocation
444+ assert invocation is not None
445+ received_tool_call_id = invocation .tool_call_id
446+ assert invocation .tool_name == "nested_tool"
447+ assert invocation .tool_arguments == '{"input": "hello"}'
446448 return "extracted"
447449
448450 tool = agent .as_tool (
@@ -460,7 +462,7 @@ async def extractor(result: RunResult | RunResultStreaming) -> str:
460462 output = await tool .on_invoke_tool (parent_tool_context , '{"input": "hello"}' )
461463
462464 assert output == "extracted"
463- assert received_call_id == "call_abc_123"
465+ assert received_tool_call_id == "call_abc_123"
464466
465467
466468@pytest .mark .asyncio
@@ -1412,7 +1414,7 @@ async def on_stream(payload: AgentToolStreamEvent) -> None:
14121414
14131415
14141416@pytest .mark .asyncio
1415- async def test_agent_as_tool_streaming_extractor_can_access_tool_context (
1417+ async def test_agent_as_tool_streaming_extractor_can_access_agent_tool_invocation (
14161418 monkeypatch : pytest .MonkeyPatch ,
14171419) -> None :
14181420 agent = Agent (name = "streaming_tool_context_agent" )
@@ -1441,7 +1443,13 @@ async def test_agent_as_tool_streaming_extractor_can_access_tool_context(
14411443 streamed_instance ._event_queue .put_nowait (stream_event )
14421444 streamed_instance .is_complete = True
14431445
1444- def fake_run_streamed (cls , / , starting_agent , input , ** kwargs ) -> RunResultStreaming :
1446+ def fake_run_streamed (
1447+ cls ,
1448+ / ,
1449+ starting_agent ,
1450+ input ,
1451+ ** kwargs ,
1452+ ) -> RunResultStreaming :
14451453 del cls , starting_agent , input , kwargs
14461454 return streamed_instance
14471455
@@ -1455,8 +1463,11 @@ async def unexpected_run(*args: Any, **kwargs: Any) -> None:
14551463
14561464 async def extractor (result : RunResult | RunResultStreaming ) -> str :
14571465 nonlocal received_call_id
1458- assert result .tool_context is not None
1459- received_call_id = result .tool_context .tool_call_id
1466+ invocation = result .agent_tool_invocation
1467+ assert invocation is not None
1468+ received_call_id = invocation .tool_call_id
1469+ assert invocation .tool_name == "stream_tool"
1470+ assert invocation .tool_arguments == '{"input": "go"}'
14601471 return "custom value"
14611472
14621473 async def on_stream (payload : AgentToolStreamEvent ) -> None :
0 commit comments