AI Agents

Agent Swarm vs Pipeline: Which Architecture to Use and When

Swarms and pipelines are the two dominant multi-agent architectures. How they differ, when each one wins.

Building your first multi-agent system, you face an architectural choice that will define how the system scales, fails, and is debugged: do you connect agents in a pipeline, or do you let them operate in parallel as a swarm? Both patterns appear in production systems, both have legitimate use cases, and choosing the wrong one does not break your system outright - it just makes it harder to reason about, slower to debug, and more expensive to run than necessary. The choice comes down to whether your task is a sequence or a search.

Agent swarm
An agent swarm is a multi-agent architecture where multiple agents work simultaneously and independently on different aspects of the same goal, with their outputs aggregated by an orchestrator or synthesiser - contrasted with an agent pipeline, where agents execute sequentially and each agent's output is the next agent's input.

The short answer: pipeline vs swarm

A pipeline is a directed sequence of agents where each agent's output is the next agent's input. Work flows in one direction. Steps are ordered because each step depends on the previous one. A swarm is a set of agents that work simultaneously on different aspects of the same goal, coordinating through a shared state or an orchestrator that aggregates their outputs. Work is parallelised because steps are independent of each other.

Head-to-head comparison

Dimension Pipeline Swarm
Task structure Sequential, each step depends on previous Parallel, steps are independent
Latency Additive (step 1 + step 2 + step 3) Limited by slowest parallel agent
Debugging Straightforward - inspect each step's input/output Complex - parallel execution, race conditions
Cost Proportional to task length Proportional to task breadth × parallel agents
Failure handling One failure stops the chain One failure may not affect others
State management Each agent's output is the next agent's full context Shared state requires coordination
Best for Transform, refine, validate workflows Research, coverage, parallel execution

When to choose a pipeline

Choose the pipeline when the task has a natural sequence that cannot be reordered. The canonical signal: each step transforms the output of the previous step. If step 2 cannot start until step 1 is complete - not as a matter of architecture, but as a matter of logic - you have a pipeline.

Common pipeline use cases:

  • Content production: Research → Draft → Edit → SEO → Publish. Each step requires the previous output to exist and be complete.
  • Data processing: Extract → Normalise → Validate → Store. A corrupted record in normalisation must stop processing before it reaches storage.
  • Code generation workflows: Spec → Code → Test → Lint → PR description. Tests can only be written after the code exists.
// Pipeline: linear, each step receives previous step's output
async function runPipeline(input: string): Promise {
  const researched = await runAgent('researcher', input);
  const drafted = await runAgent('writer', researched);
  const edited = await runAgent('editor', drafted);
  const finalised = await runAgent('publisher', edited);
  return finalised;
}
// Total time: time(researcher) + time(writer) + time(editor) + time(publisher)

When to choose a swarm

Choose the swarm when the task involves coverage or breadth - when you want multiple agents exploring different aspects of the same problem simultaneously, and the goal is to synthesise their independent findings. The canonical signal: agents can start working immediately without waiting for any other agent's output.

Common swarm use cases:

  • Competitive research: Five agents simultaneously analyse five competitors. No agent needs another's output to start.
  • Multi-source data collection: Agents query different APIs or databases in parallel for different data types that all feed into one report.
  • Parallel validation: Multiple specialist agents each check a different aspect of the same artifact (security agent, performance agent, style agent reviewing the same PR).
  • Hypothesis testing: Multiple agents each explore a different hypothesis about a problem; an aggregator synthesises which hypothesis has the strongest evidence.
// Swarm: parallel, all agents start simultaneously
async function runSwarm(goal: string, agents: string[]): Promise {
  // All agents start at the same time
  const results = await Promise.all(
    agents.map(agentType => runAgent(agentType, goal))
  );

  // Synthesise parallel outputs
  return synthesise(goal, results);
}
// Total time: max(time(agent1), time(agent2)..., time(agentN)) + time(synthesise)

The hybrid: pipeline with parallel stages

Most real-world multi-agent systems are neither pure pipelines nor pure swarms. They are pipelines where some stages themselves run agents in parallel. A research-to-report workflow might have a sequential structure (plan → research → write → review) but a parallel research stage (five research agents working simultaneously on different sub-topics):

async function runHybrid(goal: string): Promise {
  // Sequential phase 1: planning
  const plan = await runAgent('planner', goal);
  const subtopics = parsePlan(plan); // Returns ['topic A', 'topic B', 'topic C']

  // Parallel phase 2: research
  const researchResults = await Promise.all(
    subtopics.map(topic => runAgent('researcher', topic))
  );

  // Sequential phase 3: synthesis
  const draft = await runAgent('writer', formatResearch(goal, researchResults));
  const final = await runAgent('editor', draft);

  return final;
}
// Total time: time(planner) + max(researcher×N) + time(writer) + time(editor)

This hybrid collapses the most expensive phase (research) from additive to parallel while keeping the steps that genuinely depend on sequence in their correct order.

Failure handling: the key difference

Pipeline failures are simple: one agent fails, the chain stops. This is appropriate when downstream steps cannot produce meaningful output without upstream input. Handle pipeline failures by catching at the pipeline level and deciding whether to retry from the failed step, skip it, or abort.

Swarm failures are more complex: one agent fails, others may continue. The aggregation step must handle partial results gracefully - not assume all agents will complete successfully. Design swarm aggregators to produce a meaningful partial output when some agents fail:

// Swarm aggregation with partial failure handling
const settled = await Promise.allSettled(
  agents.map(agentType => runAgent(agentType, goal))
);

const successful = settled
  .filter((r): r is PromiseFulfilledResult => r.status === 'fulfilled')
  .map(r => r.value);

const failed = settled.filter(r => r.status === 'rejected').length;

if (successful.length === 0) {
  throw new Error('All swarm agents failed');
}

// Synthesise from whatever succeeded
const result = await synthesise(goal, successful);
if (failed > 0) {
  return `${result}

[Note: ${failed} agent(s) failed to complete - results may be incomplete]`;
}
return result;

Decision guide

Use this three-question heuristic:

  1. Can any agent start before another finishes? If no - pipeline. If yes - candidate for swarm.
  2. Does each agent need the previous agent's output to do its job? If yes - pipeline. If no - swarm.
  3. Is coverage or transformation the goal? Coverage (explore broadly, synthesise) → swarm. Transformation (refine, validate, format) → pipeline.

When in doubt, start with a pipeline. Pipelines are easier to implement correctly, easier to debug, and easier to explain. Refactor to a swarm when profiling reveals that latency is dominated by a sequential stage that could run in parallel - not before.

Both swarms and pipelines can incorporate the supervisor pattern for orchestration - the supervisor manages routing in either architecture. For understanding how individual agents in a swarm or pipeline handle their internal execution, see the agentic loop explained.