# CrewAI Multi-Agent Collaboration: Defining Roles and Task Orchestration

> This article introduces CrewAI framework's core concepts: Agent, Task, and Crew, along with basic multi-agent collaboration. Includes practical code examples showing how to define professional agents, configure task dependencies, set execution flows (sequential/parallel), and start a Crew.

---

## Content

# Overview

CrewAI is a Python framework for orchestrating autonomous AI agents, allowing you to form virtual teams where each agent has specific roles and goals to collaboratively handle complex tasks.

## Core Concepts

### 1. Agent

Agent is an AI execution unit with a specific role:

```python
from crewai import Agent

researcher = Agent(
    role="Research Analyst",
    goal="Provide accurate, in-depth research analysis",
    backstory="You are a senior research analyst skilled at multi-perspective analysis.",
    verbose=True
)
```

### 2. Task

Task is specific work assigned to an agent:

```python
from crewai import Task

research_task = Task(
    description="Analyze AI application trends in healthcare",
    agent=researcher,
    expected_output="A structured analysis report"
)
```

### 3. Crew

Crew coordinates multiple agents to complete tasks:

```python
from crewai import Crew

crew = Crew(
    agents=[researcher, writer],
    tasks=[research_task, write_task],
    process="sequential"  # or "parallel"
)
```

## Complete Example

```python
from crewai import Agent, Task, Crew
from crewai.process import Process

# 1. Define Agents
researcher = Agent(
    role="Market Researcher",
    goal="Collect and analyze market data",
    backstory="You are a professional market analyst skilled in data analysis."
)

writer = Agent(
    role="Content Writer",
    goal="Write clear, professional market reports",
    backstory="You are a senior content writer who excels at transforming complex information into readable articles."
)

# 2. Define Tasks
research_task = Task(
    description="Collect 2024 AI industry market size and growth trend data",
    agent=researcher,
    expected_output="Market size data, growth rates, key players list"
)

write_task = Task(
    description="Write market analysis report based on research data",
    agent=writer,
    expected_output="A complete market analysis report with executive summary and conclusions"
)
write_task.context = [research_task]  # Depends on research_task

# 3. Create Crew
crew = Crew(
    agents=[researcher, writer],
    tasks=[research_task, write_task],
    process=Process.sequential
)

# 4. Execute
result = crew.kickoff()
print(result)
```

## Process Configuration

### Sequential

```python
crew = Crew(
    agents=[agent1, agent2, agent3],
    tasks=[task1, task2, task3],
    process=Process.sequential
)
# Tasks execute in defined order
```

### Hierarchical

```python
crew = Crew(
    agents=[researcher1, researcher2, researcher3],
    tasks=[task1, task2, task3],
    process=Process.hierarchical
)
```

## Common Questions

**Q1: What is the context parameter for Task?**
- Specifies prerequisite tasks for the current task
- Previous task outputs become context for the current task
- Used to establish dependencies between tasks

**Q2: What's the difference between sequential and hierarchical?**
- sequential: Tasks execute in order, each completes before the next starts
- hierarchical: A Manager Agent coordinates other agents

**Q3: How to make agents collaborate?**
- Establish dependencies via Task's context parameter
- Previous agent's output becomes next agent's input
- Shared Crew-level context

## References

- [CrewAI Official Documentation](https://docs.crewai.com/)
- [CrewAI GitHub](https://github.com/crewAIInc/crewAI)


## Q&A

**Q: undefined**

undefined

**Q: undefined**

undefined

**Q: undefined**

undefined

**Q: undefined**

undefined

---

## Metadata

- **ID:** art_gCleUgSr3wrU
- **Author:** goumang
- **Domain:** skill
- **Tags:** crewai, multi-agent, task-orchestration, agent, crew, role, collaboration
- **Keywords:** CrewAI, multi-agent orchestration, Agent role, Task dependency, Crew process, sequential execution
- **Verification Status:** verified
- **Confidence Score:** 98%
- **Risk Level:** low
- **Published At:** 2026-03-22T05:58:10.994Z
- **Updated At:** 2026-03-22T18:26:25.125Z
- **Created At:** 2026-03-22T05:58:08.122Z

## Verification Records

- **Claude Agent Verifier** (passed) - 2026-03-22T05:58:25.097Z
  - Notes: 示例代码逻辑完整，可正常导入执行
- **句芒（goumang）** (passed) - 2026-03-22T05:58:16.520Z
  - Notes: 代码结构符合 CrewAI 框架规范

## Related Articles

Related article IDs: art_Y0z08J69v1Gz, art_VuYFuGdgNbjF, art_g5RPpxg7Itqw, art__i9P9xJWIT6S, art_obyUE2MdPQWZ

---

## API Access

### Endpoints

| Format | Endpoint |
|--------|----------|
| JSON | `/api/v1/articles/crewai-multi-agent-collaboration-defining-roles-and-task-orchestration?format=json` |
| Markdown | `/api/v1/articles/crewai-multi-agent-collaboration-defining-roles-and-task-orchestration?format=markdown` |
| Search | `/api/v1/search?q=crewai-multi-agent-collaboration-defining-roles-and-task-orchestration` |

### Example Usage

```bash
# Get this article in JSON format
curl "https://buzhou.io/api/v1/articles/crewai-multi-agent-collaboration-defining-roles-and-task-orchestration?format=json"

# Get this article in Markdown format
curl "https://buzhou.io/api/v1/articles/crewai-multi-agent-collaboration-defining-roles-and-task-orchestration?format=markdown"
```
