Master complex multi-agent workflows! This tutorial teaches you how to coordinate multiple agents using parallel execution, agents-as-tools patterns, and advanced orchestration techniques for building sophisticated AI systems.
Sign in to save downloads to your library and vote.
Preview
πΌ Tutorial 9: Multi-Agent Orchestration
Master complex multi-agent workflows! This tutorial teaches you how to coordinate multiple agents using parallel execution, agents-as-tools patterns, and advanced orchestration techniques for building sophisticated AI systems.
π― What You'll Learn
- Parallel Execution: Running multiple agents simultaneously with
asyncio.gather() - Agents as Tools: Using agents as function tools for complex orchestration
- Workflow Coordination: Sequential and parallel agent processing patterns
- Result Synthesis: Combining outputs from multiple agents intelligently
π§ Core Concept: What Is Multi-Agent Orchestration?
Multi-agent orchestration enables coordinated AI workflows where multiple specialized agents work together to solve complex problems. Think of orchestration as a conductor leading an orchestra where:
- Different agents have specialized roles and expertise
- Agents can work in parallel or sequence based on workflow needs
- Results from multiple agents are synthesized intelligently
- Complex tasks are broken down across multiple AI capabilities
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ-β
β MULTI-AGENT ORCHESTRATION β
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ-β€
β β
β COMPLEX TASK β
β β β
β βΌ β
β βββββββββββββββ 1. TASK DECOMPOSITION β
β βORCHESTRATOR β β
β β AGENT β 2. AGENT COORDINATION β
β βββββββββββββββ β
β β β
β βΌ β
β βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β PARALLEL EXECUTION β β
β β βββββββββββ βββββββββββ βββββββββββ βββββββββββ β β |
β β βRESEARCH β βWRITING β βANALYSIS β βREVIEW β β β |
β β β AGENT β β AGENT β β AGENT β β AGENT β β β |
β β βββββββββββ βββββββββββ βββββββββββ βββββββββββ β β |
β βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β β β β β
β βΌ βΌ βΌ βΌ β
β βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β RESULT SYNTHESIS β β
β β β’ Combine outputs intelligently β β
β β β’ Quality assessment and selection β β
β β β’ Final coordinated response β β
β βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ-β
π Tutorial Overview
This tutorial demonstrates three key orchestration patterns:
1. Parallel Agent Execution (parallel_execution.py)
- Running multiple agents simultaneously with
asyncio.gather() - Quality assessment and best result selection
- Translation example with multiple attempts
2. Agents as Tools Orchestration (agents_as_tools.py)
- Using specialized agents as function tools
- Content creation workflow with research and writing agents
- Custom agent tool configuration and coordination
3. Complex Workflow Orchestration (complex_orchestration.py)
- Multi-stage workflows combining parallel and sequential execution
- Content pipeline with research, writing, review, and optimization
- Advanced result synthesis and quality control
π Project Structure
9_multi_agent_orchestration/
βββ README.md # This file - concept explanation
βββ requirements.txt # Dependencies
βββ parallel_execution.py # Parallel agent patterns (45 lines)
βββ agents_as_tools.py # Agents as tools orchestration (55 lines)
βββ complex_orchestration.py # Advanced workflow patterns (70 lines)
βββ app.py # Streamlit orchestration demo (optional)
βββ env.example # Environment variables template
π― Learning Objectives
By the end of this tutorial, you'll understand:
- β How to run multiple agents in parallel for improved performance
- β Using agents as function tools for complex orchestration
- β Combining sequential and parallel execution patterns
- β Synthesizing results from multiple agents intelligently
- β When to use different orchestration patterns for various use cases
π Getting Started
-
Install OpenAI Agents SDK:
pip install openai-agents -
Install dependencies:
pip install -r requirements.txt -
Set up environment variables:
cp env.example .env # Edit .env and add your OpenAI API key -
Test parallel execution:
python parallel_execution.py -
Try agents as tools:
python agents_as_tools.py -
Explore complex workflows:
python complex_orchestration.py
π§ͺ Sample Use Cases
Parallel Execution
- Multiple translation attempts with quality selection
- Content generation with diversity and choice
- Research from multiple perspectives simultaneously
Agents as Tools
- Content creation: research β writing β editing pipeline
- Analysis workflows: data processing β insights β recommendations
- Customer service: triage β specialist β quality assurance
Complex Orchestration
- Multi-stage content production with feedback loops
- Research and development workflows with validation
- Educational content creation with multiple review stages
π§ Key Orchestration Patterns
1. Parallel Execution with Quality Selection
import asyncio
from agents import Agent, Runner, trace
# Run multiple agents in parallel
with trace("Parallel translation"):
results = await asyncio.gather(
Runner.run(translator_agent, message),
Runner.run(translator_agent, message),
Runner.run(translator_agent, message)
)
# Select best result
best = await Runner.run(selector_agent, combined_results)
2. Agents as Function Tools
from agents import Agent, function_tool
@function_tool
async def research_tool(topic: str) -> str:
result = await Runner.run(research_agent, f"Research: {topic}")
return str(result.final_output)
orchestrator = Agent(
name="Content Orchestrator",
tools=[research_tool, writing_tool]
)
3. Sequential + Parallel Hybrid
# Sequential stages with parallel execution within stages
with trace("Content Creation Pipeline"):
# Stage 1: Parallel research
research_results = await asyncio.gather(
research_agent_1.run(topic),
research_agent_2.run(topic)
)
# Stage 2: Sequential writing
content = await writing_agent.run(combined_research)
# Stage 3: Parallel review
reviews = await asyncio.gather(
quality_agent.run(content),
style_agent.run(content)
)
π‘ Orchestration Design Best Practices
- Task Decomposition: Break complex tasks into agent-sized pieces
- Parallel Optimization: Use parallel execution where agents are independent
- Quality Control: Include review and selection mechanisms
- Error Handling: Plan for agent failures and provide fallbacks
- Result Synthesis: Design intelligent combination of multiple outputs
π¨ Important Notes
- Tracing Integration: Use
trace()to group multi-agent workflows - Resource Management: Consider API rate limits with parallel execution
- Quality vs Speed: Balance parallelization with result quality
- Error Propagation: Handle failures gracefully in complex workflows
π Next Steps
After completing this tutorial, you'll be ready for:
- Tutorial 10: Tracing & Observability - Monitoring complex workflows
- Tutorial 11: Production Patterns - Real-world deployment strategies
π¨ Troubleshooting
- Performance Issues: Check for unnecessary sequential execution
- Quality Problems: Improve result synthesis and selection logic
- Rate Limiting: Implement backoff and retry for parallel calls
- Memory Usage: Monitor resource consumption with many parallel agents
π‘ Pro Tips
- Start Simple: Begin with basic parallel execution, add complexity gradually
- Measure Performance: Compare parallel vs sequential execution times
- Quality Metrics: Develop criteria for selecting best results from multiple agents
- Workflow Visualization: Use tracing to understand complex execution flows
- Agent Specialization: Design agents with clear, focused responsibilities
Ingestion metadata
- Source catalog
- awesome-llm-apps
- Repository
- Shubhamsaboo/awesome-llm-apps Β· main
- File path
- ai_agent_framework_crash_course/openai_sdk_crash_course/9_multi_agent_orchestration/README.md
- Last refreshed
- 7/23/2026, 10:39:09 PM (4h ago)
- Refresh schedule
- Daily Β· 03:00 UTC
- Dedupe status
- Unique Β· deduped by (source, url)