Giới thiệu
Một agent đơn lẻ có giới hạn. CrewAI cho phép bạn tạo đội ngũ agents với vai trò khác nhau, cộng tác để hoàn thành task phức tạp — giống như team thật.
1. CrewAI Concepts
from crewai import Agent, Task, Crew
researcher = Agent(
role="Senior Researcher",
goal="Tìm kiếm và tổng hợp thông tin chính xác",
backstory="Bạn là researcher 10 năm kinh nghiệm...",
tools=[web_search_tool],
)
writer = Agent(
role="Content Writer",
goal="Viết bài viết hấp dẫn từ research",
backstory="Bạn là technical writer...",
)
editor = Agent(
role="Editor",
goal="Review và polish bài viết",
backstory="Bạn là senior editor...",
)
# Define tasks
research_task = Task(description="Research about AI Agents trends 2025", agent=researcher)
write_task = Task(description="Write a blog post from the research", agent=writer)
edit_task = Task(description="Edit and polish the blog post", agent=editor)
# Assemble crew
crew = Crew(agents=[researcher, writer, editor], tasks=[research_task, write_task, edit_task])
result = crew.kickoff()
Tóm tắt
- CrewAI = team of agents with specialized roles
- Agent = role + goal + backstory + tools
- Task = work item assigned to an agent
- Process types: sequential, hierarchical, consensual
Bài tập
- Xây content creation pipeline: Researcher → Writer → Editor
- Implement hierarchical process với Manager agent
- Thêm custom tools cho mỗi agent
- So sánh output quality: 1 agent vs 3-agent crew