@@ -843,8 +843,6 @@ async def _run_single_turn_streamed(
843
843
all_tools : list [Tool ],
844
844
previous_response_id : str | None ,
845
845
) -> SingleStepResult :
846
- # Track tool call IDs we've already emitted to avoid duplicates when we later
847
- # enqueue all items at the end of the turn.
848
846
emitted_tool_call_ids : set [str ] = set ()
849
847
850
848
if should_run_agent_start_hooks :
@@ -891,8 +889,6 @@ async def _run_single_turn_streamed(
891
889
previous_response_id = previous_response_id ,
892
890
prompt = prompt_config ,
893
891
):
894
- # 1. If the event signals the end of the assistant response, remember it so we can
895
- # process the full response after the streaming loop.
896
892
if isinstance (event , ResponseCompletedEvent ):
897
893
usage = (
898
894
Usage (
@@ -913,8 +909,6 @@ async def _run_single_turn_streamed(
913
909
)
914
910
context_wrapper .usage .add (usage )
915
911
916
- # 2. Detect tool call output-item additions **while** the model is still streaming.
917
- # Emit a high-level RunItemStreamEvent so UIs can react immediately.
918
912
if isinstance (event , ResponseOutputItemAddedEvent ):
919
913
output_item = event .item
920
914
@@ -929,10 +923,8 @@ async def _run_single_turn_streamed(
929
923
RunItemStreamEvent (item = tool_item , name = "tool_called" )
930
924
)
931
925
932
- # Always forward the raw event.
933
926
streamed_result ._event_queue .put_nowait (RawResponsesStreamEvent (data = event ))
934
927
935
- # 2. At this point, the streaming is complete for this turn of the agent loop.
936
928
if not final_response :
937
929
raise ModelBehaviorError ("Model did not produce a final response!" )
938
930
@@ -951,9 +943,8 @@ async def _run_single_turn_streamed(
951
943
tool_use_tracker = tool_use_tracker ,
952
944
)
953
945
954
- # Remove tool_called items we've already emitted during streaming to avoid duplicates.
955
946
if emitted_tool_call_ids :
956
- import dataclasses as _dc # local import to avoid polluting module namespace
947
+ import dataclasses as _dc
957
948
958
949
filtered_items = [
959
950
item
0 commit comments