Skip to content

Improve index keys in StreamingChunk #9684

@Amnah199

Description

@Amnah199

Problem
While updating the chat generators for the new StreamingChunk, we’ve found that the current use of multiple index fields during streaming is confusing and potentially redundant.

In some cases, 3–4 different index values are passed within the same chunk, for example:

  1. Index of the StreamingChunk
  2. Index of the ToolCallDelta
  3. Index in the meta of the original response chunk from the API
  4. Index in the ToolCall from the API

Example chunk from OpenAIChatGenerator

StreamingChunk(
    content="",
    meta={
        "model": "gpt-4o-mini-2024-07-18",
        "index": 0,  # (3) API response chunk index
        "tool_calls": [
            ChoiceDeltaToolCall(
                index=1,  # (4) ToolCallDelta index from API
                id="call_C88m67V16CrETq6jbNXjdZI9",
                function=ChoiceDeltaToolCallFunction(arguments="", name="weather"),
                type="function",
            )
        ],
        "finish_reason": None,
        "received_at": ANY,
        "usage": None,
    },
    index=1,  # (1) StreamingChunk index
    tool_calls=[
        ToolCallDelta(
            tool_name="weather",
            id="call_C88m67V16CrETq6jbNXjdZI9",
            index=1  # (2) ToolCallDelta index
        )
    ],
    start=True,
)

Why This is a Problem

  • Hard to read and maintain
  • It’s not immediately obvious which index is relevant for tracing content blocks vs. tool calls.
  • The current meta payload may be carrying redundant information from the raw API response.

Possible Directions for Solution:

  • Consider removing index keys from meta if they dont serve a purpose.
  • Rename our index keys to make them explicit (e.g., chunk_index, tool_call_index) We have nested index in ToolCallDelta of StreamingChunk.
  • Rethink storing the entire raw chunk in meta if it adds noise without value.

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Medium priority, add to the next sprint if no P1 availabletopic:streaming

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions