# CrewAI

Source: https://aiand-docs-staging.pages.dev/ja/integrations/crewai/

[CrewAI](https://docs.crewai.com/) は役割ベースのマルチエージェントシステムを構築するフレームワークです。OpenAI 互換プロバイダへの接続には LiteLLM（`litellm` extra でインストール）を使用しており、環境変数を 2 つ設定するだけで ai& と接続できます。

## セットアップ

```bash
pip install 'crewai[litellm]'
```

```bash
export OPENAI_API_KEY="sk-your-aiand-api-key"
export OPENAI_API_BASE="https://api.aiand.com/v1"
```

## 2 エージェントの crew

```python
from crewai import Agent, Task, Crew, LLM

llm = LLM(model="openai/google/gemma-4-31b-it")

researcher = Agent(
    role="Researcher",
    goal="Find accurate information",
    backstory="An experienced research analyst.",
    llm=llm,
)

writer = Agent(
    role="Writer",
    goal="Write a clear summary",
    backstory="A concise technical writer.",
    llm=llm,
)

research_task = Task(
    description="Research the city of Tokyo — population, history, notable features.",
    expected_output="Bullet points covering the key facts.",
    agent=researcher,
)

write_task = Task(
    description="Write a 100-word summary based on the research.",
    expected_output="A 100-word paragraph.",
    agent=writer,
)

crew = Crew(agents=[researcher, writer], tasks=[research_task, write_task])
print(crew.kickoff())
```

## ツール付き

```python
from crewai.tools import tool

@tool("get_weather")
def get_weather(city: str) -> str:
    """Get current weather for a city."""
    return f"Sunny in {city}, 22°C"

researcher = Agent(
    role="Weather Reporter",
    goal="Answer weather questions",
    backstory="A meteorologist.",
    llm=llm,
    tools=[get_weather],
)
```

<Aside type="note">
  `LLM(model="openai/google/gemma-4-31b-it")` の `openai/` プレフィックスに注意 — LiteLLM ではこれが「OpenAI 互換プロバイダ」を意味し、その後ろの `google/gemma-4-31b-it` が実際の ai& のモデル ID です。
</Aside>
