UNPKG

@tanstack/ai

Version:

Type-safe TypeScript AI SDK for streaming chat, tool calling, agents, structured outputs, and multimodal generation.

54 lines (53 loc) • 2.17 kB
import { boolean, choice } from '../../evaluate/index.js'; import { DefinedAgent } from './define-agent.js'; import { SubagentOrder, SubagentRouterPick } from './spawn.js'; export interface SubagentRouteOptions<TAgents extends ReadonlyArray<DefinedAgent>> { /** * Question text for every agent. The key is the agent name. * Omit this and each question uses that agent's description. */ when?: { [K in TAgents[number]['name']]: string; }; /** * Agents that run after the other selected agents. The lead group starts * together. The `then` agents then run one after another in list order, and * each reads the text so far. Used only when the router picks at least one * agent from each group. Otherwise `pick` returns `{ names, order }`. */ then?: ReadonlyArray<TAgents[number]['name']>; } type RouteQuestions<TAgents extends ReadonlyArray<DefinedAgent>> = { [K in TAgents[number]['name']]: ReturnType<typeof boolean>; } & { order: ReturnType<typeof choice<{ parallel: string; sequence: string; }>>; }; type RouteAnswers<TAgents extends ReadonlyArray<DefinedAgent>> = { [K in TAgents[number]['name']]: { value: boolean; }; } & { order: { value: SubagentOrder; }; }; /** * Build `decide()` questions for a subagent router. * * One yes/no question per agent, plus an `order` choice. * `pick` returns `main`, one name, `{ names, order }`, or `{ steps }`. * Names follow the `agents` array order. * `{ names, order }` overrides `subagents.order` for that turn. * `then`: agents that run after the other selected agents. The lead group * starts together. The `then` agents then run one after another in list * order, and each reads the text so far. Used only when the router picks at * least one agent from each group. Otherwise `pick` returns `{ names, order }`. */ export declare function subagentRoute<const TAgents extends ReadonlyArray<DefinedAgent>>(agents: TAgents, options?: SubagentRouteOptions<TAgents>): { questions: RouteQuestions<TAgents>; pick: (result: RouteAnswers<TAgents>) => SubagentRouterPick; }; export {};