官方定義:crewAI helps you build agentic teams that collaborate using shared memory, tools, and workflows. It provides abstractions for roles, tasks, and communication.
核心賣點:
適用場景:
pip install crewai
from crewai import Agent, Task, Crew
from langchain.chat_models import ChatOpenAI
# 初始化 LLM
llm = ChatOpenAI(model="gpt-4o-mini")
# 定義兩個角色
researcher = Agent(
role="Researcher",
goal="研究最新的 AI 工具與框架",
backstory="你是一位專業技術研究員,擅長從多來源整理資訊。",
llm=llm
)
writer = Agent(
role="Writer",
goal="撰寫技術部落格文章",
backstory="你是一名文字編輯,善於用簡潔語言說明技術內容。",
llm=llm
)
# 定義任務
task = Task(
description="請合作撰寫一篇介紹 CrewAI 的技術文章。",
agents=[researcher, writer]
)
# 組成團隊
crew = Crew(agents=[researcher, writer], tasks=[task])
result = crew.run()
print(result)
這樣就能建立一個最小化的多 Agent 團隊,由研究員與寫手分工完成同一個任務。
crewAI 支援讓 Agent 使用工具(Tools),例如網頁搜尋、文件讀取、Python 程式執行:
from crewai_tools import SerperDevTool, BrowserTool, FileReadTool
search_tool = SerperDevTool()
browser = BrowserTool()
file_reader = FileReadTool()
researcher = Agent(
role="Researcher",
goal="找出最新 AI 框架趨勢",
backstory="你是一位技術研究員。",
tools=[search_tool, browser],
)
writer = Agent(
role="Writer",
goal="撰寫摘要與分析",
backstory="你是一名部落客。",
tools=[file_reader],
)
crewAI 支援設計任務流程:
from crewai import Process
crew = Crew(
agents=[researcher, writer],
tasks=[task],
process=Process.sequential # 也可設定為 concurrent 並行
)
crew.run()
可讓多 Agent 同時或依序執行,根據任務需求選擇流程策略。
技術:crewAI
分類:多智能體協作框架
難度:⭐⭐⭐☆☆(1–5 顆星)
實用度:⭐⭐⭐⭐⭐(1–5 顆星)
一句話:讓多個 AI Agent 能像團隊一樣分工合作完成任務。
適用情境:需要多角色 AI 協作(研究、撰文、測試、分析等)或自動化工作流。
crewAI 的設計讓我想到「AI 團隊的 Slack」:每個成員(Agent)都有自己的角色、目標與背景,然後透過自然語言協作完成任務。
它最大的價值是把多智能體協作「模組化」,不再需要手動寫互動邏輯,直接描述角色與流程即可。