Next.js Discord

Discord Forum

AI SDK with streaming + tool calls?

Unanswered
Cuckoo wasp posted this in #help-forum
Open in Discord
Cuckoo waspOP
I haven't been able to find any examples of using the Vercel AI SDK with both streaming and tool calls enabled at the same time.
For example, I'm currently using the SDK as such in a server action: (with streamText)
  const cont = async (messages: any[]) => {
    const stream = createStreamableValue();
    (async () => {
      const { textStream } = await streamText(
        {
          model: openai('gpt-4o'),
          messages,
        });
      for await (const delta of textStream) stream.update(delta);
      stream.done();
    })();
    return stream.value;
  };

  return cont(m);


and this works for streaming text content. But if I include an argument tools within the streamText call, it is totally silent when it tries to call the tools, and I can't seem to get access to it.
Is streamText at all compatible with tool calling? (Given that it seems natural that if a tool is not called, I should just be able to stream the textContent response)

0 Replies