Multi-agent AI workflows are at the heart of next-generation automation, powering everything from supply chain logistics to personalized enterprise productivity. In this tutorial, you’ll learn how to design, implement, and deploy a fully automated multi-agent workflow using open-source tools, with practical code and configuration you can test right now.
For broader context on architectures, use cases, and pitfalls, see our PILLAR: The 2026 Guide to Multi-Agent AI Workflow Automation—Architectures, Use Cases & Pitfalls.
Prerequisites
- Operating System: Linux (Ubuntu 22.04 LTS recommended) or macOS (Sonoma or later)
- Python: 3.10 or later
- Docker: 24.x or later
- Git: 2.40 or later
- Basic Knowledge: Python programming, Docker fundamentals, REST APIs, YAML configuration
- Open-Source Multi-Agent Orchestrator:
crewAI(v0.27+),LangGraph(v0.9+), orAutogen(v2.1+). We'll usecrewAIfor this tutorial. - API Keys: For local open-source LLMs (e.g., Ollama, LM Studio) or OpenAI/Anthropic if using cloud models (optional, but recommended for full automation)
-
Define Your Multi-Agent Workflow Concept
Before you write any code, clarify what your agents will do and how they’ll interact. For this tutorial, we’ll automate a document review process:
- Agent 1 (Extractor): Extracts key data from documents.
- Agent 2 (Validator): Checks data for errors or inconsistencies.
- Agent 3 (Summarizer): Writes an executive summary of findings.
This pattern is common in finance, legal, and compliance. For more on real-world applications, see How Multi-Agent AI Workflows Are Powering Complex Supply Chains in 2026.
Tip: Sketch your workflow as a flowchart or sequence diagram to visualize agent hand-offs.
-
Set Up Your Environment
-
Clone the Project Template
git clone https://github.com/crewai/crewai-starter multi-agent-demo cd multi-agent-demo
-
Create a Python Virtual Environment
python3 -m venv .venv source .venv/bin/activate
-
Install Dependencies
pip install -r requirements.txt
If you’re using
crewAI, make sure you have at least version 0.27:pip install crewai==0.27.0
-
Set Up a Local LLM (Optional but Recommended)
For offline, open-source LLMs, install Ollama and pull a model:
curl -fsSL https://ollama.com/install.sh | sh ollama pull mistralScreenshot description: Terminal showing successful
ollama pull mistraland model ready for inference. -
Configure API Keys (if using cloud LLMs)
export OPENAI_API_KEY=sk-xxxxxxx export ANTHROPIC_API_KEY=sk-ant-xxxxxx
-
Clone the Project Template
-
Define Your Agents
In
agents.py, define each agent’s role, tools, and communication patterns. Here’s a minimal example:from crewai import Agent, Tool def load_document(file_path): with open(file_path, 'r') as f: return f.read() extractor = Agent( name="Extractor", description="Extracts key data (e.g., names, dates, totals) from documents.", tools=[Tool(name="DocumentLoader", func=load_document)] ) validator = Agent( name="Validator", description="Validates extracted data for errors or inconsistencies.", tools=[] ) summarizer = Agent( name="Summarizer", description="Summarizes findings for executives.", tools=[] )Screenshot description: VSCode editor with
agents.pyopen, showing three agent classes with docstrings.For advanced agent design patterns, see Mastering Multi-Agent Coordination: How to Prevent Fail Loops in AI Workflow Automation.
-
Implement Agent Communication and Workflow Logic
In
workflow.py, orchestrate agent interactions.crewAIuses “crews” to manage agent flows.from crewai import Crew, Task from agents import extractor, validator, summarizer extract_task = Task( agent=extractor, description="Extract all relevant data from input.txt", input={"file_path": "input.txt"} ) validate_task = Task( agent=validator, description="Validate the extracted data for accuracy.", depends_on=[extract_task] ) summarize_task = Task( agent=summarizer, description="Summarize the validated data for an executive report.", depends_on=[validate_task] ) doc_review_crew = Crew( name="DocumentReviewCrew", tasks=[extract_task, validate_task, summarize_task] ) if __name__ == "__main__": doc_review_crew.run()Screenshot description: Terminal output showing agent logs—Extractor completes, Validator checks, Summarizer outputs summary.
-
Configure Workflow Parameters and LLM Backends
In
config.yaml, specify LLM endpoints and agent parameters. Example:llm_backend: ollama llm_model: mistral agents: extractor: temperature: 0.2 validator: temperature: 0.1 summarizer: temperature: 0.3 max_tokens: 512If you use OpenAI or Anthropic, update
llm_backendand provide API keys as environment variables.Screenshot description: YAML file open in editor, highlighting
llm_backend: ollamaand agent parameters.For more on cost optimization and backend selection, see How to Create Cost-Optimized Multi-Agent AI Workflows Without Sacrificing Performance.
-
Test Your Workflow Locally
-
Add a Sample Document
echo "Invoice #1234\nDate: 2026-04-25\nTotal: $1,500\nClient: Acme Corp" > input.txt
-
Run the Workflow
python workflow.py
Expected output:
[Extractor] Extracted: Invoice #1234, Date: 2026-04-25, Total: $1,500, Client: Acme Corp [Validator] Data validated: No errors found. [Summarizer] Executive summary generated. -
Review Agent Logs
Check logs for agent hand-off and error handling. Look for clear transitions between tasks.
For advanced validation and continuous testing, see Testing Multi-Agent AI Workflows: Frameworks, Metrics, and Continuous Validation.
-
Add a Sample Document
-
Containerize for Deployment
Use Docker to ensure portability. Create a
Dockerfile:FROM python:3.10-slim WORKDIR /app COPY . /app RUN pip install --upgrade pip && pip install -r requirements.txt CMD ["python", "workflow.py"]Build and test locally:
docker build -t multi-agent-demo . docker run --rm -v $(pwd)/input.txt:/app/input.txt multi-agent-demoScreenshot description: Docker build and run output, showing workflow completion inside the container.
For open-source deployment best practices, see Open-Source AgentOps: The Rise of Community-Led Workflow Automation Tools in 2026.
-
Automate and Schedule (Optional)
Use
cron(Linux/macOS) or a CI/CD tool to schedule your workflow. Examplecronjob to run every hour:0 * * * * cd /path/to/multi-agent-demo && /usr/bin/docker run --rm -v $(pwd)/input.txt:/app/input.txt multi-agent-demoFor enterprise-grade orchestration, consider tools like
Argo WorkflowsorAirflowfor complex scheduling and monitoring.
Common Issues & Troubleshooting
-
Agents not handing off tasks: Ensure
depends_onis set correctly in yourTaskdefinitions. -
LLM backend connection errors: Verify
ollamais running (ollama serve
). For remote APIs, check your API keys and network connectivity. -
Docker permission errors: Use
sudoif needed, or add your user to thedockergroup. -
Incorrect output or hallucinations: Lower the
temperatureinconfig.yamland add more explicit agent instructions. -
Resource constraints: Use lighter LLMs (e.g.,
mistralorphi-3) for local testing.
For common design mistakes, see Common Mistakes in Multi-Agent AI Workflow Design—And How to Avoid Them (2026).
Next Steps
- Expand Your Workflow: Add more agents (e.g., compliance checker, notification sender), or connect to real data sources and APIs.
- Secure Your Workflow: Implement authentication, rate limiting, and audit logging. See Securing Multi-Agent AI Workflows: Zero Trust Architectures for 2026.
- Production Deployment: Deploy on Kubernetes or serverless platforms for scalability.
- Ethics & Compliance: Review UN Publishes New 2026 Guidelines for Auditing Multi-Agent AI Workflows and The Ethics of Multi-Agent AI Workflows: Transparency, Bias & Human Accountability for responsible deployment.
- Deepen Your Knowledge: Explore the 2026 Guide to Multi-Agent AI Workflow Automation for advanced architectures and real-world case studies.
Related Tutorials: