DevInterviewMasterStart free →
AI & AutomationFree to read

Multi-Agent Systems (CrewAI, AutoGen, Swarm)

Teams of AI Agents Working Together

Learn how multiple specialized AI agents collaborate to solve complex problems. Explore popular frameworks like CrewAI, AutoGen, and OpenAI Swarm for building multi-agent applications.

What Are Multi-Agent Systems?

A Team of Specialists, Not a Single Generalist

The Core Idea:

A Multi-Agent System (MAS) is a group of specialized AI agents that work together, each with a defined role, personality, and set of tools. Instead of one LLM trying to do everything, you have a team where each member excels at their specific job.

Think of it like a cricket team: you have batsmen, bowlers, a wicketkeeper, and a captain. Each player has a specialized role. The captain coordinates the team strategy. A multi-agent system works the same way - specialized agents coordinated by a system.

Real-World Example - Startup Operating System:

Imagine building an AI-powered startup team:

  • CEO Agent: Strategic decisions, prioritization, final approvals
  • CTO Agent: Technical architecture, code review, tech stack decisions
  • Marketing Agent: Content creation, SEO strategy, social media
  • Sales Agent: Lead qualification, email outreach, follow-ups
  • Finance Agent: Budget tracking, revenue forecasting, expense analysis

Each agent has its own system prompt, tools, and expertise. They communicate with each other, debate strategies, and collaborate on complex decisions.

Single Agent vs Multi-Agent - When to Choose:

FactorSingle AgentMulti-Agent
Task ComplexitySimple, focusedComplex, multi-domain
Expertise NeededOne domainMultiple domains
Quality RequirementGood enoughHigh (peer review)
CostLowerHigher (multiple LLM calls)
DebuggingEasierMore complex

Note: Multi-agent systems shine when you need different types of expertise working together. The key is giving each agent a clear, focused role rather than making agents that try to do everything.

CrewAI - Role-Based Agent Teams

The Most Popular Multi-Agent Framework

What is CrewAI?

CrewAI is an open-source framework that lets you create role-playing AI agents that collaborate on tasks. Each agent has a role, goal, backstory, and tools. You define tasks with expected outputs, and CrewAI orchestrates the collaboration.

CrewAI Core Concepts:

  • Agent: An AI team member with a role (e.g., "Senior Market Researcher"), goal, backstory, and tools. The backstory helps the LLM stay in character.
  • Task: A specific assignment given to an agent with a description, expected output format, and optional context from other tasks.
  • Crew: The team of agents working together. You define the process (sequential or hierarchical) and which tasks each agent handles.
  • Process: How agents collaborate - sequential (one by one) or hierarchical (manager delegates).

Example - Content Creation Crew:

Crew: "Blog Writing Team"

Agent 1: Senior Research Analyst
  Role: Research trending topics and gather data
  Tools: web_search, news_api
  Backstory: "Expert researcher with 10 years of experience
              in technology journalism"

Agent 2: Content Strategist
  Role: Create content outline and SEO strategy
  Tools: keyword_research, competitor_analysis
  Backstory: "Digital marketing expert who has grown
              multiple blogs to 1M+ monthly visitors"

Agent 3: Senior Content Writer
  Role: Write engaging, SEO-optimized blog posts
  Tools: grammar_check, readability_scorer
  Backstory: "Award-winning tech writer who simplifies
              complex topics for Indian developers"

Process: Sequential
  Task 1 (Researcher) -> Task 2 (Strategist) -> Task 3 (Writer)

CrewAI Strengths:

  • + Very easy to set up - intuitive API
  • + Role-playing makes agents more focused and consistent
  • + Built-in memory and context sharing between agents
  • + Supports both sequential and hierarchical processes
  • ~ Growing ecosystem but still maturing
  • - Can be expensive for complex crews (many LLM calls)

Note: CrewAI is the best starting point for multi-agent systems. Its role-playing approach makes agents more focused and the API is very developer-friendly.

AutoGen - Conversational Multi-Agent

Microsoft's Framework Where Agents Talk to Each Other

What is AutoGen?

AutoGen (by Microsoft Research) is a framework where agents have conversations with each other to solve problems. Instead of a rigid pipeline, agents debate, discuss, and refine ideas through multi-turn dialogue. Think of it as a group discussion where participants build on each other's ideas.

AutoGen Core Concepts:

  • ConversableAgent: Base agent that can send and receive messages. Can be AI-powered or human.
  • AssistantAgent: AI agent that uses an LLM to generate responses. Has a system prompt defining its expertise.
  • UserProxyAgent: Represents a human user. Can execute code, provide feedback, or auto-reply based on rules.
  • GroupChat: Multiple agents in a conversation. A GroupChatManager decides who speaks next based on context.

Example - Code Review System:

GroupChat: "Code Review Meeting"

Agent 1: Developer
  "I wrote this function to process payments via Razorpay API.
   Here is the code..."

Agent 2: Security Reviewer
  "I see two issues: (1) The API key is hardcoded - use env
   variables. (2) No input validation on the amount field -
   someone could pass negative amounts."

Agent 3: Performance Reviewer
  "The Razorpay API call is synchronous. For high traffic,
   you should use async/await and add retry logic with
   exponential backoff."

Agent 1: Developer
  "Good points. Let me fix these issues...
   [Updated code with env vars, validation, and async]"

Agent 2: Security Reviewer
  "Looks good now. The input validation covers edge cases.
   Approved from security perspective."

Agent 4: UserProxy (Human)
  "LGTM. Ship it."

AutoGen vs CrewAI:

FeatureCrewAIAutoGen
Interaction StyleTask-based (do this task)Conversation-based (discuss this)
Best ForStructured workflowsCollaborative problem solving
Human IntegrationLimitedFirst-class (UserProxy)
Code ExecutionVia toolsBuilt-in Docker sandbox
Learning CurveEasierSteeper

Note: AutoGen is great when you need agents to debate and refine ideas. Its conversational approach produces higher quality outputs for complex reasoning tasks.

OpenAI Swarm - Lightweight Agent Handoffs

Simple, Lightweight, Production-Ready Agent Routing

What is Swarm?

Swarm is OpenAI's experimental framework focused on lightweight agent handoffs. Instead of complex orchestration, Swarm is about simple routing: when one agent realizes a task needs a different specialist, it "hands off" the conversation to that specialist.

Think of it like calling a bank helpline: you start with the general support agent, who transfers you to the credit card department, who then transfers you to the fraud team. Each transfer is a "handoff".

Swarm Core Concepts:

  • Agent: A lightweight wrapper around an LLM with a system prompt and tools. Very minimal overhead.
  • Handoff: An agent can return a different agent as a "tool result", transferring the conversation. The new agent takes over completely.
  • Context Variables: Shared state passed between agents during handoffs. Like a patient file passed between doctors.
  • Routines: Predefined sequences of steps an agent should follow. Think of them as SOPs (Standard Operating Procedures).

Example - Customer Support System:

Swarm Customer Support:

Agent: Triage Agent
  "Hello! How can I help you today?"
  User: "I was charged twice for my Hotstar subscription"
  Triage Agent thinks: This is a billing issue.
  -> HANDOFF to Billing Agent (with context: user_id, issue_type)

Agent: Billing Agent
  "I can see your account. Let me check the transactions...
   Yes, I see two charges of Rs 299 on Feb 15.
   I will initiate a refund for the duplicate charge.
   Is there anything else?"
  User: "Yes, I also want to upgrade to the annual plan"
  Billing Agent thinks: This is a plan change request.
  -> HANDOFF to Subscription Agent (with context: refund_initiated)

Agent: Subscription Agent
  "I see your refund is being processed. For the annual plan,
   you will get 2 months free. Shall I proceed?"

Swarm vs CrewAI vs AutoGen:

  • Swarm: Best for customer-facing routing. Simple handoffs, minimal overhead, production-ready.
  • CrewAI: Best for structured backend workflows. Role-based teams with defined tasks.
  • AutoGen: Best for complex reasoning. Agents debate and iterate to reach high-quality solutions.

Note: Swarm is perfect for customer support and routing scenarios where different specialists need to handle different parts of a conversation. It is the simplest multi-agent framework.

Designing Effective Multi-Agent Systems

Best Practices for Production Multi-Agent Apps

Agent Design Principles:

  • Single Responsibility: Each agent should do ONE thing well. A "research and write and edit" agent is worse than three specialized agents.
  • Clear Interfaces: Define exactly what input each agent expects and what output it produces. Use structured output (JSON schemas) for reliability.
  • Minimal Context: Only pass the information each agent needs. Do not dump the entire conversation history to every agent.
  • Appropriate Model: Use GPT-4/Claude for the manager and reasoning agents. Use GPT-3.5/Haiku for simple extraction and formatting tasks. Saves 10-50x on cost.

Communication Patterns Between Agents:

  • Direct Messaging: Agent A sends output directly to Agent B. Simple but tightly coupled.
  • Shared Blackboard: All agents read/write to a shared state. Flexible but can cause conflicts.
  • Message Queue: Agents communicate through a queue (like RabbitMQ). Scalable and decoupled.
  • Event-Driven: Agents publish events that other agents subscribe to. Very scalable but harder to debug.

Common Mistakes to Avoid:

  • Too Many Agents: Start with 2-3 agents. More agents = more coordination overhead, more errors, more cost.
  • Vague Roles: "General Purpose Agent" is useless. Be specific: "SQL Query Generator for PostgreSQL databases".
  • No Error Boundaries: One failing agent should not crash the entire system. Isolate failures.
  • Ignoring Costs: A 5-agent crew with GPT-4 can cost $1-5 per run. Use cheaper models where possible.
  • No Evaluation: Measure output quality. Multi-agent does not automatically mean better quality.

Note: More agents does not mean better results. Start with the minimum number of agents that can solve your problem, and only add more when you have clear evidence of improvement.

Interview Questions - Multi-Agent Systems

Q: When would you use a multi-agent system instead of a single agent?

Use multi-agent when: (1) The task requires different types of expertise (research + coding + writing). (2) You want peer review quality - one agent checks another's work. (3) The task is too complex for a single context window. (4) You need specialization with different models for different sub-tasks (expensive model for reasoning, cheap model for formatting).

Q: Compare CrewAI, AutoGen, and Swarm.

CrewAI: Role-based teams with structured task workflows. Best for content creation and research pipelines. AutoGen: Conversational agents that debate and iterate. Best for complex reasoning and code review. Swarm: Lightweight agent handoffs. Best for customer support routing. Choose based on your interaction pattern: structured tasks (CrewAI), discussion (AutoGen), or routing (Swarm).

Q: How do you optimize costs in a multi-agent system?

(1) Use cheaper models for simple agents (GPT-3.5/Haiku for formatting, GPT-4/Opus for reasoning). (2) Minimize context passed to each agent - only what they need. (3) Cache results of expensive operations. (4) Reduce agent count - do you really need 5 agents or can 3 do the job? (5) Use structured outputs to avoid retry loops. (6) Set token limits per agent per run.

Q: What is the biggest challenge in multi-agent systems?

The biggest challenge is coordination and communication quality. Agents can misunderstand each other, produce contradictory outputs, or get into infinite loops of back-and-forth. Debugging is hard because you need to trace conversations across multiple agents. Solutions include clear interfaces, structured output schemas, conversation limits, and comprehensive logging.

Frequently Asked Questions

What is Multi-Agent Systems?

Learn how multiple specialized AI agents collaborate to solve complex problems. Explore popular frameworks like CrewAI, AutoGen, and OpenAI Swarm for building multi-agent applications.

How does Multi-Agent Systems work?

A Team of Specialists, Not a Single Generalist The Core Idea: A Multi-Agent System (MAS) is a group of specialized AI agents that work together, each with a defined role, personality, and set of tools. Instead of one LLM trying to do everything, you have a team where each member excels at their specific job.

Browse all AI & Automation topics →

Practice this on DevInterviewMaster

Read the full Multi-Agent Systems (CrewAI, AutoGen, Swarm) breakdown with interactive demos, quizzes, and Hinglish notes.

Open the interactive topic →

800+ system-design, LLD, coding, and design-pattern topics. Unlock everything with Pro (₹499, one-time) or Ultimate (₹999, one-time) — lifetime access, no subscription.