Skip to content
Source
Sign inSign up
TanStack/ai
Open History to see the last commit

subagentRoute.md

63 lines1.5 KB

1---
2id: subagentRoute
3title: subagentRoute
4---
5​
6```ts
7function subagentRoute<TAgents>(agents, options?): object;
8```
9​
10Defined in: [packages/ai/src/activities/chat/agents/route.ts:53](https://github.com/TanStack/ai/blob/main/packages/ai/src/activities/chat/agents/route.ts#L53)
11​
12Build `decide()` questions for a subagent router.
13​
14One yes/no question per agent, plus an `order` choice.
15`pick` returns `main`, one name, `{ names, order }`, or `{ steps }`.
16Names follow the `agents` array order.
17`{ names, order }` overrides `subagents.order` for that turn.
18`then`: agents that run after the other selected agents. The lead group
19starts together. The `then` agents then run one after another in list
20order, and each reads the text so far. Used only when the router picks at
21least one agent from each group. Otherwise `pick` returns `{ names, order }`.
22​
23## Type Parameters
24​
25### TAgents
26​
27`TAgents` *extends* readonly [`DefinedAgent`](../interfaces/DefinedAgent.md)\<`string`, readonly `SubagentTool`[], [`SchemaInput`](../type-aliases/SchemaInput.md) \| `undefined`, readonly [`InterruptDefinition`](../interfaces/InterruptDefinition.md)\<`any`, `any`, `any`, `any`, `any`\>[]\>[]
28​
29## Parameters
30​
31### agents
32​
33`TAgents`
34​
35### options?
36​
37[`SubagentRouteOptions`](../interfaces/SubagentRouteOptions.md)\<`TAgents`\>
38​
39## Returns
40​
41`object`
42​
43### pick
44​
45```ts
46pick: (result) => SubagentRouterPick;
47```
48​
49#### Parameters
50​
51##### result
52​
53`RouteAnswers`\<`TAgents`\>
54​
55#### Returns
56​
57[`SubagentRouterPick`](../type-aliases/SubagentRouterPick.md)
58​
59### questions
60​
61```ts
62questions: RouteQuestions<TAgents>;
63```