> ## Documentation Index
> Fetch the complete documentation index at: https://veniceai-mintlify-d2fddb8a.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Integrazione CrewAI

> Costruisci crew multi-agente con CrewAI e Venice — configura i modelli Venice privati e senza censura come backend LLM per la collaborazione tra agenti basata sui ruoli.

[CrewAI](https://www.crewai.com/) ti consente di costruire sistemi multi-agente autonomi in cui agenti AI specializzati collaborano su compiti complessi. Venice AI funziona come provider LLM drop-in grazie alla compatibilità con OpenAI.

## Setup

```bash theme={null}
pip install crewai crewai-tools
```

## Configurazione di base

Configura Venice come provider LLM di CrewAI usando l'interfaccia compatibile con OpenAI:

```python theme={null}
import os

os.environ["OPENAI_API_KEY"] = "your-venice-api-key"
os.environ["OPENAI_API_BASE"] = "https://api.venice.ai/api/v1"
os.environ["OPENAI_MODEL_NAME"] = "venice-uncensored"
```

Oppure configura per agente con l'oggetto LLM:

```python theme={null}
from crewai import LLM

venice_llm = LLM(
    model="openai/venice-uncensored",
    api_key="your-venice-api-key",
    base_url="https://api.venice.ai/api/v1",
    temperature=0.7,
)

# Per compiti di ragionamento complessi
venice_flagship = LLM(
    model="openai/zai-org-glm-5-1",
    api_key="your-venice-api-key",
    base_url="https://api.venice.ai/api/v1",
    temperature=0.3,
)
```

## La tua prima crew

Crea una semplice crew di ricerca con due agenti:

```python theme={null}
from crewai import Agent, Task, Crew

# Agente 1: Ricercatore
researcher = Agent(
    role="Senior Research Analyst",
    goal="Find comprehensive, accurate information on the given topic",
    backstory="You are an expert researcher with a keen eye for detail. "
              "You excel at finding and synthesizing information from multiple sources.",
    llm=venice_flagship,
    verbose=True,
)

# Agente 2: Scrittore
writer = Agent(
    role="Content Strategist",
    goal="Create engaging, well-structured content from research findings",
    backstory="You are a skilled writer who transforms complex research "
              "into clear, compelling content that readers love.",
    llm=venice_llm,
    verbose=True,
)

# Task 1: Ricerca
research_task = Task(
    description="Research the topic: {topic}. "
                "Find key facts, recent developments, and expert opinions. "
                "Provide a structured summary with sources.",
    expected_output="A detailed research summary with key findings, "
                    "organized by subtopic, with at least 5 key points.",
    agent=researcher,
)

# Task 2: Scrivi l'articolo
write_task = Task(
    description="Using the research provided, write a compelling blog post "
                "about {topic}. Include an introduction, main sections, and conclusion.",
    expected_output="A well-written blog post of 500-800 words with clear sections.",
    agent=writer,
    context=[research_task],  # Usa l'output di research_task
)

# Crea ed esegui la crew
crew = Crew(
    agents=[researcher, writer],
    tasks=[research_task, write_task],
    verbose=True,
)

result = crew.kickoff(inputs={"topic": "The future of privacy-preserving AI"})
print(result)
```

## Crew multi-agente per analisi di prodotto

Un esempio più complesso con agenti specializzati:

```python theme={null}
from crewai import Agent, Task, Crew, Process

# Modelli diversi per capacità diverse degli agenti
fast_llm = LLM(model="openai/qwen3-5-9b", api_key="your-key", base_url="https://api.venice.ai/api/v1")
smart_llm = LLM(model="openai/zai-org-glm-5-1", api_key="your-key", base_url="https://api.venice.ai/api/v1")
uncensored_llm = LLM(model="openai/venice-uncensored-1-2", api_key="your-key", base_url="https://api.venice.ai/api/v1")

# Analista di mercato - serve intelligenza
market_analyst = Agent(
    role="Market Research Analyst",
    goal="Analyze market trends and competitive landscape",
    backstory="You are a veteran market analyst with 15 years of experience "
              "in tech markets. You provide unbiased, data-driven insights.",
    llm=smart_llm,
    verbose=True,
)

# Red Team - beneficia di un pensiero senza restrizioni
red_team = Agent(
    role="Red Team Critic",
    goal="Find weaknesses, risks, and potential failures in business strategies",
    backstory="You are a brutally honest critic who stress-tests ideas. "
              "You find every possible flaw and risk, no matter how uncomfortable.",
    llm=uncensored_llm,  # Senza restrizioni per critiche oneste
    verbose=True,
)

# Strategist - serve ragionamento
strategist = Agent(
    role="Business Strategist",
    goal="Synthesize analysis into actionable strategy recommendations",
    backstory="You are a McKinsey-trained strategist who creates clear, "
              "actionable plans from complex analyses.",
    llm=smart_llm,
    verbose=True,
)

# Task
market_task = Task(
    description="Analyze the market opportunity for: {product_idea}. "
                "Cover market size, competitors, trends, and target audience.",
    expected_output="Structured market analysis with TAM/SAM/SOM estimates, "
                    "top 5 competitors, and 3 key market trends.",
    agent=market_analyst,
)

critique_task = Task(
    description="Critically evaluate this product idea and market analysis. "
                "Find every weakness, risk, and potential failure mode. Be brutally honest.",
    expected_output="A list of at least 5 critical risks, 3 potential failure modes, "
                    "and honest assessment of whether this idea will succeed.",
    agent=red_team,
    context=[market_task],
)

strategy_task = Task(
    description="Based on the market analysis and red team critique, "
                "create a go-to-market strategy that addresses the identified risks.",
    expected_output="A clear go-to-market strategy with: positioning statement, "
                    "3 key differentiators, launch timeline, and risk mitigations.",
    agent=strategist,
    context=[market_task, critique_task],
)

crew = Crew(
    agents=[market_analyst, red_team, strategist],
    tasks=[market_task, critique_task, strategy_task],
    process=Process.sequential,
    verbose=True,
)

result = crew.kickoff(inputs={
    "product_idea": "A privacy-first AI coding assistant that runs on Venice API"
})
print(result)
```

## Usare i tool

Migliora gli agenti con web search e altri tool:

<Note>
  `SerperDevTool` richiede una variabile d'ambiente `SERPER_API_KEY` da [serper.dev](https://serper.dev). In alternativa, puoi usare la web search integrata di Venice passando `venice_parameters: {"enable_web_search": "auto"}` tramite `model_kwargs` — senza alcuna API key aggiuntiva. Vedi la guida LangChain alla [Web Search Integration](/guides/integrations/langchain#web-search-integration) per un esempio.
</Note>

```python theme={null}
from crewai_tools import SerperDevTool, WebsiteSearchTool
from crewai import Agent, Task, Crew

# Tool di web search (richiede la variabile d'ambiente SERPER_API_KEY)
search_tool = SerperDevTool()

researcher = Agent(
    role="Web Researcher",
    goal="Find the latest information on any topic",
    backstory="You are an expert web researcher.",
    llm=venice_flagship,
    tools=[search_tool],
    verbose=True,
)

task = Task(
    description="Research the latest developments in {topic} from the past week.",
    expected_output="A summary of 5 recent developments with dates and sources.",
    agent=researcher,
)

crew = Crew(agents=[researcher], tasks=[task], verbose=True)
result = crew.kickoff(inputs={"topic": "decentralized AI"})
```

## Guida alla scelta del modello per CrewAI

Scegli il modello Venice giusto per ogni ruolo di agente:

| Ruolo dell'agente                    | Modello consigliato                                          | Perché                                                          |
| ------------------------------------ | ------------------------------------------------------------ | --------------------------------------------------------------- |
| Ragionamento complesso / Strategia   | `zai-org-glm-5-1`                                            | Miglior modello di ragionamento privato                         |
| Analisi senza restrizioni / Red team | `venice-uncensored-1-2`                                      | Nessun filtro sui contenuti                                     |
| Alto volume / Compiti veloci         | `qwen3-5-9b`                                                 | Il più economico a $0,10/1M token input e $0,15/1M token output |
| Agenti di generazione di codice      | `qwen3-coder-480b-a35b-instruct`                             | Ottimizzato per il codice                                       |
| Compiti vision/multimodali           | `qwen3-vl-235b-a22b`                                         | Comprensione avanzata delle immagini                            |
| Team con budget limitato             | `qwen3-5-9b` (veloce) + `venice-uncensored-1-2` (principale) | Combinazione a basso costo                                      |

## Suggerimenti per l'ottimizzazione dei costi

1. **Usa modelli più economici per gli agenti più semplici**: non ogni agente ha bisogno di un modello di punta. Usa `qwen3-4b` per formattazione, riassunti o estrazione semplice.

2. **Usa `venice-uncensored` per ruoli creativi/critici**: è veloce, economico e non rifiuta analisi scomode.

3. **Riserva i modelli di punta per il ragionamento**: usa `zai-org-glm-5-1` solo per agenti che richiedono ragionamento complesso o un uso affidabile dei tool.

4. **Limita le iterazioni massime**: imposta `max_iter` sugli agenti per evitare un uso fuori controllo dei token:
   ```python theme={null}
   agent = Agent(role="...", goal="...", backstory="...", llm=venice_llm, max_iter=5)
   ```

## Vantaggio della privacy

Le garanzie di privacy di Venice lo rendono ideale per casi d'uso CrewAI che coinvolgono:

* **Strategia di business confidenziale** — Zero data retention significa che la tua analisi competitiva rimane privata
* **Elaborazione di dati sensibili** — I modelli privati non registrano né memorizzano mai i tuoi dati
* **Esercizi di red team** — I modelli senza restrizioni forniscono feedback onesto senza filtri sui contenuti

<CardGroup cols={2}>
  <Card title="Documentazione CrewAI" icon="book" href="https://docs.crewai.com/">
    Documentazione ufficiale CrewAI
  </Card>

  <Card title="Modelli Venice" icon="database" href="/models/overview">
    Sfoglia tutti i modelli Venice
  </Card>
</CardGroup>
