11from openai .types .responses import ResponseOutputMessage , ResponseOutputText
2+ from openai .types .responses .response_reasoning_item import ResponseReasoningItem
23
34from agents import Agent , HandoffInputData , RunContextWrapper
45from agents .extensions .handoff_filters import remove_all_tools
56from agents .items import (
67 HandoffOutputItem ,
78 MessageOutputItem ,
9+ ReasoningItem ,
810 ToolCallOutputItem ,
911 TResponseInputItem ,
1012)
@@ -23,6 +25,10 @@ def _get_message_input_item(content: str) -> TResponseInputItem:
2325 }
2426
2527
28+ def _get_reasoning_input_item () -> TResponseInputItem :
29+ return {"id" : "rid" , "summary" : [], "type" : "reasoning" }
30+
31+
2632def _get_function_result_input_item (content : str ) -> TResponseInputItem :
2733 return {
2834 "call_id" : "1" ,
@@ -77,6 +83,12 @@ def _get_handoff_output_run_item(content: str) -> HandoffOutputItem:
7783 )
7884
7985
86+ def _get_reasoning_output_run_item () -> ReasoningItem :
87+ return ReasoningItem (
88+ agent = fake_agent (), raw_item = ResponseReasoningItem (id = "rid" , summary = [], type = "reasoning" )
89+ )
90+
91+
8092def test_empty_data ():
8193 handoff_input_data = HandoffInputData (
8294 input_history = (),
@@ -161,21 +173,24 @@ def test_removes_tools_from_new_items_and_history():
161173 handoff_input_data = HandoffInputData (
162174 input_history = (
163175 _get_message_input_item ("Hello1" ),
176+ _get_reasoning_input_item (),
164177 _get_function_result_input_item ("World" ),
165178 _get_message_input_item ("Hello2" ),
166179 ),
167180 pre_handoff_items = (
181+ _get_reasoning_output_run_item (),
168182 _get_message_output_run_item ("123" ),
169183 _get_tool_output_run_item ("456" ),
170184 ),
171185 new_items = (
186+ _get_reasoning_output_run_item (),
172187 _get_message_output_run_item ("Hello" ),
173188 _get_tool_output_run_item ("World" ),
174189 ),
175190 run_context = RunContextWrapper (context = ()),
176191 )
177192 filtered_data = remove_all_tools (handoff_input_data )
178- assert len (filtered_data .input_history ) == 2
193+ assert len (filtered_data .input_history ) == 3
179194 assert len (filtered_data .pre_handoff_items ) == 1
180195 assert len (filtered_data .new_items ) == 1
181196
@@ -187,11 +202,13 @@ def test_removes_handoffs_from_history():
187202 _get_handoff_input_item ("World" ),
188203 ),
189204 pre_handoff_items = (
205+ _get_reasoning_output_run_item (),
190206 _get_message_output_run_item ("Hello" ),
191207 _get_tool_output_run_item ("World" ),
192208 _get_handoff_output_run_item ("World" ),
193209 ),
194210 new_items = (
211+ _get_reasoning_output_run_item (),
195212 _get_message_output_run_item ("Hello" ),
196213 _get_tool_output_run_item ("World" ),
197214 _get_handoff_output_run_item ("World" ),
0 commit comments