Skip to content

Commit ba09334

Browse files
committed
fix(handoff_filters): also drop ReasoningItem in remove_all_tools for store=False handoffs to avoid API item not found error
1 parent aeaf83f commit ba09334

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

src/agents/extensions/handoff_filters.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from ..items import (
55
HandoffCallItem,
66
HandoffOutputItem,
7+
ReasoningItem,
78
RunItem,
89
ToolCallItem,
910
ToolCallOutputItem,
@@ -41,6 +42,7 @@ def _remove_tools_from_items(items: tuple[RunItem, ...]) -> tuple[RunItem, ...]:
4142
or isinstance(item, HandoffOutputItem)
4243
or isinstance(item, ToolCallItem)
4344
or isinstance(item, ToolCallOutputItem)
45+
or isinstance(item, ReasoningItem)
4446
):
4547
continue
4648
filtered_items.append(item)

tests/test_extension_filters.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from agents.items import (
66
HandoffOutputItem,
77
MessageOutputItem,
8+
ReasoningItem,
89
ToolCallOutputItem,
910
TResponseInputItem,
1011
)
@@ -77,6 +78,12 @@ def _get_handoff_output_run_item(content: str) -> HandoffOutputItem:
7778
)
7879

7980

81+
def _get_reasoning_output_run_item() -> ReasoningItem:
82+
return ReasoningItem(
83+
agent=fake_agent(), raw_item={"id": "rid", "summary": [], "type": "reasoning"}
84+
)
85+
86+
8087
def test_empty_data():
8188
handoff_input_data = HandoffInputData(
8289
input_history=(),
@@ -165,10 +172,12 @@ def test_removes_tools_from_new_items_and_history():
165172
_get_message_input_item("Hello2"),
166173
),
167174
pre_handoff_items=(
175+
_get_reasoning_output_run_item(),
168176
_get_message_output_run_item("123"),
169177
_get_tool_output_run_item("456"),
170178
),
171179
new_items=(
180+
_get_reasoning_output_run_item(),
172181
_get_message_output_run_item("Hello"),
173182
_get_tool_output_run_item("World"),
174183
),
@@ -187,11 +196,13 @@ def test_removes_handoffs_from_history():
187196
_get_handoff_input_item("World"),
188197
),
189198
pre_handoff_items=(
199+
_get_reasoning_output_run_item(),
190200
_get_message_output_run_item("Hello"),
191201
_get_tool_output_run_item("World"),
192202
_get_handoff_output_run_item("World"),
193203
),
194204
new_items=(
205+
_get_reasoning_output_run_item(),
195206
_get_message_output_run_item("Hello"),
196207
_get_tool_output_run_item("World"),
197208
_get_handoff_output_run_item("World"),

0 commit comments

Comments
 (0)