Skip to content

Commit d9cdf40

Browse files
authored
fix: use ResponseOutputRefusal for refusal content part added event
In the refusal handling branch, the `ResponseContentPartAddedEvent` was incorrectly using `ResponseOutputText` as the `part` payload. This violates the OpenAI Agents protocol, which requires refusal content to be represented by `ResponseOutputRefusal` so that downstream consumers can access the `.refusal` field. This change updates the `part` field to use `ResponseOutputRefusal(refusal="", type="refusal")`, ensuring type consistency with both the accumulated state and the corresponding `ResponseContentPartDoneEvent`. Additionally, the `output_index` calculation is slightly improved for clarity by explicitly using `(1 if state.reasoning_content_index_and_output else 0)` instead of a boolean expression, though the primary fix is the payload type correction. This is a safe, minimal, and high-impact fix that aligns the stream handler with the official response schema.
1 parent f91b38f commit d9cdf40

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

src/agents/models/chatcmpl_stream_handler.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -309,12 +309,10 @@ async def handle_stream(
309309
yield ResponseContentPartAddedEvent(
310310
content_index=state.refusal_content_index_and_output[0],
311311
item_id=FAKE_RESPONSES_ID,
312-
output_index=state.reasoning_content_index_and_output
313-
is not None, # fixed 0 -> 0 or 1
314-
part=ResponseOutputText(
315-
text="",
316-
type="output_text",
317-
annotations=[],
312+
output_index=(1 if state.reasoning_content_index_and_output else 0),
313+
part=ResponseOutputRefusal(
314+
refusal="",
315+
type="refusal",
318316
),
319317
type="response.content_part.added",
320318
sequence_number=sequence_number.get_and_increment(),

0 commit comments

Comments
 (0)