Blog/AI Automation/Multi-Agent Orchestration Patterns
POST
October 01, 2025
LAST UPDATEDOctober 01, 2025

Multi-Agent Orchestration Patterns

Explore multi-agent orchestration patterns with LangGraph and CrewAI. Learn supervisor, sequential, and parallel architectures for complex AI workflows.

Tags

AIMulti-AgentLangGraphCrewAIOrchestration
Multi-Agent Orchestration Patterns
6 min read

Multi-Agent Orchestration Patterns

This is Part 7 of the AI Automation Engineer Roadmap series.

TL;DR

Multi-agent orchestration coordinates specialized AI agents to tackle complex tasks that exceed the capability of any single agent working alone. The three core patterns -- supervisor, pipeline, and swarm -- each solve different coordination challenges, and frameworks like LangGraph, CrewAI, and PydanticAI provide the building blocks to implement them.

Why This Matters

In Part 5: Building AI Agents with Tool Calling, we built agents that could reason and act autonomously. In Part 6: Model Context Protocol, we gave those agents standardized access to external systems. But a single agent, no matter how capable, has fundamental limits.

Consider building an AI-powered code review system. One agent needs to understand the codebase architecture. Another needs to check for security vulnerabilities. A third should verify test coverage. A fourth should assess performance implications. Trying to stuff all of that expertise into a single agent's prompt leads to context window bloat, confused prioritization, and degraded output quality.

Multi-agent systems solve this by decomposing complex tasks into specialized roles. Each agent focuses on what it does best, and an orchestration layer coordinates their work. The result is more reliable output, better use of context windows, and the ability to parallelize work for faster completion.

Core Concepts

Why Single Agents Hit Limits

Single agents face three structural constraints:

Context window saturation. As you add more tools, instructions, and domain knowledge to a single agent, the context window fills up. Performance degrades as the model struggles to attend to everything simultaneously.

Role confusion. An agent asked to be both a security auditor and a UX reviewer will compromise on both. Specialized agents with focused system prompts produce significantly better results than generalist agents.

Sequential bottlenecks. A single agent processes one step at a time. Multi-agent systems can fan out work in parallel -- researching, analyzing, and generating simultaneously.

Orchestration Pattern: Supervisor

The supervisor pattern uses one agent as a coordinator that delegates work to specialized sub-agents. The supervisor decides which agent to call, passes relevant context, collects results, and synthesizes a final response.

[User Request]
      |
  [Supervisor Agent]
   /      |       \
[Research] [Analysis] [Writer]
   \      |       /
  [Supervisor combines results]
      |
  [Final Response]

When to use it: Tasks that require multiple types of expertise where a central coordinator can decompose the work and merge results. Examples include document analysis, comprehensive code review, and research synthesis.

Orchestration Pattern: Pipeline

The pipeline pattern chains agents sequentially, where each agent's output feeds into the next. Think assembly line -- each station adds value before passing work downstream.

[Input] → [Agent A: Extract] → [Agent B: Analyze] → [Agent C: Format] → [Output]

When to use it: Workflows with clear, ordered steps where each stage transforms the data in a specific way. Examples include content pipelines (research, draft, edit, format), data processing (extract, validate, enrich, load), and code generation (plan, implement, review, test).

Orchestration Pattern: Swarm

The swarm pattern allows agents to communicate peer-to-peer without a central coordinator. Agents hand off tasks to each other based on the conversation context and their own specializations.

[Agent A] ←→ [Agent B]
    ↕              ↕
[Agent C] ←→ [Agent D]

When to use it: Dynamic workflows where the path through agents depends on runtime conditions. Customer support (routing between billing, technical, account agents) and interactive troubleshooting are common examples.

Agent-to-Agent Communication

Multi-agent systems need structured ways to pass information between agents. The key mechanisms are:

  • Shared state objects that all agents can read and write to, providing a common memory.
  • Message passing where agents send structured messages with results, requests, and context.
  • Tool handoffs where one agent explicitly transfers control to another with relevant context attached.

Hands-On Implementation

LangGraph: State Machine Agents

LangGraph models multi-agent workflows as directed graphs with shared state. Each node is an agent or function, and edges define the flow between them.

typescript
// multi-agent-review.ts
import { StateGraph, Annotation, END } from "@langchain/langgraph";
import { ChatOpenAI } from "@langchain/openai";
 
// Define shared state across all agents
const ReviewState = Annotation.Root({
  code: Annotation<string>,
  securityReview: Annotation<string>,
  performanceReview: Annotation<string>,
  finalReport: Annotation<string>,
  currentStep: Annotation<string>,
});
 
const model = new ChatOpenAI({ model: "gpt-4o" });
 
// Agent 1: Security Reviewer
async function securityAgent(
  state: typeof ReviewState.State
) {
  const response = await model.invoke([
    {
      role: "system",
      content: `You are a senior security engineer. Analyze code
        for vulnerabilities: injection attacks, auth issues,
        data exposure, insecure dependencies. Be specific
        about line numbers and severity.`,
    },
    {
      role: "user",
      content: `Review this code for security issues:\n\n${state.code}`,
    },
  ]);
 
  return {
    securityReview: response.content as string,
    currentStep: "security_complete",
  };
}
 
// Agent 2: Performance Reviewer
async function performanceAgent(
  state: typeof ReviewState.State
) {
  const response = await model.invoke([
    {
      role: "system",
      content: `You are a performance optimization expert.
        Analyze code for: N+1 queries, memory leaks,
        unnecessary re-renders, missing indexes, blocking
        operations. Suggest concrete fixes.`,
    },
    {
      role: "user",
      content: `Review this code for performance:\n\n${state.code}`,
    },
  ]);
 
  return {
    performanceReview: response.content as string,
    currentStep: "performance_complete",
  };
}
 
// Agent 3: Supervisor synthesizes reviews
async function supervisorAgent(
  state: typeof ReviewState.State
) {
  const response = await model.invoke([
    {
      role: "system",
      content: `You are a lead engineer. Synthesize security
        and performance reviews into a unified report.
        Prioritize issues by severity: critical, high,
        medium, low. Remove duplicates.`,
    },
    {
      role: "user",
      content: `
Security Review:
${state.securityReview}
 
Performance Review:
${state.performanceReview}
 
Produce a final prioritized code review report.`,
    },
  ]);
 
  return {
    finalReport: response.content as string,
    currentStep: "complete",
  };
}
 
// Build the graph
const workflow = new StateGraph(ReviewState)
  .addNode("security", securityAgent)
  .addNode("performance", performanceAgent)
  .addNode("supervisor", supervisorAgent)
  // Run security and performance reviews in parallel
  .addEdge("__start__", "security")
  .addEdge("__start__", "performance")
  // Both feed into supervisor
  .addEdge("security", "supervisor")
  .addEdge("performance", "supervisor")
  .addEdge("supervisor", END);
 
const app = workflow.compile();
 
// Execute the multi-agent review
const result = await app.invoke({
  code: `
    app.get('/users/:id', async (req, res) => {
      const user = await db.query(
        "SELECT * FROM users WHERE id = " + req.params.id
      );
      const orders = await db.query(
        "SELECT * FROM orders WHERE user_id = " + req.params.id
      );
      for (const order of orders) {
        order.items = await db.query(
          "SELECT * FROM items WHERE order_id = " + order.id
        );
      }
      res.json({ user, orders });
    });
  `,
});
 
console.log(result.finalReport);

CrewAI: Role-Based Agents

CrewAI takes a higher-level approach, defining agents with roles, goals, and backstories. This Python example shows how CrewAI organizes multi-agent collaboration:

python
# content_crew.py
from crewai import Agent, Task, Crew, Process
 
researcher = Agent(
    role="Senior Research Analyst",
    goal="Find comprehensive, accurate information on the given topic",
    backstory="""You are an expert researcher with 15 years of
    experience in technology analysis. You excel at finding
    primary sources and synthesizing complex information.""",
    verbose=True,
    allow_delegation=False,
)
 
writer = Agent(
    role="Technical Content Writer",
    goal="Create engaging, technically accurate content",
    backstory="""You are a senior technical writer who has
    written for major tech publications. You make complex
    topics accessible without dumbing them down.""",
    verbose=True,
    allow_delegation=False,
)
 
editor = Agent(
    role="Senior Editor",
    goal="Ensure content is polished, accurate, and publication-ready",
    backstory="""You are a meticulous editor with an eye for
    factual accuracy, logical flow, and reader engagement.
    You catch errors others miss.""",
    verbose=True,
    allow_delegation=False,
)
 
# Define sequential tasks
research_task = Task(
    description="Research {topic} thoroughly. Cover current state, key players, recent developments, and future outlook.",
    expected_output="A detailed research brief with citations",
    agent=researcher,
)
 
writing_task = Task(
    description="Write a 1500-word article based on the research brief. Use clear headings, include examples, and maintain technical depth.",
    expected_output="A complete article draft in markdown",
    agent=writer,
)
 
editing_task = Task(
    description="Edit the article for accuracy, clarity, flow, and grammar. Verify all technical claims against the research.",
    expected_output="A polished, publication-ready article",
    agent=editor,
)
 
# Assemble the crew with sequential processing
crew = Crew(
    agents=[researcher, writer, editor],
    tasks=[research_task, writing_task, editing_task],
    process=Process.sequential,
    verbose=True,
)
 
result = crew.kickoff(inputs={"topic": "Edge AI deployment patterns"})
print(result)

PydanticAI: Type-Safe Multi-Agent Coordination

PydanticAI brings strong typing to agent interactions, which is especially valuable when agents pass structured data to each other:

typescript
// typed-agents.ts
import { Agent } from "pydantic-ai";
import { z } from "zod";
 
// Define typed schemas for agent communication
const ResearchOutput = z.object({
  findings: z.array(
    z.object({
      claim: z.string(),
      evidence: z.string(),
      confidence: z.enum(["high", "medium", "low"]),
    })
  ),
  sources: z.array(z.string()),
});
 
const AnalysisOutput = z.object({
  summary: z.string(),
  recommendations: z.array(
    z.object({
      action: z.string(),
      priority: z.enum(["critical", "high", "medium", "low"]),
      rationale: z.string(),
    })
  ),
});
 
// Typed research agent
async function runResearchAgent(topic: string) {
  const agent = new Agent(
    "openai:gpt-4o",
    {
      systemPrompt: `You are a research specialist. Analyze
        the given topic and return structured findings with
        confidence levels.`,
      resultType: ResearchOutput,
    }
  );
 
  return await agent.run(`Research: ${topic}`);
}
 
// Typed analysis agent that consumes research output
async function runAnalysisAgent(
  research: z.infer<typeof ResearchOutput>
) {
  const agent = new Agent(
    "openai:gpt-4o",
    {
      systemPrompt: `You are a strategic analyst. Given
        research findings, produce actionable recommendations
        prioritized by impact and confidence.`,
      resultType: AnalysisOutput,
    }
  );
 
  return await agent.run(
    `Analyze these findings and recommend actions:\n${JSON.stringify(research, null, 2)}`
  );
}
 
// Pipeline orchestration
async function researchPipeline(topic: string) {
  const research = await runResearchAgent(topic);
  const analysis = await runAnalysisAgent(research.data);
 
  return {
    research: research.data,
    analysis: analysis.data,
  };
}

Task Decomposition Strategies

Effective multi-agent systems need smart task decomposition. Here is a reusable decomposition pattern:

typescript
// task-decomposer.ts
import { ChatOpenAI } from "@langchain/openai";
import { z } from "zod";
 
const SubTask = z.object({
  id: z.string(),
  description: z.string(),
  agentType: z.enum([
    "researcher",
    "coder",
    "reviewer",
    "writer",
  ]),
  dependencies: z
    .array(z.string())
    .describe("IDs of tasks that must complete first"),
  estimatedComplexity: z.enum(["low", "medium", "high"]),
});
 
const DecompositionPlan = z.object({
  subtasks: z.array(SubTask),
  executionOrder: z
    .array(z.array(z.string()))
    .describe("Groups of task IDs that can run in parallel"),
});
 
async function decomposeTask(
  task: string
): Promise<z.infer<typeof DecompositionPlan>> {
  const model = new ChatOpenAI({ model: "gpt-4o" });
 
  const response = await model.invoke([
    {
      role: "system",
      content: `Decompose the given task into subtasks for
        a multi-agent system. Identify which agent type
        should handle each subtask, what dependencies exist,
        and which tasks can run in parallel. Return valid JSON
        matching the schema.`,
    },
    {
      role: "user",
      content: task,
    },
  ]);
 
  return DecompositionPlan.parse(
    JSON.parse(response.content as string)
  );
}

Best Practices

  • Start with a single agent, then decompose. Build the simplest version first. Only split into multiple agents when you hit clear limits in quality, context, or speed.
  • Give each agent a focused system prompt. Specialized agents with narrow, clear instructions outperform generalist agents trying to do everything.
  • Use structured data between agents. Define Zod schemas or Pydantic models for inter-agent communication. This catches integration errors early and makes debugging straightforward.
  • Implement timeout and retry logic per agent. One slow or failing agent should not block the entire pipeline. Set per-agent timeouts and retry policies independently.
  • Log every agent interaction. In multi-agent systems, debugging requires tracing which agent said what, when, and why. Structured logging is not optional.
  • Keep the number of agents small. Two to five well-designed agents typically outperform ten poorly scoped ones. More agents means more coordination overhead and more failure points.

Common Pitfalls

  • Over-engineering from day one. Teams build elaborate multi-agent architectures for problems a single well-prompted agent could solve. Validate that you actually need multiple agents before investing in orchestration.
  • Infinite delegation loops. Supervisor agents that can delegate back to themselves or create circular dependencies. Always enforce a maximum recursion depth and track visited states.
  • Context loss between agents. If Agent B only gets Agent A's final output, it misses nuance. Pass enough context for each agent to do its job, but not so much that you overwhelm the context window.
  • Ignoring failure modes. What happens when one agent in a pipeline fails? Without explicit error handling, the entire workflow crashes silently or produces garbage output.
  • Shared state race conditions. When multiple agents write to the same state simultaneously, you get inconsistent results. Use immutable state updates or explicit locking.

What's Next

Multi-agent systems are powerful, but how do you know they are working correctly? As complexity grows, you need systematic evaluation, tracing, and monitoring. In Part 8: LLMOps -- Evaluation, Tracing, and Monitoring, we will set up the observability infrastructure to keep multi-agent workflows reliable in production.

FAQ

When should you use multi-agent systems instead of a single agent?

Use multi-agent systems when tasks require different expertise (research, coding, review), when parallel processing improves speed, or when breaking down complex workflows into specialized steps increases reliability.

What are the main multi-agent orchestration patterns?

The main patterns are supervisor (one agent delegates to others), sequential pipeline (agents pass work in order), parallel fan-out (multiple agents work simultaneously), and hierarchical (nested supervisor structures).

How do LangGraph and CrewAI compare for multi-agent systems?

LangGraph offers fine-grained control with graph-based workflows and is ideal for custom orchestration. CrewAI provides higher-level abstractions with role-based agents and is faster to prototype with but less flexible.

Collaboration

Need help with a project?

Let's Build It

I help startups and established companies design, build, and scale world-class digital products. From deep technical architecture to pixel-perfect UI — let's bring your vision to life.

SH

Article Author

Sadam Hussain

Senior Full Stack Developer

Senior Full Stack Developer with over 7 years of experience building React, Next.js, Node.js, TypeScript, and AI-powered web platforms.

Related Articles

AI Evaluation for Production Workflows
Mar 21, 20266 min read
AI
Evaluation
LLMOps

AI Evaluation for Production Workflows

Learn how to evaluate AI workflows in production using task-based metrics, human review, regression checks, and business-aligned quality thresholds.

How to Build an AI Workflow in a Production SaaS App
Mar 21, 20267 min read
AI
SaaS
Workflows

How to Build an AI Workflow in a Production SaaS App

A practical guide to designing and shipping AI workflows inside a production SaaS app, with orchestration, fallback logic, evaluation, and user trust considerations.

Building AI Features Safely: Guardrails, Fallbacks, and Human Review
Mar 21, 20266 min read
AI
LLM
Guardrails

Building AI Features Safely: Guardrails, Fallbacks, and Human Review

A production guide to shipping AI features safely with guardrails, confidence thresholds, fallback paths, auditability, and human-in-the-loop review.