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

DefinedAgent.md

179 lines4.8 KB

1---
2id: DefinedAgent
3title: DefinedAgent
4---
5​
6Defined in: [packages/ai/src/activities/chat/agents/define-agent.ts:101](https://github.com/TanStack/ai/blob/main/packages/ai/src/activities/chat/agents/define-agent.ts#L101)
7​
8A named child agent. `run` is a `chat()` call (or any stream of AG-UI
9chunks), or a promise of a plain value such as an image result. A
10`chat({ stream: false })` result counts as its text.
11`TTools` and `TSchema` stay on the object so `useChat({ subagents })` can
12type that child's parts. `TResult` is the value a promise `run` resolves to.
13​
14## Extends
15​
16- `SubagentInfo`
17​
18## Type Parameters
19​
20### TName
21​
22`TName` *extends* `string` = `string`
23​
24### TTools
25​
26`TTools` *extends* `ReadonlyArray`\<`SubagentTool`\> = `ReadonlyArray`\<`SubagentTool`\>
27​
28### TSchema
29​
30`TSchema` *extends* [`SchemaInput`](../type-aliases/SchemaInput.md) \| `undefined` = [`SchemaInput`](../type-aliases/SchemaInput.md) \| `undefined`
31​
32### TInterrupts
33​
34`TInterrupts` *extends* `ReadonlyArray`\<[`InterruptDefinition`](InterruptDefinition.md)\<`any`, `any`, `any`, `any`\>\> = `ReadonlyArray`\<[`InterruptDefinition`](InterruptDefinition.md)\<`any`, `any`, `any`, `any`\>\>
35​
36### TInput
37​
38`TInput` *extends* [`SchemaInput`](../type-aliases/SchemaInput.md) \| `undefined` = `any`
39​
40### TResult
41​
42`TResult` = `unknown`
43​
44### TProduces
45​
46`TProduces` *extends* [`AgentProduces`](../type-aliases/AgentProduces.md) \| `undefined` = [`AgentProduces`](../type-aliases/AgentProduces.md) \| `undefined`
47​
48## Properties
49​
50### description
51​
52```ts
53description: string;
54```
55​
56Defined in: [packages/ai/src/activities/chat/agents/define-agent.ts:113](https://github.com/TanStack/ai/blob/main/packages/ai/src/activities/chat/agents/define-agent.ts#L113)
57​
58Required here: the router and the synthetic tool both read it.
59​
60#### Overrides
61​
62```ts
63AGUISubagentInfo.description
64```
65​
66***
67​
68### inputSchema?
69​
70```ts
71optional inputSchema?: TInput;
72```
73​
74Defined in: [packages/ai/src/activities/chat/agents/define-agent.ts:133](https://github.com/TanStack/ai/blob/main/packages/ai/src/activities/chat/agents/define-agent.ts#L133)
75​
76The input this agent needs, such as a short brief. `run` reads it as
77`ctx.input`, and the client card as `part.subagent.input`. In tool mode,
78the parent model writes it when it calls this agent's tool. Without it,
79the tool takes a text `prompt`. When the run uses `sessionId` or
80`background`, that name is reserved. A `subagents.router` gives it in
81its pick as `{ name, input }`. The input is checked against this schema
82first. A router can start this agent only when the schema is a Standard
83Schema, such as a zod schema. A plain JSON Schema works in tool mode
84only. A turn with a router input cannot resume after an interrupt.
85​
86***
87​
88### interrupts?
89​
90```ts
91optional interrupts?: TInterrupts;
92```
93​
94Defined in: [packages/ai/src/activities/chat/agents/define-agent.ts:135](https://github.com/TanStack/ai/blob/main/packages/ai/src/activities/chat/agents/define-agent.ts#L135)
95​
96***
97​
98### name
99​
100```ts
101name: TName;
102```
103​
104Defined in: [packages/ai/src/activities/chat/agents/define-agent.ts:111](https://github.com/TanStack/ai/blob/main/packages/ai/src/activities/chat/agents/define-agent.ts#L111)
105​
106Unique name or identifier of the subagent.
107​
108#### Overrides
109​
110```ts
111AGUISubagentInfo.name
112```
113​
114***
115​
116### outputSchema?
117​
118```ts
119optional outputSchema?: TSchema;
120```
121​
122Defined in: [packages/ai/src/activities/chat/agents/define-agent.ts:136](https://github.com/TanStack/ai/blob/main/packages/ai/src/activities/chat/agents/define-agent.ts#L136)
123​
124***
125​
126### produces?
127​
128```ts
129optional produces?: TProduces;
130```
131​
132Defined in: [packages/ai/src/activities/chat/agents/define-agent.ts:121](https://github.com/TanStack/ai/blob/main/packages/ai/src/activities/chat/agents/define-agent.ts#L121)
133​
134What this agent makes. See [AgentProduces](../type-aliases/AgentProduces.md).
135​
136***
137​
138### run
139​
140```ts
141run: (ctx) =>
142 | AsyncIterable<AGUIEvent, any, any>
143 | Promise<AsyncIterable<AGUIEvent, any, any>>
144| Promise<TResult>;
145```
146​
147Defined in: [packages/ai/src/activities/chat/agents/define-agent.ts:114](https://github.com/TanStack/ai/blob/main/packages/ai/src/activities/chat/agents/define-agent.ts#L114)
148​
149#### Parameters
150​
151##### ctx
152​
153[`SubagentRunContext`](../type-aliases/SubagentRunContext.md)\<`TInput`\>
154​
155#### Returns
156​
157 \| `AsyncIterable`\<[`AGUIEvent`](../type-aliases/AGUIEvent.md), `any`, `any`\>
158 \| `Promise`\<`AsyncIterable`\<[`AGUIEvent`](../type-aliases/AGUIEvent.md), `any`, `any`\>\>
159 \| `Promise`\<`TResult`\>
160​
161***
162​
163### subagents?
164​
165```ts
166optional subagents?: unknown;
167```
168​
169Defined in: [packages/ai/src/activities/chat/agents/define-agent.ts:137](https://github.com/TanStack/ai/blob/main/packages/ai/src/activities/chat/agents/define-agent.ts#L137)
170​
171***
172​
173### tools?
174​
175```ts
176optional tools?: TTools;
177```
178​
179Defined in: [packages/ai/src/activities/chat/agents/define-agent.ts:134](https://github.com/TanStack/ai/blob/main/packages/ai/src/activities/chat/agents/define-agent.ts#L134)