How to prevent some tool calls to be streamed while neatly saving everything in my db? #8551
Unanswered
peguerosdc
asked this question in
Help
Replies: 0 comments
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:tool1
andtool2
must not be streamed to the user. Instead, a generic "executing tool" message should be showntool3
must be streamed to the user.finalAgent
must be streamed to the userfinalAgent
is finished, the streaming stopsWhat I have found so far:
Option 1: use stream transformation
I can use the
streamText
function to code the agent pattern that I described above and useexperimental_transformStream
to filter the stream and remove the parts related totool1
andtool2
, 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 inonFinish
I can just have a dump of everything and pass it to asaveChat
function 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
createUIMessageStream
I could follow the multi-step agent example in the cookbox by:
createUIMessageStream
to create a useChat-compatible streamstreamText
, maybe with the openai sdk), make sure to stream the calls totool3
, and codefinalAgent
withstreamText
to 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-sdk
is the right tool for this?Beta Was this translation helpful? Give feedback.
All reactions