1
1
from openai .types .responses import ResponseOutputMessage , ResponseOutputText
2
+ from openai .types .responses .response_reasoning_item import ResponseReasoningItem
2
3
3
4
from agents import Agent , HandoffInputData , RunContextWrapper
4
5
from agents .extensions .handoff_filters import remove_all_tools
5
6
from agents .items import (
6
7
HandoffOutputItem ,
7
8
MessageOutputItem ,
9
+ ReasoningItem ,
8
10
ToolCallOutputItem ,
9
11
TResponseInputItem ,
10
12
)
@@ -23,6 +25,10 @@ def _get_message_input_item(content: str) -> TResponseInputItem:
23
25
}
24
26
25
27
28
+ def _get_reasoning_input_item () -> TResponseInputItem :
29
+ return {"id" : "rid" , "summary" : [], "type" : "reasoning" }
30
+
31
+
26
32
def _get_function_result_input_item (content : str ) -> TResponseInputItem :
27
33
return {
28
34
"call_id" : "1" ,
@@ -77,6 +83,12 @@ def _get_handoff_output_run_item(content: str) -> HandoffOutputItem:
77
83
)
78
84
79
85
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
+
80
92
def test_empty_data ():
81
93
handoff_input_data = HandoffInputData (
82
94
input_history = (),
@@ -161,21 +173,24 @@ def test_removes_tools_from_new_items_and_history():
161
173
handoff_input_data = HandoffInputData (
162
174
input_history = (
163
175
_get_message_input_item ("Hello1" ),
176
+ _get_reasoning_input_item (),
164
177
_get_function_result_input_item ("World" ),
165
178
_get_message_input_item ("Hello2" ),
166
179
),
167
180
pre_handoff_items = (
181
+ _get_reasoning_output_run_item (),
168
182
_get_message_output_run_item ("123" ),
169
183
_get_tool_output_run_item ("456" ),
170
184
),
171
185
new_items = (
186
+ _get_reasoning_output_run_item (),
172
187
_get_message_output_run_item ("Hello" ),
173
188
_get_tool_output_run_item ("World" ),
174
189
),
175
190
run_context = RunContextWrapper (context = ()),
176
191
)
177
192
filtered_data = remove_all_tools (handoff_input_data )
178
- assert len (filtered_data .input_history ) == 2
193
+ assert len (filtered_data .input_history ) == 3
179
194
assert len (filtered_data .pre_handoff_items ) == 1
180
195
assert len (filtered_data .new_items ) == 1
181
196
@@ -187,11 +202,13 @@ def test_removes_handoffs_from_history():
187
202
_get_handoff_input_item ("World" ),
188
203
),
189
204
pre_handoff_items = (
205
+ _get_reasoning_output_run_item (),
190
206
_get_message_output_run_item ("Hello" ),
191
207
_get_tool_output_run_item ("World" ),
192
208
_get_handoff_output_run_item ("World" ),
193
209
),
194
210
new_items = (
211
+ _get_reasoning_output_run_item (),
195
212
_get_message_output_run_item ("Hello" ),
196
213
_get_tool_output_run_item ("World" ),
197
214
_get_handoff_output_run_item ("World" ),
0 commit comments