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

feat (rsc): multiple tool calls for streamUI #1904

Draft
wants to merge 14 commits into
base: main
Choose a base branch
from

Conversation

gclark-eightfold
Copy link
Contributor

@gclark-eightfold gclark-eightfold commented Jun 10, 2024

Summary

Adds the ability to invoke multiple tool calls for streamUI.

Addresses #1894, #1532 (comment)

NOTE: For usage with aiState, it's important to call aiState.done(...) only in the onFinish callback (if expecting multiple tool calls). -- Not sure if this is a breaking change.

Tasks

@gclark-eightfold gclark-eightfold changed the title feat: onFinish and multiple tool calls for streamUI feat (rsc): multiple tool calls for streamUI Jun 11, 2024
@bneigher
Copy link

#1894

@gclark-eightfold gclark-eightfold force-pushed the stream-ui-multiple-tool-calls branch from e15066d to cdcf506 Compare June 20, 2024 18:20
Comment on lines +288 to +292
if (wasPreviouslyText && (done || value.type !== 'text-delta')) {
const textNodeId = `text-${textNodeIndex}`;
if (!uiStreams[textNodeId]) {
throw new Error('Expected text node to exist');
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is it possible to have text intermixed with tool calling?
I was able to get text before tool calling, but trying to prompt at least the OpenAI agent to require a text response after tool calling did not seem to work.

If text nodes can only appear once and before tool calling, this can be simplified instead of trying to keep track of nodes being written.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Additionally, I noticed that with tool calling can come with a delay before the first chunk comes in for reader.read(). This had the unexpected effect of leaving out a last word or words of a text body that comes before tool calling and only shows up once the tool calls start streaming in.

@gclark-eightfold
Copy link
Contributor Author

@lgrammel LMK if you have any thoughts on this implementation.
You had mentioned previously that streamUI would be refactored eventually to match streamText / other patterns, so let me know if you think supporting this would be best to do after that change or before.

I've ad-hoc tested this in my own application and it does seem to work, though I've made a few comments on the implementation where things were maybe not as ideal.

@dutsik-p
Copy link

dutsik-p commented Jul 2, 2024

Hi Guys!
Any news on releasing this feature.

@syedgaian
Copy link

Hi guys any news on , when will this feature be released?

@gclark-eightfold
Copy link
Contributor Author

gclark-eightfold commented Jul 23, 2024

Hi guys any news on , when will this feature be released?

Haven't put this PR up for review because it's a bit buggy after updating it to the latest AI SDK version.
Currently getting these errors in my application I've patched with the changes in this PR:

  • Unexpected Fiber popped.
  • Detected multiple renderers concurrently rendering the same context provider. This is currently unsupported.
  • TypeError: Cannot read properties of null (reading 'children')

@gclark-eightfold
Copy link
Contributor Author

gclark-eightfold commented Jul 23, 2024

@lgrammel I reverted #2068 locally and tested on my application code and it fixed the issues described above.

Any idea how best to resolve this issue?

@artokun
Copy link

artokun commented Aug 4, 2024

Ah, I was wondering why my app kept hanging up. This would be awesome to get released

@edspencer
Copy link

I had the same requirement and ended up building a layer on top of streamText to do it. It sounds like this will be natively supported in the SDK at some point, but for the time being I think it's still something one needs to put together oneself.

Check out https://github.com/edspencer/stream-multi if you are interested - the little video there shows the ability to have the LLM respond with both streaming text and any number of tools calls.

I published it as a npm module called ai-stream-multi. It basically has the same API as streamText(), but adds the concept of Segments, which are either a Tool or Text, and of which there can be any number in a given response from the LLM. Use the onSegment callback to update the AIState.

Demo

@zzh8829
Copy link

zzh8829 commented Oct 10, 2024

link all the related discussion, a new implementation could fix all these problems together.
#2915
#1894
#1895
#1976
#2915

@zzh8829
Copy link

zzh8829 commented Oct 10, 2024

I created a similar version here but using the new streamText api as the plumbing.
#1895 (comment)

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.

7 participants