Skip to main content
Multi-agent systems enable complex AI applications by coordinating specialized agents. This guide covers four key patterns found across production agents in the repository.

Pattern Overview

Multi-agent architectures distribute work among specialized agents, each with focused capabilities. Choose your pattern based on:
  • Orchestrator: When you need central control and dynamic task routing
  • Swarm: For autonomous agent collaboration with handoffs
  • Graph: When workflows have clear dependencies and parallel steps
  • Workflow: For sequential, multi-stage processing pipelines

Orchestrator Pattern (Agent as Tools)

The orchestrator pattern uses a manager agent that delegates tasks to specialized worker agents. The orchestrator decides which specialist to call based on the user’s request.

Architecture

User Query → Orchestrator Agent → [Research Agent | Product Agent | Trip Agent]

          Final Response

Implementation Example

From course/aws_strands/06_multi_agent_pattern/06_1_agent_as_tools/main.py:
from strands import Agent
from strands.models.litellm import LiteLLMModel

ORCHESTRATOR_SYSTEM_PROMPT = """
You are a master assistant that routes complex queries to specialized agents.
Based on the user's request, determine the best tool to use.

- For research questions → Use the `research_assistant`
- For product recommendations → Use the `product_recommendation_assistant`
- For travel planning → Use the `trip_planning_assistant`
- For simple queries → Answer directly without using a tool
"""

def create_orchestrator_agent() -> Agent:
    model = LiteLLMModel(
        client_args={"api_key": os.getenv("NEBIUS_API_KEY")},
        model_id="nebius/moonshotai/Kimi-K2-Instruct",
    )
    
    orchestrator = Agent(
        model=model,
        system_prompt=ORCHESTRATOR_SYSTEM_PROMPT,
        tools=[
            research_assistant,
            product_recommendation_assistant,
            trip_planning_assistant,
        ],
    )
    return orchestrator

Real-World Example: Content Team Agent

From advance_ai_agents/content_team_agent/main.py:
# Specialized agents for different SEO tasks
search_insights_agent = Agent(
    name="Search Insights Agent",
    model=Nebius(id="moonshotai/Kimi-K2-Instruct"),
    tools=[search_google_ai_mode, search_google_ai_overview],
    description="Expert SEO researcher for SERP data gathering"
)

serp_analysis_agent = Agent(
    name="SERP Analysis Agent",
    description="Expert at understanding and structuring SERP data",
    output_schema=SearchInsights,
)

content_strategist_agent = Agent(
    name="Content Strategist Agent",
    description="Senior content strategist for SEO optimization"
)

seo_editor_agent = Agent(
    name="SEO Editor Agent",
    description="Expert editor for keyword integration",
    output_schema=SectionEdits,
)
The orchestrator pattern works best when:
  • You have distinct task categories (research, analysis, writing)
  • Tasks don’t depend on sequential execution
  • You need dynamic routing based on user intent

Swarm Pattern

Swarm agents autonomously decide which agent should handle the next step through dynamic handoffs. Unlike orchestrators, there’s no central controller.

Architecture

Researcher ⇄ Coder ⇄ Reviewer ⇄ Architect
    ↓         ↓        ↓         ↓
         Autonomous Handoffs

Implementation Example

From course/aws_strands/06_multi_agent_pattern/06_2_swarm_agent/main.py:
from strands.multiagent import Swarm

# Create specialized agents
researcher = Agent(
    name="researcher",
    model=model,
    system_prompt="You are a research specialist..."
)

coder = Agent(
    name="coder",
    model=model,
    system_prompt="You are a coding specialist..."
)

reviewer = Agent(
    name="reviewer",
    model=model,
    system_prompt="You are a code review specialist..."
)

architect = Agent(
    name="architect",
    model=model,
    system_prompt="You are a system architecture specialist..."
)

# Create a swarm with autonomous handoffs
swarm = Swarm(
    [coder, researcher, reviewer, architect],
    entry_point=researcher,  # Start with researcher
    max_handoffs=20,
    max_iterations=20,
    execution_timeout=900.0,  # 15 minutes
    node_timeout=300.0,  # 5 minutes per agent
    repetitive_handoff_detection_window=8,
    repetitive_handoff_min_unique_agents=3,
)

# Execute with autonomous agent selection
result = swarm("Design and implement a simple REST API for a todo app")

Key Configuration Parameters

ParameterPurposeExample Value
max_handoffsLimit total agent transitions20
max_iterationsMaximum execution cycles20
execution_timeoutOverall timeout (seconds)900.0
node_timeoutPer-agent timeout (seconds)300.0
repetitive_handoff_detection_windowSliding window for loop detection8
repetitive_handoff_min_unique_agentsMin unique agents in window3
Swarm patterns can create infinite loops. Always set:
  • max_handoffs and max_iterations limits
  • repetitive_handoff_detection_window to catch cycles
  • Appropriate timeouts for safety

Graph Pattern

Graph-based workflows define explicit dependencies between agents, enabling parallel execution where possible.

Architecture

         Researcher
           /    \
          ↓      ↓
    Analyst  Fact Checker
          \      /
           ↓    ↓
       Report Writer

Implementation Example

From course/aws_strands/06_multi_agent_pattern/06_3_graph_agent/main.py:
from strands.multiagent import GraphBuilder

# Create specialized agents
researcher = Agent(
    name="researcher",
    system_prompt="Research specialist for gathering data"
)

analyst = Agent(
    name="analyst",
    system_prompt="Data analysis specialist"
)

fact_checker = Agent(
    name="fact_checker",
    system_prompt="Fact checking specialist"
)

report_writer = Agent(
    name="report_writer",
    system_prompt="Report writing specialist"
)

# Build the graph with explicit dependencies
builder = GraphBuilder()

# Add nodes
builder.add_node(researcher, "research")
builder.add_node(analyst, "analysis")
builder.add_node(fact_checker, "fact_check")
builder.add_node(report_writer, "report")

# Define dependencies (edges)
builder.add_edge("research", "analysis")
builder.add_edge("research", "fact_check")
builder.add_edge("analysis", "report")
builder.add_edge("fact_check", "report")

# Set entry point
builder.set_entry_point("research")
builder.set_execution_timeout(600)  # 10 minute timeout

# Build and execute
graph = builder.build()
result = graph("Research AI impact on healthcare and create a report")

Parallel Execution

In the graph above, analyst and fact_checker run in parallel after researcher completes, since they don’t depend on each other.
Use graph patterns when:
  • You have clear task dependencies
  • Some steps can run in parallel
  • You need deterministic execution order
  • Workflow structure is known upfront

Workflow Pattern (Sequential Pipeline)

Workflows execute agents in a fixed sequence, with each agent’s output feeding into the next. Perfect for multi-stage processing pipelines.

Architecture

Searcher → Analyst → Writer → Final Report

Implementation Example

From advance_ai_agents/deep_researcher_agent/agents.py:
from agno.workflow import Workflow
from agno.agent import Agent

class DeepResearcherAgent(Workflow):
    """
    Multi-stage research workflow:
    1. Gathers information from the web
    2. Analyzes and synthesizes findings
    3. Produces a clear, structured report
    """
    
    # Stage 1: Research and gather information
    searcher: Agent = Agent(
        tools=[ScrapeGraphTools(api_key=os.getenv("SGAI_API_KEY"))],
        model=Nebius(id="deepseek-ai/DeepSeek-V3-0324"),
        description="Expert at finding and extracting web information",
        instructions="""
        1. Search for authoritative sources on the topic
        2. Extract key facts, statistics, expert opinions
        3. Cover multiple perspectives
        4. Mention References & Sources
        """
    )
    
    # Stage 2: Analyze research findings
    analyst: Agent = Agent(
        model=Nebius(id="deepseek-ai/DeepSeek-V3-0324"),
        description="Critical thinker who synthesizes research",
        instructions="""
        1. Identify key themes, trends, contradictions
        2. Highlight important findings and implications
        3. Suggest areas for further investigation
        4. Extract ONLY actual reference links provided
        5. Don't hallucinate or make up information
        """
    )
    
    # Stage 3: Write final report
    writer: Agent = Agent(
        model=Nebius(id="deepseek-ai/DeepSeek-V3-0324"),
        description="Professional technical writer",
        instructions="""
        1. Write engaging introduction with context
        2. Organize findings into logical sections
        3. Use bullet points, tables for clarity
        4. Include actionable recommendations
        5. Add References section if analyst provided links
        6. Use ONLY actual links from the analyst
        """
    )
    
    def run(self, topic: str) -> Iterator[RunResponse]:
        """Execute the research pipeline"""
        # Step 1: Research
        research_content = self.searcher.run(topic)
        
        # Step 2: Analysis
        analysis = self.analyst.run(research_content.content)
        
        # Step 3: Report Writing (streaming)
        report = self.writer.run(analysis.content, stream=True)
        yield from report

Usage

agent = DeepResearcherAgent()
response = agent.run(topic="AI agent frameworks comparison")

for chunk in response:
    if chunk.content:
        print(chunk.content, end="")

Pattern Comparison

PatternControl FlowBest ForComplexity
OrchestratorCentral routingDynamic task delegation, mixed queriesLow
SwarmAutonomous handoffsCollaborative problem-solving, emergent solutionsHigh
GraphDependency-basedParallel execution, clear dependenciesMedium
WorkflowSequential pipelineMulti-stage processing, data transformationLow

Best Practices

1. Choose the Right Pattern

# ✅ Good: Sequential workflow for research pipeline
class ResearchWorkflow(Workflow):
    searcher: Agent
    analyst: Agent
    writer: Agent

# ❌ Bad: Swarm for simple sequential tasks (unnecessary complexity)

2. Set Appropriate Limits

# ✅ Good: Clear limits and timeouts
swarm = Swarm(
    agents=[...],
    max_handoffs=20,
    execution_timeout=900.0,
    repetitive_handoff_detection_window=8
)

# ❌ Bad: No limits (risk of infinite loops)
swarm = Swarm(agents=[...])  # Missing safety limits

3. Use Structured Outputs

# ✅ Good: Typed outputs for agent communication
class SearchInsights(BaseModel):
    primary_keywords: str
    related_keywords: str
    search_intent: str

analyst = Agent(
    output_schema=SearchInsights,  # Structured output
    ...
)

# ❌ Bad: Unstructured string outputs between agents
analyst = Agent(...)  # Hard to parse output

4. Clear Agent Responsibilities

# ✅ Good: Focused, single-responsibility agents
researcher = Agent(
    description="Expert at finding information from the web",
    instructions="Search for sources and extract facts"
)

# ❌ Bad: Vague, multi-purpose agent
agent = Agent(description="Do everything")  # Too broad

Real-World Examples

Finance Research Agent

Location: advance_ai_agents/agentfield_finance_research_agent/src/reasoners.py 5-agent investment committee:
  • Manager (orchestrator)
  • Analyst (bull case)
  • Contrarian (bear case)
  • Editor (synthesis)
  • Skills layer (data gathering)

Content SEO Workflow

Location: advance_ai_agents/content_team_agent/main.py Sequential pipeline:
  1. Search insights agent (SERP research)
  2. SERP analysis agent (keyword extraction)
  3. Content strategist (recommendations)
  4. SEO editor (content optimization)

AI Consultant

Location: memory_agents/ai_consultant_agent/workflow.py Research + reasoning workflow:
  1. Tavily search (case studies)
  2. LLM analysis (recommendations)
  3. Structured output (consulting report)

Next Steps

Human-in-the-Loop Patterns

Add human oversight and approval to multi-agent workflows

Memory Systems

Give agents persistent memory across conversations

Best Practices

Production-ready patterns and error handling

API Keys

Configure credentials for multi-agent systems

Build docs developers (and LLMs) love