Parallel
Run a fixed set of named branches at once on the same input.
.parallel() sends the same input to a fixed object of named branches and runs
them concurrently. Its output is an object keyed by branch name.
import { Agent } from "@nylorun/agents";
export const review = Agent({ id: "review" })
.parallel(
{ security: securityReviewer, style: styleReviewer, tests: testAuditor },
{ id: "checks" },
)
.pipe(summarizer);Use .parallel() when the number and names of branches are known while you
write the flow. Each branch can be an agent, an HTTP tool, a flow agent or a
flow(). The example produces:
{
security: securityResult,
style: styleResult,
tests: testResult,
}The next stage receives the whole object. Tell its agent, in its instructions, that it gets one result per branch.
Branch names key the output; each agent keeps the session named by its own id.
The same agent in two branches needs a second id:
{ a: reviewer, b: reviewer.withId("reviewer-b") }.
If one branch fails, the others are cancelled and the stage fails with the failing agent's path. All branches share the Agent the flow session runs on. Cancelling the flow cancels active branches; completed work stays checkpointed.
See the shipped parallel example.
Use Map instead when the branch count comes from input data.