ai icon indicating copy to clipboard operation
ai copied to clipboard

streamText + web search tools outputs each chunk as a separate text part

Open nikitatome opened this issue 1 year ago • 2 comments

Description

When I use the web search tool in combination with streamText it seems that each output chunk is an individual text part, instead of being concatenated together into a single text part. We do not have this issue with generateText. This issue adds unnecessary overhead to rendering and persistence.

An example output:

      {
        "text": "Here are the latest tech news highlights from this week (July 21-23, 2025):\n\n## Major AI & Tech Developments\n\n**AI Market Surge**: ",
        "type": "text"
      },
      {
        "text": "Nvidia became the world's first $4 trillion company as its stock surged on AI demand",
        "type": "text"
      },
      {
        "text": ", underscoring Wall Street's confidence in AI technology.\n\n**UK AI-Powered Traffic Enforcement**: ",
        "type": "text"
      },
      {
        "text": "UK police have begun deploying AI-enabled cameras to detect drivers illegally using phones or failing to wear seatbelts. The cameras use machine learning to flag violations in real time and have already caught thousands during trials.",
        "type": "text"
      },
      {
        "text": "\n\n**Yahoo Japan's AI Mandate**: ",
        "type": "text"
      },

AI SDK Version

  • ai: 5.0.0-beta.25

nikitatome avatar Jul 23 '25 16:07 nikitatome

most likely a won't fix because this is how openai produces the text parts and changing it can lead to issues with multi step chats

lgrammel avatar Jul 24 '25 08:07 lgrammel

Identify issue type

Identified type: Feature
Confidence: Medium

Rationale: The issue requests/ implies a behavior change to merge or normalize streamed text parts for ergonomics/performance, but does not show a documented contract being violated or a concrete failure. Maintainer clarification indicates the behavior reflects provider output rather than an SDK bug.

Evidence:

  • Reporter says streamText with web search tools returns each output chunk as an individual text part rather than concatenating into one text part.
  • Reporter notes generateText does not show the same behavior and says the current output adds rendering and persistence overhead.
  • Maintainer comments this is likely won't-fix because it is how OpenAI produces the text parts and changing it could cause issues with multi-step chats.

lgrammel avatar Jul 02 '26 09:07 lgrammel