workflows/chain¶
Source: src/workflows/chain.ts
chain: 1 → 1 → 1. The output of step n is the input of step n+1.
chain¶
function
export async function chain(options: ChainOptions): Promise<WorkflowResult> { /* … */ }
Runs the agents in sequence, feeding each one the previous output.
Lifetime is the whole point of this combinator:
"task": one spawn per step. Every step reads the code afresh, with no accumulated bias, and pays to re-read it."workflow": one spawn per distinct agent, reused when it comes back. The reviewer does not repeat its remarks, the coder remembers what it was told. This is the “team” regime.
A failing step stops the chain - there is no input left for the next one -
and its Result is returned as is. The workflow itself never throws.
Whoever opens, closes: every subagent this function spawned is closed in the
finally, cancellation included.
ChainOptions¶
type
export type ChainOptions = WorkflowOptions & {
/** The agents to run, in order. The same agent may appear several times. */
steps: Agent[];
/** The task given to the first step. */
input: string;
};
What a chain needs: the agents, in order, and the task for the first one.