Learn to build sophisticated multi-agent systems by mastering six architectural patterns plus production-ready implementation techniques.
This workshop teaches LangGraph through architectural patterns, not code syntax. You'll understand when and why to choose different approaches, progressing from simple workflows to sophisticated multi-agent systems.
Caution
LangGraph is a relatively recent library that is continuously updated with new syntax, not all LLMs have caught on to this so always cross-check with documentation when unsure. Ask AI to check latest documentation before generating any code.
- Python 3.9+ or Anaconda/Miniconda
- OpenAI API key
- Basic Python and AI understanding
- Review Multi-Agent Patterns: Practical Guide before starting
-
Clone the repository:
- with https:
git clone https://github.com/TandemCreativeDev/fac-ws_ai_multi-agent.git cd fac-ws_ai_multi-agent
- with ssh:
git clone git@github.com:TandemCreativeDev/fac-ws_ai_multi-agent.git cd fac-ws_ai_multi-agent
-
Setup environment
- with conda (recommended for Mac and Linux):
conda env create -f environment.yml conda activate multi-agent
- with pip only (easier for Windows):
pip install langchain-openai langgraph python-dotenv matplotlib
-
Create
.env
file:OPENAI_API_KEY=your_key_here
- Two versions per pattern: Start with
patterns_simple/
to understand concepts, then do exercises inpatterns/
- Six architectural patterns + production implementation: Each builds on previous concepts
- Three exercises per file: Modify the code to complete each exercise
- Generated output: Check
generated/
folder after running the patterns - Incremental Difficulty: Each pattern builds on previous concepts
- Focus on concepts, not syntax: Focus on when to use each pattern, not just how
For each pattern:
-
Read the simple version in
patterns_simple/
-
Run the full version in
patterns/
-
Examine the generated output in
generated/
Full pattern implementations generate timestamped folders in
generated/
:generated/ └── 01_sequential_workflow_20250602_143022/ ├── original_code.py ├── refactored_code.py └── AUDIT_TRAIL.md
-
Complete the 3 exercises by modifying the code in the file you just ran (the one in
patterns/
) -
Discuss when you'd use this pattern vs others
Pattern 1: Sequential Workflow 🔁👨💻🕵️🔧✅
- File:
patterns/01_sequential_workflow.py
- Concept: Linear pipeline (coder → reviewer → refactorer)
- Use case: Predictable, step-by-step processes
- File:
patterns/01_sequential_workflow.py
- Concept: Linear pipeline (coder → reviewer → refactorer)
- Use case: Predictable, step-by-step processes
Run and explore:
python patterns/01_sequential_workflow.py
# Check generated/ folder for output
- Add a tester agent: Create
tester_agent
function that generates unit tests. Add node after refactorer.
Important
The tester agent's state key must be tests
for the utils function to be able to pick it up and add to the output folder.
- Change focus to security: Modify all prompts to emphasise security vulnerabilities instead of general quality.
- Add conditional routing: Route to different refactoring approaches based on code type (web, API, data processing).
- File:
patterns/02_conditional_routing.py
- Concept: Router analyzes content and routes to appropriate specialist
- Use case: Domain-specific expert selection based on code characteristics
Run and explore:
python patterns/02_conditional_routing.py
# Watch router decision in output
- Add database expert: Create
database_expert_agent
and update router logic to route SQL/schema code. - Smart routing: Make router consider task description as well as code content for routing decisions.
- Multi-expert routing: Allow router to send code to multiple experts when it contains mixed concerns.
Pattern 3: Parallel Processing 🧠⚙️⚙️⚙️📦
- File:
patterns/03_parallel_processing.py
- Concept: Concurrent analysis by multiple specialists
- Use case: Independent tasks that can run simultaneously
- File:
patterns/03_parallel_processing.py
- Concept: Concurrent analysis by multiple specialists
- Use case: Independent tasks that can run simultaneously
Run and explore:
python patterns/03_parallel_processing.py
# Check SYNTHESIS_REPORT.md
- Add documentation agent: Create
documentation_agent
that generates docstrings. Run in parallel. - Add fallback routing: If an expert agent fails, route to a general expert as fallback.
- Weighted synthesis: Give security 2x weight in final recommendations.
Pattern 4: Supervisor Agents 🧑🏫🧑🔧🧑🔬🗂️
- File:
patterns/04_supervisor_agents.py
- Concept: Intelligent coordination of specialist agents
- Use case: Complex tasks requiring dynamic expertise
- File:
patterns/04_supervisor_agents.py
- Concept: Intelligent coordination of specialist agents
- Use case: Complex tasks requiring dynamic expertise
Run and explore:
python patterns/04_supervisor_agents.py
# Check EXPERT_ANALYSIS.md
- Add database expert: Create
database_expert_agent
for SQL/schema review. Update supervisor logic.
Important
The database agent's state key must be database_report
for the utils function to be able to pick it up and add to the output folder.
- Smart content routing: Make supervisor check code content (e.g., "if 'sql' in code: route to database expert").
Important
The state key must be task_type
for the utils function to be able to pick it up and add to the output folder.
- Expert collaboration: Let security expert see quality report before finalising.
- File:
patterns/05_evaluator_optimiser.py
- Concept: Continuous improvement through feedback loops
- Use case: Iteratively refinable outputs
- File:
patterns/05_evaluator_optimiser.py
- Concept: Continuous improvement through feedback loops
- Use case: Iteratively refinable outputs
Run and explore:
python patterns/05_evaluator_optimiser.py
# Watch score progression
- Adjust thresholds: Change
quality_threshold = 7
to 9. How many iterations now? Play around withmax_iterations
too. - Add fast track: If initial score ≥ 8, skip refactoring entirely.
- Multi-criteria routing: Score separately for security, performance, readability. Route based on lowest score.
Pattern 6: Orchestrator-Worker 🎼👷👷♀️📋🔗
- File:
patterns/06_orchestrator_worker.py
- Concept: Dynamic task breakdown with isolated worker execution
- Use case: Complex tasks requiring unpredictable decomposition
Run and explore:
python patterns/06_orchestrator_worker.py
# Note dynamic worker creation
- Smart task detection: Make orchestrator identify task type (frontend, backend, database) and assign appropriate worker types.
- Worker specialisation: Create different worker agents for different task types with specialised prompts.
- Dependency handling: Allow orchestrator to create subtasks with dependencies (e.g., "database schema must complete before API").
- Understand: Run simple version, trace execution flow
- Experiment: Complete the 4 exercises for each pattern
- Analyse: Compare patterns - when would you choose each?
- Build: Combine patterns for your use case
- Deploy: Apply production-ready techniques from Pattern 6
Your Need | Use This Pattern |
---|---|
Step-by-step process | Sequential |
Quality-based branching | Conditional |
Speed through parallelism | Parallel |
Complex coordination | Supervisor |
Iterative improvement | Evaluator |
Dynamic task decomposition | Orchestrator |
Production deployment (any pattern) | + Production Concerns |
After completing all exercises:
- Identify your use case's requirements
- Select appropriate architectural pattern(s) (1-6)
- Combine patterns if needed, add tools
- Experiment using different models for different agents (perhaps a reasoning model for reviews etc)
- Apply production-ready techniques
- Deploy using LangGraph Platform
Remember: Master the patterns, then combine them creatively. Apply production concerns to make them deployment-ready. The best solution uses the simplest pattern that meets your requirements.