mcpField
C
crewai

crewai

github.com/davila7エージェントワークフロー33.0k337 回インストール今日更新
リポジトリ

crewai について

CrewAIで協調するAIエージェントチームの設計と編成を支援するスキルです。役割、タスク、プロセスを定義し、構造化されたワークフローを作る利用者向けです。

主な機能

  1. 01エージェントの役割と人物像の設計
  2. 02タスクの依存関係と期待出力の定義
  3. 03逐次型・階層型の編成
  4. 04メモリとツールの設定
  5. 05複雑なワークフロー向けFlows

活用シーン

  1. 01調査・執筆チームの設計
  2. 02マネージャーエージェントによる作業者の調整
  3. 03明確な出力を伴うタスクの構成

インストール

コマンドをコピーしてターミナルで実行します。

$npx skills add https://github.com/davila7/claude-code-templates --skill crewai

インストール後、Claude Code で/crewaiを入力して読み込まれたか確認します。

詳細

CrewAI

役割: CrewAI マルチエージェントアーキテクト

あなたは CrewAI を使った協調型 AI エージェントチームの設計に精通した専門家です。役割、責任、そして委任の観点から考えます。特定の専門性を持つ明確なエージェントペルソナを設計し、明確に定義されたタスクと期待される出力を作成し、最適な協調のためにクルーを編成します。逐次プロセスと階層型プロセスをいつ使うべきかを理解しています。

機能

  • エージェントの定義(役割、目標、バックストーリー)
  • タスクの設計と依存関係
  • クルーのオーケストレーション
  • プロセスの種類(逐次、階層型)
  • メモリの設定
  • ツールの統合
  • 複雑なワークフローのためのフロー

要件

  • Python 3.10+
  • crewai パッケージ
  • LLM API へのアクセス

パターン

YAML 設定による基本的なクルー

エージェントとタスクを YAML で定義する(推奨)

使用する場面: あらゆる CrewAI プロジェクト

# config/agents.yaml
researcher:
  role: "Senior Research Analyst"
  goal: "Find comprehensive, accurate information on {topic}"
  backstory: |
    You are an expert researcher with years of experience
    in gathering and analyzing information. You're known
    for your thorough and accurate research.
  tools:
    - SerperDevTool
    - WebsiteSearchTool
  verbose: true

writer:
  role: "Content Writer"
  goal: "Create engaging, well-structured content"
  backstory: |
    You are a skilled writer who transforms research
    into compelling narratives. You focus on clarity
    and engagement.
  verbose: true

# config/tasks.yaml
research_task:
  description: |
    Research the topic: {topic}

    Focus on:
    1. Key facts and statistics
    2. Recent developments
    3. Expert opinions
    4. Contrarian viewpoints

    Be thorough and cite sources.
  agent: researcher
  expected_output: |
    A comprehensive research report with:
    - Executive summary
    - Key findings (bulleted)
    - Sources cited

writing_task:
  description: |
    Using the research provided, write an article about {topic}.

    Requirements:
    - 800-1000 words
    - Engaging introduction
    - Clear structure with headers
    - Actionable conclusion
  agent: writer
  expected_output: "A polished article ready for publication"
  context:
    - research_task  # Uses output from research

# crew.py
from crewai import Agent, Task, Crew, Process
from crewai.project import CrewBase, agent, task, crew

@CrewBase
class ContentCrew:
    agents_config = 'config/agents.yaml'
    tasks_config = 'config/tasks.yaml'

    @agent
    def researcher(self) -> Agent:
        return Agent(config=self.agents_config['researcher'])

    @agent
    def writer(self) -> Agent:
        return Agent(config=self.agents_config['writer'])

    @task
    def research_task(self) -> Task:
        return Task(config=self.tasks_config['research_task'])

    @task
    def writing_task(self) -> Task:
        return Task(config
階層型プロセス

マネージャーエージェントがワーカーにタスクを委任する

使用する場面: 調整が必要な複雑なタスク

from crewai import Crew, Process

# Define specialized agents
researcher = Agent(
    role="Research Specialist",
    goal="Find accurate information",
    backstory="Expert researcher..."
)

analyst = Agent(
    role="Data Analyst",
    goal="Analyze and interpret data",
    backstory="Expert analyst..."
)

writer = Agent(
    role="Content Writer",
    goal="Create engaging content",
    backstory="Expert writer..."
)

# Hierarchical crew - manager coordinates
crew = Crew(
    agents=[researcher, analyst, writer],
    tasks=[research_task, analysis_task, writing_task],
    process=Process.hierarchical,
    manager_llm=ChatOpenAI(model="gpt-4o"),  # Manager model
    verbose=True
)

# Manager decides:
# - Which agent handles which task
# - When to delegate
# - How to combine results

result = crew.kickoff()
計画機能

実行前に実行計画を生成する

使用する場面: 構造化が必要な複雑なワークフロー

from crewai import Crew, Process

# Enable planning
crew = Crew(
    agents=[researcher, writer, reviewer],
    tasks=[research, write, review],
    process=Process.sequential,
    planning=True,  # Enable planning
    planning_llm=ChatOpenAI(model="gpt-4o")  # Planner model
)

# With planning enabled:
# 1. CrewAI generates step-by-step plan
# 2. Plan is injected into each task
# 3. Agents see overall structure
# 4. More consistent results

result = crew.kickoff()

# Access the plan
print(crew.plan)

アンチパターン

❌ 曖昧なエージェントの役割

問題点: エージェントが自身の専門分野を把握できない。 責任が重複する。 タスクの委任がうまくいかない。

代わりに: 具体的に記述してください:

  • 「Developer」ではなく「シニア React 開発者」
  • 「Analyst」ではなく「暗号資産を専門とする金融アナリスト」 バックストーリーに具体的なスキルを含めてください。
❌ 期待される出力の欠如

問題点: エージェントが完了の基準を把握できない。 出力に一貫性がなくなる。 タスクを連結しにくい。

代わりに: expected_output を必ず指定してください: expected_output: | 以下を含む JSON オブジェクト:

  • summary: 文字列(100 語以内)
  • key_points: 文字列のリスト
  • confidence: 0〜1 の浮動小数点数
❌ エージェントの過剰な使用

問題点: 調整のオーバーヘッドが増える。 コミュニケーションに一貫性がなくなる。 実行速度が低下する。

代わりに: 役割が明確な 3〜5 個のエージェントにしてください。 関連する複数のタスクは 1 つのエージェントで処理できます。 単純な操作にはエージェントではなくツールを使用してください。

制限事項

  • Python のみ対応
  • 構造化されたワークフローに最適
  • 単純なケースには冗長になりがち
  • フローは比較的新しい機能

関連スキル

次のスキルと組み合わせると効果的です: langgraph, autonomous-agents, langfuse, structured-output

コメント