# CrewAI

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

[CrewAI](https://docs.crewai.com/) builds role-playing multi-agent systems. It routes OpenAI-compatible providers through LiteLLM, installed with the `litellm` extra — so ai& works by setting two env vars.

## Setup

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

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

## A two-agent 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())
```

## With tools

```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">
  Note the `openai/` prefix in `LLM(model="openai/google/gemma-4-31b-it")` — LiteLLM uses it to mean "OpenAI-compatible provider," and `google/gemma-4-31b-it` after it is the actual ai& model id.
</Aside>
