Skip to content

Support correct and lossless reconstruction of OpenAI messages when streaming for multi-turn conversation (needed for deep research etc.) #6964

@jonaslalin

Description

@jonaslalin

Description

Streaming Response Message Reconstruction Issue:

The current streaming implementation cannot correctly reconstruct the (await result.response).messages array from streaming deltas, which prevents proper multi-turn conversation continuity. Specific issues include:

  • Complex Reasoning Structure: Reasoning items can contain arrays of summary texts that cannot be properly reconstructed from individual deltas
  • Missing Output Index: The output_index needed to correctly place chunk deltas in the final array structure is not exposed to consumers
  • Incomplete State Building: The streaming parser does not correctly build the final message state from deltas, particularly for complex reasoning content
  • Multi-turn Conversation Breakage: For deep research models and similar advanced reasoning models, users cannot continue conversations with the correct message prefix without implementing custom parsing logic

This means that for streaming scenarios with reasoning models, developers currently need to either:

  1. Use non-streaming mode for multi-turn conversations, or
  2. Implement custom delta parsing logic (which lacks access to necessary metadata like output_index)

See real output from responses API to highlight this issue:

curl https://api.openai.com/v1/responses \
  -H "Authorization: Bearer $OPENAI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "o3-deep-research",
    "input": "Research the economic impact of semaglutide on global healthcare systems. Include specific figures, trends, statistics, and measurable outcomes. Prioritize reliable, up-to-date sources: peer-reviewed research, health organizations (e.g., WHO, CDC), regulatory agencies, or pharmaceutical earnings reports. Include inline citations and return all source metadata. Be analytical, avoid generalities, and ensure that each section supports data-backed reasoning that could inform healthcare policy or financial modeling.",
    "tools": [
      { "type": "web_search_preview" }
    ],
    "reasoning": {
      "effort": "medium", 
      "summary": "auto"
    },
    "include": ["reasoning.encrypted_content"],
    "stream": true
  }'

AI SDK Version

No response

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

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy