Skip to content

[bug] smoothStream: tool calls emitted mid-response #13199

Description

@mindplay-dk

Description

I tested this:

async function loop() {
  console.log("Enter a message or press ENTER to quit...\n\n");

  const messages: ModelMessage[] = [];

  while (true) {
    const input = await prompt.input("😏");

    if (input === "") {
      break; // quit
    }

    messages.push({ role: "user", content: input });

    process.stdout.write("> 🤖 ");

    const result = await agent.stream({
      messages,
      experimental_transform: [smoothStream({ delayInMs: 50, chunking: "word" })],
    });

    for await (const text of result.textStream) {
      process.stdout.write(text);
    }

    messages.push(...(await result.response).messages);

    process.stdout.write("\n\n");
  } // loop
}

This does not work well - I'm seeing output like this:

? 😏 replace "Sunny" with "Rainy" in hello.txt
> 🤖 
I'll {
  path: 'hello.txt',
  rootPath: '/home/mindplay/workspace/agent-cooper',
  targetPath: '/home/mindplay/workspace/agent-cooper/hello.txt',
  offset: undefined,
  limit: undefined
}
help you replace "Sunny" with "Rainy" in hello.txt. First, let me read the file to see its current contents.

Now { path: 'hello.txt', old_str: 'Sunny', new_str: 'Rainy' }
I can see the file contents. I'll replace "Sunny" with "Rainy":

Done! I've successfully replaced "Sunny" with "Rainy" in hello.txt. The file now contains:

```
One
Rainy
Day
```

Those objects are console.log messages from the tools.

It looks like the tool calls are being emitted mid-response.

It's not the LLM - I can look in the AI SDK devtools, and it doesn't look broken up like this.

Commenting out the smoothStream transform fixes the issue.

Could it be the specific options I'm passing? I'm just going to disable it for now.

AI SDK Version

@ai-sdk/devtools@0.0.15
@openrouter/ai-sdk-provider@2.2.5
ai@6.0.116

Code of Conduct

  • I agree to follow this project's Code of Conduct

Metadata

Metadata

Assignees

No one assigned

    Type

    Fields

    No fields configured for Bug.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions