Skip to content

TanStack AI Integration

Christian Pojoni edited this page May 2, 2026 · 1 revision

TanStack AI Integration

The package exposes routing and worker execution as TanStack AI server tools.

Router tool

import {
  createSubagentRouter,
  createSubagentRouterTool,
} from '@5queezer/tanstack-ai-subagents'

const route = createSubagentRouter({
  intents: {
    incident: ['incident', 'outage', 'sev1'],
  },
})

export const routeTool = createSubagentRouterTool({ router: route })

Without a custom router, createSubagentRouterTool() uses the default deterministic router.

Run tool

import { chat } from '@tanstack/ai'
import { createRunSubagentsTool } from '@5queezer/tanstack-ai-subagents'

export const runTool = createRunSubagentsTool({
  chat,
  getAdapter: getChatModel,
  tools,
  profiles,
  maxWorkers: 4,
})

run_subagents only executes when the routing action allows it:

  • spawn_one_specialist
  • spawn_multiple_specialists

Other actions are rejected before worker execution.

Tools

The package does not ship concrete worker tools. Your app owns the tool registry.

const tools = {
  github_search: githubSearch,
  github_get: githubGet,
  test_runner: testRunner,
}

Worker briefs reference tools by name. If a worker asks for a missing or nullish tool implementation, validation fails before the worker runs.

Profiles

Profiles define reusable worker capabilities.

const profiles = {
  verify: {
    toolNames: ['test_runner'],
    systemPrompt: 'Verify the assigned task and report exact commands and evidence.',
    model: 'provider/verification-model',
  },
}

A worker can use profile: 'verify' instead of listing toolNames directly.

Worker limits

  • spawn_one_specialist requires exactly one worker.
  • spawn_multiple_specialists requires at least two workers.
  • Default maximum: four workers.
  • Override with maxWorkers.
createRunSubagentsTool({
  chat,
  getAdapter,
  tools,
  maxWorkers: 8,
})

Lifecycle callbacks

Lifecycle callbacks are observability hooks. Callback failures are ignored so they cannot change worker outcomes.

createRunSubagentsTool({
  chat,
  getAdapter,
  tools,
  onWorkerStart: (brief) => logStart(brief),
  onWorkerFail: (brief, error) => logFailure(brief, error),
  onWorkerFinish: (result, brief) => logFinish(brief, result),
})

Clone this wiki locally