CrewAI Agent 與 Task 入門:怎麼拆角色才不會亂成一團

3 min read

很多人用 CrewAI 第一次翻車,不是 API 問題,而是角色分工亂掉
只要你記住一個原則:一個 Agent 一種專長,一個 Task 一件事,成功率會高非常多。

先拆 Agent,再寫 Task

推薦這樣想:

  • Agent 是「誰」
  • Task 是「做什麼」
  • Context 是「前一步給後一步什麼資料」

如果你讓一個 Agent 同時研究、寫作、審稿,它通常會變成全都沾一點、全都不夠深。

好的 Agent 設計範例

researcher:
  role: >
    AI Research Analyst
  goal: >
    Collect accurate and current information
  backstory: >
    You specialize in finding reliable sources and extracting key facts.
  allow_delegation: false
 
writer:
  role: >
    Technical Writer
  goal: >
    Turn raw findings into clear and practical documentation
  backstory: >
    You explain complex ideas in simple language for beginners.
  allow_delegation: false

⚠️ allow_delegation 預設建議關掉,先把流程做穩,再考慮更動態的分派。

好的 Task 設計範例

research_task:
  description: >
    Find 8-10 important updates about {topic} in 2026.
    Include what changed and why it matters.
  expected_output: >
    A markdown bullet list.
    Each bullet includes: title, summary, and source URL.
  agent: researcher
 
write_task:
  description: >
    Convert the research bullets into a tutorial article with examples.
  expected_output: >
    A markdown article with intro, 3 sections, and conclusion.
  agent: writer
  context:
    - research_task

新手最常踩的 3 個坑

  1. Task 描述太短:模型不知道你要什麼格式
  2. 沒有 expected_output:輸出格式每次都漂
  3. 沒有 context:後續任務拿不到前面結果

一個簡單檢查表

每次寫完 YAML,請過這 5 題:

  • 這個 Agent 是不是只有一個專長?
  • 這個 Task 是不是只做一件事?
  • expected_output 有沒有寫清楚格式?
  • 任務依賴有沒有補 context
  • 誰輸出到檔案?有沒有設 output_file

下一步

分工清楚後,接著要決定「怎麼跑流程」。
下一篇直接帶你看 CrewProcess
👉 Crew 與 Process