Appearance
Function: agent()
ts
function agent<S>(ctx: Context, options: AgentOptions<S>): Promise<string | output<S>>;Defined in: packages/sdk/src/renderer/templates/agent.ts:113
Run a specialized subagent and return its result. Usually reached as the agent run-option inside a tool's execute (already bound to ctx); the standalone form takes ctx explicitly.
Type Parameters
| Type Parameter |
|---|
S extends ZodType<unknown, unknown, $ZodTypeInternals<unknown, unknown>> |
Parameters
| Parameter | Type | Description |
|---|---|---|
ctx | Context | Render context (provides the model + secrets). |
options | AgentOptions<S> | The subagent configuration. |
Returns
Promise<string | output<S>>
Example
ts
const draftPlan = tool({
description: 'Draft an editable plan for a task',
inputSchema: z.object({task: z.string()}),
execute: async ({task}, {agent}) => {
const steps = await agent({
prompt: `Break "${task}" into 3–6 concrete steps.`,
output: z.array(z.string()),
});
return plan({title: task, steps: steps.map((s) => step(s))});
},
});