Cortex · API

asTool

asTool wraps an agent as a tool that another agent can call. The tool takes { input } and returns the nested agent’s data, or its response when it has no data; the nested run’s events are emitted on the parent run’s stream with a longer agentPath. Both agents’ turns are scripted; no model is called.

Agents
const programmeAgent = defineAgent({
  id: 'programme',
  description: 'Knows what plays on a night and how many seats are left.',
  instructions: 'Answer from the tools, in one sentence.',
  tools: [seatsLeft],
});

const desk = defineAgent({
  id: 'desk',
  instructions: 'Help the member. Ask the programme agent about shows and seats.',
  tools: [asTool(programmeAgent, { llm })],
});

const result = await desk.run('How many seats are left on Saturday?', { llm }).result;
Nested runs, turn by turn
Scripted model turn (desk)
calls programme {"input":"How many seats are left on 2026-10-24?"}
Events by agent path
['desk: tool-start programme']
Output matches the expected value

Runs in this page on the installed package. The input and the expected output are defined by the example.