Build a multi-agent research app in React with TanStack AI TanStack released TanStack AI 1.0, the first stable version of its AI library, adding subagents, tool approvals and chat compaction plus 23 provider adapters for OpenAI, Anthropic, Gemini and OpenRouter. In a side-by-side build of a two-agent "Library Scout" research app, the TanStack version took 272 lines of code versus 229 for Vercel's AI SDK 7 (ai 7.0.162), with the author installing @tanstack/ai 1.1.0 and running the openai/gpt-6-luna model through OpenRouter. The author reported that setting maxCompletionTokens to 300 let gpt-6-luna spend all 300 tokens on hidden reasoning and return no answer, so every call sets reasoning: 'off'. TanStack AI 1.0 https://tanstack.com/blog/tanstack-ai-1-0 is out, and it is the first stable version of TanStack’s AI library. The release also brings a few big features. Subagents let one chat hand work to other agents, tool approvals make the app ask you before a tool runs, and compaction trims long chats so they stay within the model’s limit. It also has 23 provider adapters, so the same code can talk to OpenAI, Anthropic, Gemini, OpenRouter, and others. To see if these features are valid, I built an app called Library Scout https://github.com/marvelken/Multi-Agent-Research-TanStack . It answers a question every React developer asks too often: which library should I use? Normally that means googling, opening npm, checking downloads, checking React support, checking the size, and then picking the one with the nicest logo anyway. Library Scout does the boring part for you. The first Agent researcher pulls real numbers from npm, and a second agent, the writer, reads them and recommends one library. You stay in charge because the app asks for your permission before it searches. I also built the same app with Vercel’s AI SDK 7, so we can compare them side by side. TanStack did not save me code, because it took 272 lines against 229 for the AI SDK. But it gave me features the AI SDK could not match, and I will show you what worked and what broke. The full code for both apps is in this GitHub repo https://github.com/marvelken/Multi-Agent-Research-TanStack , so you can check any file as we go. You do not need a fancy setup to follow along. Here is what I used: First, let us create a new React app. The TanStack https://blog.logrocket.com/tanstack-markdown-vs-react-markdown/ CLI sets up the project for us, and then we add the AI packages the app needs. Run these in your terminal: npx @tanstack/cli@latest create library-scout --framework React --package-manager pnpm --blank cd library-scout pnpm add --save-exact @tanstack/ai @tanstack/ai-react @tanstack/ai-client @tanstack/ai-openrouter zod Put your key in a .env file as OPENROUTER API KEY . These commands installed @tanstack/ai 1.1.0 for me, and the AI SDK version used ai 7.0.162. Both apps use the openai/gpt-6-luna model through OpenRouter. To keep costs favorable, I gave every model call a limit on how long its reply can be, using maxCompletionTokens . The problem is that gpt-6-luna likes to think quietly before it answers, and that hidden thinking counts toward the same limit. In one test, I set the limit to 300 tokens, and the model spent all 300 thinking. It thought very hard and then said nothing at all. That is why every call in this app also sets reasoning: 'off' , which you will see in the code below. Our agents need two tools that call free npm endpoints. searchNpm finds packages, and getPackageStats gets the numbers for one package. The two functions that call npm live in src/lib/npm.ts , which you can copy from the repo. In the file src/lib/tools.ts , I define the tools there. This file has no server code, so the browser can use it too. Here is the search tool, the only one that needs your approval, and getPackageStatsDef sits below it in the same file: js export const searchNpmDef = toolDefinition { name: 'searchNpm', description: 'Search the npm registry. Returns package names, versions and descriptions.', inputSchema: z.object { query: z.string .describe 'Search words, for example "react toast"' } , needsApproval: true, } Next, I created src/lib/tools.server.ts . This file connects each tool to the function that does the work on the server: js export const searchNpmTool = searchNpmDef.server searchNpm I went ahead to create src/routes/api.chat.ts . This is the server route the chat talks to. It sends the messages to the model and streams the reply back to the browser: js POST: async { request } = { const params = await chatParamsFromRequest request const stream = chat { adapter: openRouterText MODEL MAIN , modelOptions: { maxCompletionTokens: 800 }, reasoning: 'off', messages: params.messages, threadId: params.threadId, runId: params.runId, } return toServerSentEventsResponse stream }, Now for the fun part. Each subagent has two pieces, and each piece gets its own file. I created src/lib/agents.ts for the first piece, a plain description of each agent’s name, job, tools, and input. It has no server code, so the browser can import it. The writer sits below the researcher in the same file: js export const researcher = { name: 'researcher', description: 'Researches npm packages for one focused task and returns findings with package names and real numbers.', inputSchema: z.object { task: z.string .describe 'What to research. The researcher sees only this text.' , } , tools: searchNpmDef, getPackageStatsDef , } as const Then I created src/lib/agents.server.ts for the second piece. Here, defineAgent adds a run function that calls the model on the server. The writer gets the same treatment in this file, and the prompts are in the repo: js export const researcherAgent = defineAgent { ...researcher, run: ctx = chat { adapter: openRouterText MODEL MAIN , modelOptions: { maxCompletionTokens: 1000 }, reasoning: 'off', systemPrompts: RESEARCHER PROMPT , // On a resume, ctx.messages holds the child's own paused tool call. Without it the resume fails. messages: ctx.resume ? ctx.messages : { role: 'user', content: ctx.input.task } , tools: searchNpmTool, getPackageStatsTool , ...ctx.forward, // threadId, runId, parentRunId, subagentRunId, resume, abortController } , } The lead does not need its own file, because it is just the chat call in our route. Open src/routes/api.chat.ts to see where I added the subagents and some limits to that chat call: subagents: { agents: researcherAgent, writerAgent , limits: { maxDepth: 1, maxConcurrent: 2, maxCalls: 4, timeoutMs: 120 000 }, }, The limits line lets the lead go one level deep, run two subagents at once, make four subagent calls per request, and give each one two minutes. I also checked the final browser bundle, and none of the prompts or server code leaked into it. That one line is my favorite thing in TanStack AI. Here is what I wrote by hand for a smaller version in the AI SDK app. All of its agent code lives in one file, baseline-ai-sdk/src/lib/agents.server.ts in the repo, and each tool must also call countChildCall : js let childCalls = 0 const countChildCall = = { if ++childCalls 4 throw new Error 'child limit reached 4 per request ' } // ... stopWhen: stepCountIs 6 , // ... function withChildLimits abortSignal: AbortSignal | undefined { const timeout = AbortSignal.timeout 120 000 return abortSignal ? AbortSignal.any abortSignal, timeout : timeout } The AI SDK has no separate subagent API, so you call an agent from inside a tool, and streamChild is another helper I wrote: js const researcherTool = tool { description: 'Researches npm packages for one focused task and returns findings with package names and real numbers.', inputSchema: z.object { task: z.string .describe 'What to research. The researcher sees only this text.' } , execute: async function { task }, { abortSignal } { countChildCall yield streamChild researcher, task, abortSignal }, toModelOutput: { output } = { type: 'text', value: lastText output } , } So did it work? Yes. When I asked which toast library suits a small dashboard, the lead called the researcher and then the writer in every completed run, and every download number in the answers matched npm. On the browser side, useChat does most of the work. I created src/routes/chat.$chatId.tsx , where $chatId puts the chat ID in the URL. That ID becomes the threadId , so each conversation keeps its own history, and the agent descriptions give us types. Each subagent arrives as a message part with the type 'subagent' , and we render a card for it: const { messages, sendMessage, isLoading, stop, subagents, interrupts, resuming } = useChat { connection: fetchServerSentEvents '/api/chat' , threadId: chatId, subagents: scoutAgents, // declarations only: used for types, never run in the browser tools: searchNpmDef , // types the approval interrupt for the child's searchNpm call } // ... if part.type === 'text' return