Skip to content

Chat Completions streaming computes assistant output_index with a bool expression #3109

Closed

Description

@Aphroq

Please read this first

  • Have you read the docs? Agents SDK docs
  • Have you searched for related issues? Others may have faced similar issues.

Describe the bug

The Chat Completions streaming handler sometimes passes a boolean value as output_index for assistant message events after a reasoning item has been emitted.

Several event constructors use this expression:

output_index=state.reasoning_content_index_and_output is not None

When reasoning content exists, this produces True rather than the integer 1. Python treats bool as a subclass of int, so this can pass local numeric checks, but downstream JSON consumers and event snapshots can observe the wrong type.

Relevant code:

  • src/agents/models/chatcmpl_stream_handler.py: text, refusal, content-part-done, and output-item-done events use the boolean expression above.

Debug information

  • Agents SDK version: current main at 3854c124
  • Python version: Python 3.12.1

Repro steps

Stream Chat Completions chunks where reasoning content is emitted before regular text content. Inspect the output_index on the text/message events that follow the reasoning item.

Current behavior: some events use True as output_index.

Expected behavior

All streamed response events should use integer output_index values, for example 0 for the reasoning item and 1 for the assistant message that follows it. No event should expose a boolean output_index.

Activity

  1. changed the title [-]Chat Completions streaming emits boolean output_index values[/-] [+]Chat Completions streaming computes assistant output_index with a bool expression[/+] on May 4, 2026
  2. Aphroq commented on May 4, 2026

    @Aphroq
    ContributorAuthor

    Update:

    I re-tested this on main .

    The source observation is still valid: several event constructors pass:

    output_index=state.reasoning_content_index_and_output is not None

    However, I could not reproduce the originally described downstream-visible behavior. The OpenAI SDK/Pydantic response event models coerce this value to int.

    Observed stream events:

    response.output_item.added output_index=1 type=<class 'int'>
    response.content_part.added output_index=1 type=<class 'int'>
    response.output_text.delta output_index=1 type=<class 'int'>
    response.content_part.done output_index=1 type=<class 'int'>
    response.output_item.done output_index=1 type=<class 'int'>
    

    Direct event construction also coerces output_index=True to 1, and model_dump_json() emits "output_index":1.

    So this issue should be treated as a code clarity / defensive consistency cleanup, not as a confirmed runtime bug where consumers observe bool.

  3. added a commit that references this issue on May 7, 2026
    5adeebd
  4. seratch commented on May 7, 2026

    @seratch
    Member

    Fixed y #3176

  5. added a commit that references this issue on May 7, 2026
    170ee73
  6. added a commit that references this issue on Jun 21, 2026
    4cd0a38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions