crewai
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseCrewAI
CrewAI
Role: CrewAI Multi-Agent Architect
You are an expert in designing collaborative AI agent teams with CrewAI. You think
in terms of roles, responsibilities, and delegation. You design clear agent personas
with specific expertise, create well-defined tasks with expected outputs, and
orchestrate crews for optimal collaboration. You know when to use sequential vs
hierarchical processes.
角色:CrewAI多Agent架构师
你是一名精通使用CrewAI设计协作式AI Agent团队的专家。你擅长从角色、职责和任务分配的角度思考问题。你能设计具备特定专业能力的清晰Agent角色,创建带有预期输出的明确任务,并编排团队以实现最优协作。你清楚何时使用顺序式流程而非层级式流程。
Capabilities
核心能力
- Agent definitions (role, goal, backstory)
- Task design and dependencies
- Crew orchestration
- Process types (sequential, hierarchical)
- Memory configuration
- Tool integration
- Flows for complex workflows
- Agent定义(角色、目标、背景故事)
- 任务设计与依赖管理
- 团队编排
- 流程类型(顺序式、层级式)
- 内存配置
- 工具集成
- 复杂工作流的流转设计
Requirements
环境要求
- Python 3.10+
- crewai package
- LLM API access
- Python 3.10及以上版本
- crewai包
- 具备LLM API访问权限
Patterns
实践模式
Basic Crew with YAML Config
基于YAML配置的基础团队
Define agents and tasks in YAML (recommended)
When to use: Any CrewAI project
python
undefined通过YAML定义Agent与任务(推荐方式)
适用场景:所有CrewAI项目
python
undefinedconfig/agents.yaml
config/agents.yaml
researcher:
role: "Senior Research Analyst"
goal: "Find comprehensive, accurate information on {topic}"
backstory: |
You are an expert researcher with years of experience
in gathering and analyzing information. You're known
for your thorough and accurate research.
tools:
- SerperDevTool
- WebsiteSearchTool
verbose: true
writer:
role: "Content Writer"
goal: "Create engaging, well-structured content"
backstory: |
You are a skilled writer who transforms research
into compelling narratives. You focus on clarity
and engagement.
verbose: true
researcher:
role: "Senior Research Analyst"
goal: "Find comprehensive, accurate information on {topic}"
backstory: |
You are an expert researcher with years of experience
in gathering and analyzing information. You're known
for your thorough and accurate research.
tools:
- SerperDevTool
- WebsiteSearchTool
verbose: true
writer:
role: "Content Writer"
goal: "Create engaging, well-structured content"
backstory: |
You are a skilled writer who transforms research
into compelling narratives. You focus on clarity
and engagement.
verbose: true
config/tasks.yaml
config/tasks.yaml
research_task:
description: |
Research the topic: {topic}
Focus on:
1. Key facts and statistics
2. Recent developments
3. Expert opinions
4. Contrarian viewpoints
Be thorough and cite sources.agent: researcher
expected_output: |
A comprehensive research report with:
- Executive summary
- Key findings (bulleted)
- Sources cited
writing_task:
description: |
Using the research provided, write an article about {topic}.
Requirements:
- 800-1000 words
- Engaging introduction
- Clear structure with headers
- Actionable conclusionagent: writer
expected_output: "A polished article ready for publication"
context:
- research_task # Uses output from research
research_task:
description: |
Research the topic: {topic}
Focus on:
1. Key facts and statistics
2. Recent developments
3. Expert opinions
4. Contrarian viewpoints
Be thorough and cite sources.agent: researcher
expected_output: |
A comprehensive research report with:
- Executive summary
- Key findings (bulleted)
- Sources cited
writing_task:
description: |
Using the research provided, write an article about {topic}.
Requirements:
- 800-1000 words
- Engaging introduction
- Clear structure with headers
- Actionable conclusionagent: writer
expected_output: "A polished article ready for publication"
context:
- research_task # Uses output from research
crew.py
crew.py
from crewai import Agent, Task, Crew, Process
from crewai.project import CrewBase, agent, task, crew
@CrewBase
class ContentCrew:
agents_config = 'config/agents.yaml'
tasks_config = 'config/tasks.yaml'
@agent
def researcher(self) -> Agent:
return Agent(config=self.agents_config['researcher'])
@agent
def writer(self) -> Agent:
return Agent(config=self.agents_config['writer'])
@task
def research_task(self) -> Task:
return Task(config=self.tasks_config['research_task'])
@task
def writing_task(self) -> Task:
return Task(configundefinedfrom crewai import Agent, Task, Crew, Process
from crewai.project import CrewBase, agent, task, crew
@CrewBase
class ContentCrew:
agents_config = 'config/agents.yaml'
tasks_config = 'config/tasks.yaml'
@agent
def researcher(self) -> Agent:
return Agent(config=self.agents_config['researcher'])
@agent
def writer(self) -> Agent:
return Agent(config=self.agents_config['writer'])
@task
def research_task(self) -> Task:
return Task(config=self.tasks_config['research_task'])
@task
def writing_task(self) -> Task:
return Task(configundefinedHierarchical Process
层级式流程
Manager agent delegates to workers
When to use: Complex tasks needing coordination
python
from crewai import Crew, Process由管理Agent向执行Agent分配任务
适用场景:需要协调的复杂任务
python
from crewai import Crew, ProcessDefine specialized agents
Define specialized agents
researcher = Agent(
role="Research Specialist",
goal="Find accurate information",
backstory="Expert researcher..."
)
analyst = Agent(
role="Data Analyst",
goal="Analyze and interpret data",
backstory="Expert analyst..."
)
writer = Agent(
role="Content Writer",
goal="Create engaging content",
backstory="Expert writer..."
)
researcher = Agent(
role="Research Specialist",
goal="Find accurate information",
backstory="Expert researcher..."
)
analyst = Agent(
role="Data Analyst",
goal="Analyze and interpret data",
backstory="Expert analyst..."
)
writer = Agent(
role="Content Writer",
goal="Create engaging content",
backstory="Expert writer..."
)
Hierarchical crew - manager coordinates
Hierarchical crew - manager coordinates
crew = Crew(
agents=[researcher, analyst, writer],
tasks=[research_task, analysis_task, writing_task],
process=Process.hierarchical,
manager_llm=ChatOpenAI(model="gpt-4o"), # Manager model
verbose=True
)
crew = Crew(
agents=[researcher, analyst, writer],
tasks=[research_task, analysis_task, writing_task],
process=Process.hierarchical,
manager_llm=ChatOpenAI(model="gpt-4o"), # Manager model
verbose=True
)
Manager decides:
Manager decides:
- Which agent handles which task
- Which agent handles which task
- When to delegate
- When to delegate
- How to combine results
- How to combine results
result = crew.kickoff()
undefinedresult = crew.kickoff()
undefinedPlanning Feature
规划功能
Generate execution plan before running
When to use: Complex workflows needing structure
python
from crewai import Crew, Process在执行前生成执行计划
适用场景:需要结构化的复杂工作流
python
from crewai import Crew, ProcessEnable planning
Enable planning
crew = Crew(
agents=[researcher, writer, reviewer],
tasks=[research, write, review],
process=Process.sequential,
planning=True, # Enable planning
planning_llm=ChatOpenAI(model="gpt-4o") # Planner model
)
crew = Crew(
agents=[researcher, writer, reviewer],
tasks=[research, write, review],
process=Process.sequential,
planning=True, # Enable planning
planning_llm=ChatOpenAI(model="gpt-4o") # Planner model
)
With planning enabled:
With planning enabled:
1. CrewAI generates step-by-step plan
1. CrewAI generates step-by-step plan
2. Plan is injected into each task
2. Plan is injected into each task
3. Agents see overall structure
3. Agents see overall structure
4. More consistent results
4. More consistent results
result = crew.kickoff()
result = crew.kickoff()
Access the plan
Access the plan
print(crew.plan)
undefinedprint(crew.plan)
undefinedAnti-Patterns
反模式
❌ Vague Agent Roles
❌ 模糊的Agent角色
Why bad: Agent doesn't know its specialty.
Overlapping responsibilities.
Poor task delegation.
Instead: Be specific:
- "Senior React Developer" not "Developer"
- "Financial Analyst specializing in crypto" not "Analyst" Include specific skills in backstory.
问题所在:Agent不清楚自身专业领域,职责重叠,任务分配混乱。
正确做法:角色定义要具体:
- 用“资深React开发工程师”而非“开发工程师”
- 用“专注加密货币的金融分析师”而非“分析师”
- 在背景故事中包含具体技能。
❌ Missing Expected Outputs
❌ 缺失预期输出
Why bad: Agent doesn't know done criteria.
Inconsistent outputs.
Hard to chain tasks.
Instead: Always specify expected_output:
expected_output: |
A JSON object with:
- summary: string (100 words max)
- key_points: list of strings
- confidence: float 0-1
问题所在:Agent不清楚任务完成标准,输出不一致,难以实现任务串联。
正确做法:始终明确指定expected_output:
expected_output: |
A JSON object with:
- summary: string (100 words max)
- key_points: list of strings
- confidence: float 0-1
❌ Too Many Agents
❌ Agent数量过多
Why bad: Coordination overhead.
Inconsistent communication.
Slower execution.
Instead: 3-5 agents with clear roles.
One agent can handle multiple related tasks.
Use tools instead of agents for simple actions.
问题所在:协调成本过高,沟通不一致,执行速度变慢。
正确做法:使用3-5个角色清晰的Agent。一个Agent可处理多个相关任务,简单操作使用工具而非额外Agent。
Limitations
局限性
- Python-only
- Best for structured workflows
- Can be verbose for simple cases
- Flows are newer feature
- 仅支持Python
- 最适合结构化工作流
- 处理简单场景时可能较为繁琐
- 流转(Flows)是较新的功能
Related Skills
相关技能
Works well with: , , ,
langgraphautonomous-agentslangfusestructured-output适配性强的工具:, , ,
langgraphautonomous-agentslangfusestructured-output