How to prevent some tool calls to be streamed while neatly saving everything in my db? #8551
Replies: 1 comment
-
|
This discussion was automatically locked because it has not been updated in over 30 days. If you still have questions about this topic, please ask us at community.vercel.com/ai-sdk |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hi! I have developed an agent using openai-agents-js that looks like this:
(I am not attached to using the openai's sdk, but I thought it was a simple way of explaining my goal)
And I want to integrate it with ai-sdk mostly to use the rich features of
useChat. Figuring out how to code that pattern using ai-sdk is easy, but I have some particular requirements that I'm not sure how to achieve:tool1andtool2must not be streamed to the user. Instead, a generic "executing tool" message should be showntool3must be streamed to the user.finalAgentmust be streamed to the userfinalAgentis finished, the streaming stopsWhat I have found so far:
Option 1: use stream transformation
I can use the
streamTextfunction to code the agent pattern that I described above and useexperimental_transformStreamto filter the stream and remove the parts related totool1andtool2, as suggested in the documentation:My concerns are:
tool3, would I have to understand, code and maintain all the Stream Protocols details?onFinish, making it problematic to store them in a database as exemplified in the chats sdk, being in direct conflict with requirement 5. Why would it be problematic? Because inonFinishI can just have a dump of everything and pass it to asaveChatfunction without having to worry about the order of things, which could be a problem if the data is spread in different variables.Option 2: use
createUIMessageStreamI could follow the multi-step agent example in the cookbox by:
createUIMessageStreamto create a useChat-compatible streamstreamText, maybe with the openai sdk), make sure to stream the calls totool3, and codefinalAgentwithstreamTextto merge the streams and make it available to the userMy concerns are similar to option 1:
tool3, would I have to understand, code and maintain all the Stream Protocols details? This seems to be a lot of work and error-prone.onFinish, making it problematic to store everything in a database.Any suggestions?
I was hoping someone could give me some suggestions on how to achieve this or feedback on my requirements. Some thoughts that I'm having:
onFinish(or by not usingstreamText) because from the chatbot example, it seems that it's important to save everything in the DB to load it back easily to display the chat history to the user. Does this make sense?parts?ai-sdkis the right tool for this?Beta Was this translation helpful? Give feedback.
All reactions