Skip to content

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

ParameterTypeDescription
ctxContextRender context (provides the model + secrets).
optionsAgentOptions<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))});
  },
});

Matterway Assistant SDK Documentation