11from typing import Any
22
33import pytest
4+ from openai .types .responses import ResponseOutputMessage , ResponseOutputText
45from pydantic import BaseModel
56
67from agents import (
1314 RunHooks ,
1415 Runner ,
1516 Session ,
17+ TResponseInputItem ,
1618)
1719from agents .tool_context import ToolContext
18- from openai .types .responses import ResponseOutputMessage , ResponseOutputText
1920
2021
2122class BoolCtx (BaseModel ):
@@ -242,7 +243,11 @@ async def test_agent_as_tool_returns_concatenated_text(monkeypatch: pytest.Monke
242243 ],
243244 )
244245
245- result = type ("DummyResult" , (), {"new_items" : [MessageOutputItem (agent = agent , raw_item = message )]})()
246+ result = type (
247+ "DummyResult" ,
248+ (),
249+ {"new_items" : [MessageOutputItem (agent = agent , raw_item = message )]},
250+ )()
246251
247252 async def fake_run (
248253 cls ,
@@ -269,6 +274,7 @@ async def fake_run(
269274 is_enabled = True ,
270275 )
271276
277+ assert isinstance (tool , FunctionTool )
272278 tool_context = ToolContext (context = None , tool_name = "story_tool" , tool_call_id = "call_1" )
273279 output = await tool .on_invoke_tool (tool_context , '{"input": "hello"}' )
274280
@@ -299,16 +305,16 @@ async def test_agent_as_tool_custom_output_extractor(monkeypatch: pytest.MonkeyP
299305 class DummySession (Session ):
300306 session_id = "sess_123"
301307
302- async def get_items (self , limit : int | None = None ): # type: ignore[override]
308+ async def get_items (self , limit : int | None = None ) -> list [ TResponseInputItem ]:
303309 return []
304310
305- async def add_items (self , items ): # type: ignore[override]
311+ async def add_items (self , items : list [ TResponseInputItem ]) -> None :
306312 return None
307313
308- async def pop_item (self ): # type: ignore[override]
314+ async def pop_item (self ) -> TResponseInputItem | None :
309315 return None
310316
311- async def clear_session (self ): # type: ignore[override]
317+ async def clear_session (self ) -> None :
312318 return None
313319
314320 dummy_session = DummySession ()
@@ -365,6 +371,7 @@ async def extractor(result) -> str:
365371 session = dummy_session ,
366372 )
367373
374+ assert isinstance (tool , FunctionTool )
368375 tool_context = ToolContext (context = None , tool_name = "summary_tool" , tool_call_id = "call_2" )
369376 output = await tool .on_invoke_tool (tool_context , '{"input": "summarize this"}' )
370377
0 commit comments