Skip to content

Commit a714cf4

Browse files
authored
Fix: Add empty checks for reasoning content arrays in stream handler (#1982)
1 parent 4bc33e3 commit a714cf4

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/agents/models/chatcmpl_stream_handler.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,12 @@ async def handle_stream(
150150
)
151151

152152
if reasoning_content and state.reasoning_content_index_and_output:
153+
# Ensure summary list has at least one element
154+
if not state.reasoning_content_index_and_output[1].summary:
155+
state.reasoning_content_index_and_output[1].summary = [
156+
Summary(text="", type="summary_text")
157+
]
158+
153159
yield ResponseReasoningSummaryTextDeltaEvent(
154160
delta=reasoning_content,
155161
item_id=FAKE_RESPONSES_ID,
@@ -201,7 +207,7 @@ async def handle_stream(
201207
)
202208

203209
# Create a new summary with updated text
204-
if state.reasoning_content_index_and_output[1].content is None:
210+
if not state.reasoning_content_index_and_output[1].content:
205211
state.reasoning_content_index_and_output[1].content = [
206212
Content(text="", type="reasoning_text")
207213
]

0 commit comments

Comments
 (0)