AgentsAgentChain

AgentChain

AgentChain orchestrates several sub-agents in sequence, piping each step’s output into the next. It’s the right tool when a workflow has distinct phases that must run in order.

const chain = new AgentChain([
  { subAgent: findBestPrice, input: 'office chairs, qty 10' },
  { subAgent: requestApproval, inputFrom: (prev) => prev.answer },
  { subAgent: checkoutAndTrack, inputFrom: (prev) => prev.answer },
]);
 
const result = await chain.run();

Output piping with inputFrom

Each step after the first uses inputFrom to derive its input from the previous step’s result. This is how the chain passes a found cart into an approval step, then the approved cart into checkout.

Halt-on-failure and usage aggregation

  • The chain halts on the first failure — a failed step stops the chain rather than feeding bad output downstream.
  • It aggregates token usage across steps, so you get a single usage total for the whole workflow.

Cloud rendering

Because each step runs its sub-agent through runSubAgent, the spans carry parent_span_id and sub_agent_name. The Agorio Cloud trace explorer renders the chain as a tree, making multi-step procurement flows easy to inspect. The reference procurement example (examples/procurement/ in the repository) chains find-best-price → request-approval → checkout-and-track over three mock merchants with all governance plugins active.