Open History to see the last commit
1---
2id: defineAgent
3title: defineAgent
4---
5
6```ts
7function defineAgent<TName, TTools, TSchema, TInterrupts, TInput, TResult, TProduces>(agent): DefinedAgent<TName, TTools, TSchema, TInterrupts, TInput, TResult, TProduces>;
8```
9
10Defined in: packages/ai/src/activities/chat/agents/define-agent.ts:171
11
12Define a named child agent. Pass the same object to `chat({ subagents })`.
13Pass the agents array to `useChat({ subagents })` when you render parts
14yourself. The hook uses it for types only. It does not call `run`.
15
16## Type Parameters
17
18### TName
19
20`TName` *extends* `string`
21
22### TTools
23
24`TTools` *extends* readonly `SubagentTool`[] = readonly \[\]
25
26### TSchema
27
28`TSchema` *extends* [`SchemaInput`](../type-aliases/SchemaInput.md) \| `undefined` = `undefined`
29
30### TInterrupts
31
32`TInterrupts` *extends* readonly [`InterruptDefinition`](../interfaces/InterruptDefinition.md)\<`any`, `any`, `any`, `any`, `any`\>[] = readonly \[\]
33
34### TInput
35
36`TInput` *extends* [`SchemaInput`](../type-aliases/SchemaInput.md) \| `undefined` = `undefined`
37
38### TResult
39
40`TResult` = `unknown`
41
42### TProduces
43
44`TProduces` *extends* [`AgentProduces`](../type-aliases/AgentProduces.md) \| `undefined` = `undefined`
45
46## Parameters
47
48### agent
49
50[`DefinedAgent`](../interfaces/DefinedAgent.md)\<`TName`, `TTools`, `TSchema`, `TInterrupts`, `TInput`, `TResult`, `TProduces`\>
51
52## Returns
53
54[`DefinedAgent`](../interfaces/DefinedAgent.md)\<`TName`, `TTools`, `TSchema`, `TInterrupts`, `TInput`, `TResult`, `TProduces`\>
55
56## Example
57
58```ts
59const researcher = defineAgent({
60 name: 'researcher',
61 description: 'Looks up facts',
62 run: (ctx) =>
63 chat({
64 adapter: openaiText('gpt-6.1-sol'),
65 messages: ctx.messages,
66 threadId: ctx.threadId,
67 runId: ctx.runId,
68 parentRunId: ctx.parentRunId,
69 subagentRunId: ctx.subagentRunId,
70 resume: ctx.resume,
71 }),
72})
73```