Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modify smoothStream transform to support tool call streams #5326

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

kac487
Copy link

@kac487 kac487 commented Mar 22, 2025

Extends the smoothStream transform to handle both text and tool call streaming:

  • Add separate buffers for text and tool call arguments
  • Special handling for tool-related chunk types (tool-call, tool-call-delta, tool-result)
  • Add buffer flushing logic for various stream states
  • Implement TransformStream flush method to handle remaining content
  • Keep consistent chunking behavior across both text and tool call streams

Extends the smoothStream transform to handle both text and tool call streaming:
- Add separate buffers for text and tool call arguments
- Special handling for tool-related chunk types (tool-call, tool-call-delta, tool-result)
- Add buffer flushing logic for various stream states
- Implement TransformStream flush method to handle remaining content
- Keep consistent chunking behavior across both text and tool call streams
@lgrammel
Copy link
Collaborator

Please run pnpm prettier-fix to clean up the diff.

@lgrammel
Copy link
Collaborator

lgrammel commented Mar 26, 2025

There are some bugs. Can you add test cases as a first step?

Once this is bug-free there will also need to be some refactoring.

Finally, this feature should be opt in using a flag e.g. smoothToolCalls which default to false.

Comment on lines +147 to 154
if (toolCallBuffer && toolCallBuffer.buffer.length > 0) {
controller.enqueue({
type: 'tool-call-delta',
toolCallId: toolCallBuffer.id,
toolName: toolCallBuffer.name,
argsTextDelta: toolCallBuffer.buffer,
});
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bug: what if there are several ongoing tool calls?

Comment on lines +73 to +79
controller.enqueue({
type: 'tool-call-delta',
toolCallId: toolCallBuffer.id,
toolName: toolCallBuffer.name,
argsTextDelta: toolCallBuffer.buffer,
});
toolCallBuffer = null;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bug: what if there are several ongoing tool calls?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants