CrewAI Crew 與 Process:為什麼新手應該先用 Sequential
Agent 和 Task 設計完之後,還有一個問題要回答:誰來決定這些任務按什麼順序跑?
答案就是 Crew 和 Process。
把 Crew 想成導演——它負責管理所有演員(Agent)和劇本(Task),決定誰先上場、怎麼流轉。Process 則是執行節奏,sequential 就是「按順序一個個來」,hierarchical 是「有一個管理者 Agent 自己決定分派順序」。
九成新手專案,用 Sequential 就對了
結論先說,不繞圈子:Process.sequential 是你的預設選擇。
原因不是它比較高級,而是它最容易理解、最好 debug、出問題最好定位。任務 A 做完,結果交給任務 B,B 做完交給 C——清楚、線性、可預期。
from crewai import Crew, Process
def build_crew(agents, tasks) -> Crew:
return Crew(
agents=agents,
tasks=tasks,
process=Process.sequential,
verbose=True,
)這段看起來很平淡,但其實幫你做了一個很重要的決定:流程是確定的,不依賴模型的臨場判斷。這對新手來說是很大的穩定性保障。
verbose=True 先開著——它會讓你在終端看到每個步驟的執行過程。除錯的時候你會很慶幸它開著。
Sequential 的核心優勢
不是功能比較多,而是出問題的時候你知道去哪裡找:
- 任務依賴關係清楚,每個 context 的資料流向都看得到
- 輸出可重現,同樣的輸入大概率得到類似的輸出
- 錯誤定位快,你知道是第幾步出了問題
- 成本可控,每個任務消耗多少 token 有跡可循
對剛開始的人來說,這就像先用普通難度破主線——不要一開始就挑地獄模式。
Hierarchical 是什麼,什麼時候才考慮
Hierarchical 的差別是:它會有一個「管理者 Agent」(manager),由它決定任務怎麼分派給各個執行 Agent,整個流程是動態的,而不是你事先寫死的順序。
這聽起來很炫,但代價是複雜度大幅上升——你需要設計管理者的 prompt、處理它的分派邏輯、還要確保它不會做出你不預期的決定。
考慮 Hierarchical 的前提是:
- 任務量非常多,且每次執行的任務組合不固定
- 你需要動態調整執行路徑(例如根據某個條件決定跳過某步驟)
- 你已經有穩定的監控、成本警戒、還有時間處理奇怪的 edge case
如果你現在還在調 expected_output 讓輸出穩定,先不要碰 hierarchical。真的,先不要。
把 Crew 的建立邏輯集中管理
一個實務建議:把建立 Crew 的程式碼集中在一個函式或類別,不要散落在各個地方。
from crewai import Crew, Process, Agent, Task
class ResearchCrewBuilder:
def __init__(self, topic: str):
self.topic = topic
def build(self) -> Crew:
researcher = Agent(
role=f"{self.topic} Researcher",
goal="Find accurate and current information",
backstory="You validate sources before passing information forward.",
allow_delegation=False,
verbose=True,
)
writer = Agent(
role="Technical Writer",
goal="Turn research into readable documentation",
backstory="You make complex ideas accessible to developers.",
allow_delegation=False,
verbose=True,
)
research_task = Task(
description=f"Research {self.topic}. Focus on 2026 developments.",
expected_output="10 bullet points with title, summary, and source URL.",
agent=researcher,
)
write_task = Task(
description="Convert research notes into a beginner-friendly article.",
expected_output="Markdown article with intro, 3 sections, and conclusion.",
agent=writer,
context=[research_task],
output_file="output/report.md",
)
return Crew(
agents=[researcher, writer],
tasks=[research_task, write_task],
process=Process.sequential,
verbose=True,
)這樣設計,你要換模型、換 process、加 callback,都改一個地方就好。不用在五個檔案裡找同一個 Crew 的設定。
常見問題
Q:verbose=True 會拖慢執行速度嗎?
不會。它只是把執行過程印到 terminal,不影響實際 LLM 呼叫速度。生產環境可以關掉,開發和除錯期間建議開著。
Q:sequential 的任務一定要按 list 順序執行嗎?
是的。tasks list 的順序就是執行順序。Task 的 context 可以指定吃某個前置任務的結果,但執行順序本身就是 list 的順序。
Q:Crew 可以有幾個 Agent?
沒有硬性上限,但 2-5 個是最常見的設計。Agent 太多,協作成本和除錯難度都會增加。先從最小可行的設計開始。
下一步
流程跑起來了,但 Agent 目前只能靠自己的知識回答——沒辦法查 Google、讀你的資料庫、或呼叫外部 API。下一篇來把工具接上去:
👉 Tools 整合