🤖 AI/AI Agent 🤖 AI/AI Agent 🤖 AI/AI Agent

CrewAI 多 Agent 協作:讓一組 AI 角色分工合作完成複雜專案

想讓 AI 像真實團隊一樣分工合作?CrewAI 讓你為每個 Agent 指派角色與目標,打造研究員、撰稿人、審閱者三角協作流程,自動完成複雜任務鏈。本文帶你從單一 Agent 進化到多 Agent 系統,解鎖 AI 協作的全新可能。

✍️ 峰値 PEAK · 2026年04月05日 · 约 27 分钟阅读 ~27 min read 約27分
cover 127

CrewAI 多 Agent 協作:讓一組 AI 角色分工合作完成複雜專案

CrewAI Multi-Agent Collaboration: Getting a Team of AI Roles to Divide and Conquer Complex Projects

CrewAI マルチエージェント協調:AI ロールチームが複雑なプロジェクトを分担して完成させる

用 CrewAI 打造研究、撰寫、審閱三角色協作流程,讓多 Agent 系統自動完成複雜任務鏈。

Build a researcher-writer-reviewer CrewAI pipeline and see how multi-agent systems tackle complex task chains automatically.

CrewAI でリサーチ・執筆・レビューの三役協調フローを構築し、複雜なタスクチェーンを自動処理する方法を解説。

這是《AI 工具實戰 30 天:從提示詞到 Agent,每天一個工具改變你的工作方式》系列第 20 篇,共 30 篇。走到第 20 天,我們從單一 Agent 的世界正式踏入多 Agent 協作的領域。今天的主角是 CrewAI——一個讓你像組建團隊一樣,為每個 AI 指派角色、任務與目標的開源框架。

This is Part 20 of 30 in the series “30 Days of AI Tools in Action: From Prompts to Agents, One Tool a Day to Transform Your Workflow.” At Day 20, we step beyond single-agent setups into the world of multi-agent collaboration. Today’s focus is CrewAI — an open-source framework that lets you assemble a team of AI agents, each with a defined role, task, and goal.

これは「AI ツール実践 30 日間:プロンプトから Agent まで、毎日一つのツールで仕事を変える」シリーズの第 20 篇(全 30 篇)です。20 日目となる今日は、単一 Agent の世界を超え、マルチエージェント協調の領域へ踏み込みます。今回の主役は CrewAI——チームを組むように各 AI にロール・タスク・目標を割り当てられるオープンソースフレームワークです。

為什麼需要多 Agent?Why Do We Need Multiple Agents?なぜマルチエージェントが必要なのか?

單一 LLM 在處理複雜任務時容易「什麼都做、什麼都做不好」。多 Agent 的核心思想是分工:讓擅長研究的 Agent 專注蒐集資料,讓擅長寫作的 Agent 負責生成內容,讓審閱 Agent 把關品質。每個角色只做自己最擅長的事,最終輸出遠優於單一模型獨自完成的結果。CrewAI 把這個概念包裝成直覺的 Python API,讓開發者幾十行程式碼就能建立完整的協作流程。

A single LLM handling a complex task often ends up doing everything poorly. The core idea behind multi-agent systems is specialization: a research agent focuses on gathering data, a writing agent handles content generation, and a review agent ensures quality. Each role does what it does best, and the combined output far exceeds what any single model could produce alone. CrewAI wraps this concept into an intuitive Python API, letting developers build complete collaborative pipelines in just a few dozen lines of code.

単一の LLM が複雑なタスクを処理しようとすると、「何でもやるが何も上手くできない」状態に陥りがちです。マルチエージェントの核心は分業にあります。リサーチ Agent はデータ収集に専念し、ライティング Agent はコンテンツ生成を担当し、レビュー Agent が品質を管理します。各ロールが得意なことだけを行うことで、単一モデルが単独で出す結果をはるかに上回るアウトプットが得られます。CrewAI はこのコンセプトを直感的な Python API に落とし込み、数十行のコードで完全な協調フローを構築できます。

CrewAI 核心概念:Agent、Task、CrewCrewAI Core Concepts: Agent, Task, and CrewCrewAI のコアコンセプト:Agent・Task・Crew

CrewAI 有三個核心物件。Agent 定義角色身份,包含 role(職稱)、goal(目標)、backstory(背景故事)三個欄位,這些描述直接影響 LLM 的行為模式。Task 定義具體工作,包含 description(任務說明)與 expected_output(預期輸出),並指定由哪個 Agent 執行。Crew 則是把所有 Agent 與 Task 組合起來,設定執行順序(sequential 或 hierarchical),然後呼叫 crew.kickoff() 啟動整個流程。三者的關係就像公司架構:Agent 是員工、Task 是工作項目、Crew 是專案團隊。

CrewAI has three core objects. An Agent defines a role identity with three fields: role (job title), goal (objective), and backstory (background narrative) — all of which directly shape the LLM’s behavior. A Task defines the actual work, including a description and expected_output, and specifies which agent executes it. A Crew assembles all agents and tasks, sets the execution order (sequential or hierarchical), and launches everything with crew.kickoff(). Think of it like a company structure: agents are employees, tasks are work items, and the crew is the project team.

CrewAI には三つのコアオブジェクトがあります。Agent はロールのアイデンティティを定義し、role(役職)・goal(目標)・backstory(背景ストーリー)の三フィールドで構成され、これらが LLM の振る舞いに直接影響します。Task は具体的な作業を定義し、description と expected_output を持ち、担当 Agent を指定します。Crew はすべての Agent と Task を組み合わせ、実行順序(sequential または hierarchical)を設定し、crew.kickoff() で全体を起動します。会社組織に例えると、Agent は社員、Task は業務項目、Crew はプロジェクトチームです。

實作:研究 → 撰寫 → 審閱的三角色任務鏈Hands-On: A Three-Role Task Chain — Research → Write → Review実践:リサーチ → 執筆 → レビューの三役タスクチェーン

以下是一個完整的 CrewAI 範例,模擬「撰寫一篇 AI 趨勢報告」的任務鏈:

“`python
from crewai import Agent, Task, Crew, Process

# 定義三個 Agent
researcher = Agent(
role=’資深研究員’,
goal=’蒐集最新 AI 工具趨勢的可靠資訊’,
backstory=’你是一位專注科技領域的研究員,擅長從多方來源整理重點。’
)

writer = Agent(
role=’內容撰寫師’,
goal=’將研究結果轉化為清晰易讀的文章’,
backstory=’你是一位技術寫作專家,擅長將複雜概念用簡單語言表達。’
)

reviewer = Agent(
role=’品質審閱員’,
goal=’確保文章準確、流暢且符合讀者需求’,
backstory=’你是一位嚴謹的編輯,專注於邏輯一致性與表達清晰度。’
)

# 定義三個 Task
research_task = Task(
description=’研究 2025 年最重要的五個 AI Agent 工具趨勢’,
expected_output=’條列式重點摘要,每點附上說明’,
agent=researcher
)

write_task = Task(
description=’根據研究結果撰寫一篇 500 字的趨勢分析文章’,
expected_output=’結構完整的文章,含標題與段落’,
agent=writer
)

review_task = Task(
description=’審閱文章,指出需要修正的地方並提供改善建議’,
expected_output=’審閱報告,含具體修改意見’,
agent=reviewer
)

# 組建 Crew 並執行
crew = Crew(
agents=[researcher, writer, reviewer],
tasks=[research_task, write_task, review_task],
process=Process.sequential
)

result = crew.kickoff()
print(result)
“`

這段程式碼展示了 CrewAI 最核心的使用模式:每個 Agent 的 backstory 讓 LLM 進入對應的角色狀態,Task 的 expected_output 約束輸出格式,Process.sequential 確保任務按順序傳遞,前一個任務的輸出自動成為下一個任務的輸入。

Here’s a complete CrewAI example simulating a task chain for writing an AI trends report:

“`python
from crewai import Agent, Task, Crew, Process

researcher = Agent(
role=’Senior Researcher’,
goal=’Gather reliable information on the latest AI tool trends’,
backstory=’You are a tech-focused researcher skilled at synthesizing insights from multiple sources.’
)

writer = Agent(
role=’Content Writer’,
goal=’Transform research findings into clear, readable articles’,
backstory=’You are a technical writing expert who excels at explaining complex concepts simply.’
)

reviewer = Agent(
role=’Quality Reviewer’,
goal=’Ensure the article is accurate, fluent, and reader-friendly’,
backstory=’You are a meticulous editor focused on logical consistency and clarity.’
)

research_task = Task(
description=’Research the five most important AI Agent tool trends in 2025′,
expected_output=’Bullet-point summary with explanations for each trend’,
agent=researcher
)

write_task = Task(
description=’Write a 500-word trend analysis article based on the research’,
expected_output=’A well-structured article with title and paragraphs’,
agent=writer
)

review_task = Task(
description=’Review the article and provide specific improvement suggestions’,
expected_output=’A review report with concrete revision notes’,
agent=reviewer
)

crew = Crew(
agents=[researcher, writer, reviewer],
tasks=[research_task, write_task, review_task],
process=Process.sequential
)

result = crew.kickoff()
print(result)
“`

This code demonstrates CrewAI’s core pattern: each agent’s backstory primes the LLM into the right role, expected_output constrains the format, and Process.sequential ensures each task’s output automatically feeds into the next.

以下は「AI トレンドレポート執筆」タスクチェーンをシミュレートする完全な CrewAI サンプルです:

“`python
from crewai import Agent, Task, Crew, Process

researcher = Agent(
role=’シニアリサーチャー’,
goal=’最新の AI ツールトレンドに関する信頼性の高い情報を収集する’,
backstory=’あなたは複数のソースから要点を整理するのが得意なテック系リサーチャーです。’
)

writer = Agent(
role=’コンテンツライター’,
goal=’リサーチ結果を分かりやすい記事に変換する’,
backstory=’あなたは複雑な概念をシンプルな言葉で伝えるのが得意なテクニカルライターです。’
)

reviewer = Agent(
role=’品質レビュアー’,
goal=’記事の正確性・流暢さ・読者への適合性を確保する’,
backstory=’あなたは論理的一貫性と表現の明確さに注力する厳格な編集者です。’
)

research_task = Task(
description=’2025 年に最も重要な AI Agent ツールトレンド 5 つをリサーチする’,
expected_output=’各トレンドの説明付き箇条書きサマリー’,
agent=researcher
)

write_task = Task(
description=’リサーチ結果をもとに 500 字のトレンド分析記事を執筆する’,
expected_output=’タイトルと段落を含む構成の整った記事’,
agent=writer
)

review_task = Task(
description=’記事をレビューし、具体的な改善提案を提供する’,
expected_output=’具体的な修正コメントを含むレビューレポート’,
agent=reviewer
)

crew = Crew(
agents=[researcher, writer, reviewer],
tasks=[research_task, write_task, review_task],
process=Process.sequential
)

result = crew.kickoff()
print(result)
“`

このコードは CrewAI のコアパターンを示しています。各 Agent の backstory が LLM を適切なロール状態に誘導し、expected_output が出力形式を制約し、Process.sequential が前タスクの出力を次タスクへ自動的に引き渡します。

進階技巧:工具整合與 Hierarchical 模式Advanced Tips: Tool Integration and Hierarchical Mode応用テクニック:ツール統合と Hierarchical モード

CrewAI 的 Agent 可以配備工具(Tools),例如網路搜尋、程式執行、檔案讀寫等,讓 Agent 不只是「思考」,還能真正「行動」。只需在 Agent 初始化時傳入 tools=[SerperDevTool()] 即可讓研究員 Agent 具備即時搜尋能力。此外,除了 sequential 模式,CrewAI 還支援 hierarchical 模式,由一個 Manager Agent 動態分配任務給其他 Agent,更接近真實的管理架構。對於需要根據中間結果調整後續步驟的複雜任務,hierarchical 模式能提供更大的彈性。安裝方式非常簡單:pip install crewai crewai-tools,搭配任何支援的 LLM(OpenAI、Anthropic、本地 Ollama 皆可)即可上手。

CrewAI agents can be equipped with tools — web search, code execution, file I/O, and more — so they don’t just think, they act. Simply pass tools=[SerperDevTool()] when initializing an agent to give your researcher real-time search capability. Beyond sequential mode, CrewAI also supports hierarchical mode, where a Manager Agent dynamically assigns tasks to other agents, mirroring a real management structure. For complex tasks that need to adapt based on intermediate results, hierarchical mode offers much greater flexibility. Getting started is straightforward: pip install crewai crewai-tools, then pair it with any supported LLM — OpenAI, Anthropic, or a local Ollama instance.

CrewAI の Agent にはツールを装備できます。ウェブ検索・コード実行・ファイル読み書きなど、Agent は「考える」だけでなく「行動」できるようになります。Agent 初期化時に tools=[SerperDevTool()] を渡すだけで、リサーチャー Agent にリアルタイム検索能力を付与できます。sequential モードに加え、CrewAI は hierarchical モードもサポートしており、Manager Agent が他の Agent にタスクを動的に割り当てる、より実際の管理構造に近い形を実現します。中間結果に応じて後続ステップを調整する必要がある複雑なタスクには、hierarchical モードがより大きな柔軟性を提供します。導入は簡単で、pip install crewai crewai-tools を実行し、OpenAI・Anthropic・ローカル Ollama など対応 LLM と組み合わせるだけです。

今日重點回顧Key Takeaways今日のまとめ

CrewAI 讓多 Agent 協作從概念變成可執行的程式碼。三個核心物件(Agent、Task、Crew)清晰分離了「誰來做」、「做什麼」、「怎麼協調」三個維度。透過 backstory 塑造角色、透過 expected_output 約束輸出、透過 process 控制流程,你可以在幾十行程式碼內建立一個能自動完成研究、撰寫、審閱全流程的 AI 工作團隊。這正是 Agent 系統的核心價值:把複雜任務拆解成可管理的角色與步驟,讓 AI 真正成為你的工作夥伴。

上一篇:RAG 實戰:讓 AI 讀懂你的私有文件,打造企業專屬知識問答系統

下一篇(第21篇)預告:OpenAI Assistants API:為你的產品嵌入有記憶、會用工具的 AI 助理

CrewAI turns multi-agent collaboration from a concept into executable code. The three core objects — Agent, Task, Crew — cleanly separate “who does it,” “what gets done,” and “how it’s coordinated.” By shaping roles with backstory, constraining output with expected_output, and controlling flow with process, you can build an AI work team that autonomously handles research, writing, and review in just a few dozen lines. That’s the core value of agent systems: decomposing complex tasks into manageable roles and steps, making AI a genuine working partner.

Previous: RAG in Action: Making AI Understand Your Private Documents for an Enterprise Knowledge Q&A System

Next up (Part 21): OpenAI Assistants API — Embedding a Memory-Enabled, Tool-Using AI Assistant into Your Product

CrewAI はマルチエージェント協調をコンセプトから実行可能なコードへと変えます。三つのコアオブジェクト(Agent・Task・Crew)が「誰がやるか」「何をやるか」「どう調整するか」を明確に分離します。backstory でロールを形成し、expected_output で出力を制約し、process でフローを制御することで、数十行のコードでリサーチ・執筆・レビューを自律的にこなす AI ワークチームを構築できます。これこそが Agent システムの核心的価値です。複雑なタスクを管理可能なロールとステップに分解し、AI を真の仕事のパートナーにすること。

前の記事:RAG 実践:AI にプライベート文書を読み込ませ、企業専用ナレッジ Q&A システムを構築する

次回(第 21 篇)予告:OpenAI Assistants API:記憶を持ちツールを使える AI アシスタントをプロダクトに組み込む

峰値
峰値 PEAK / 阿峰
全端开发者 · 套利交易员 · 在日创业者
Full-Stack Dev · Arb Trader · Japan-based Founder
フルスタック開発者 · アービトラージトレーダー · 在日起業家

在大阪构建系统、做套利交易、探索 AI Agent。相信系统的力量大于意志力。

Building systems, trading arb, exploring AI agents from Osaka. Systems over willpower.

大阪でシステムを構築し、アービトラージ取引を行い、AIエージェントを探求。システムは意志力を超える。

返回AI/AI Agent板块 Back to AI/AI Agent AI/AI Agentへ戻る 所有文章 →All Posts →すべての記事 →