SubAgent
A SubAgent wraps a ShoppingAgent so it can be invoked as a reusable building block by a
parent agent or by an AgentChain. It’s defined as:
const findBestPrice: SubAgent = {
name: 'find-best-price',
description: 'Find the cheapest matching product across merchants',
build: (ctx) => new ShoppingAgent({ llm: ctx.llm, merchants: ctx.merchants }),
// optional input schema for validation / tool registration
inputSchema: { /* … */ },
};Running a sub-agent
runSubAgent executes one sub-agent and threads the parent’s observability through to the child:
const result = await runSubAgent({
subAgent: findBestPrice,
input: 'wireless headphones under $200',
parentTracer,
parentOnLog,
parentDepth: 0,
maxDepth: 3,
});Child spans are tagged with parent_span_id and sub_agent_name, so in the
Agorio Cloud trace explorer a multi-agent run renders as a tree — you can see exactly
which sub-agent produced which spans.
Depth guard
When you wire sub-agents into a parent ShoppingAgent via the subAgents option, the agent
auto-registers an invoke_sub_agent tool with a depth-3 recursion guard, so sub-agents calling
sub-agents can’t recurse without bound.