I want to have two agents: Joke Selection Agent and Joke Generation Agent.
Joke Selection Agent will ask Joke Generation Agent to generate 5 jokes then Joke Selection Agent will choose the best one.
I want to display the chat output of both the agents in the UI so I was thinking of making both agents have their own API routes and use useChat for both of them. But then it becomes complicated trying to send the output of one agent which is in the UI stream into the tool response for another agent. Has anyone any advice on how to perform multi-agent workflows in Vercel AI SDK.
Hi, I saw further now that in the v6 SDK there is mention of implementing the Agent interface to create an agent that can handle multi-agent workflows. Any guidance on that or should I read how ToolLoopAgent is implemented in the repo? AI SDK 6 Beta
This sort of setup is easier with the new Workflows DevKit, here’s an example of an evaluator pattern
Otherwise –
I’d recommend using a single API route for the useChat endpoint, since keeping the streams straight is the hardest part.
You can use ToolLoopAgent directly and just give it the requirements for 5 jokes with passing evaluations. As long as it has enough tools to generate a new joke and to evaluate one it will continue until the requirements are met
I was wondering since generateText and streamText etc. can do multi-step reasoning and tool calling steps like agents, can we also stream their reasoning and toolcalling steps like working with agents in useChat? Except generateText/streamText doesn’t have a nice useChat hook that comes with it for me to display their reasoning and tool calls. How should I implement this?