> ## Documentation Index
> Fetch the complete documentation index at: https://docs.venice.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# CrewAI 集成

> 使用 CrewAI 和 Venice 构建多 agent crew —— 将私有、无审查的 Venice 模型配置为 LLM 后端，实现基于角色的 agent 协作。

[CrewAI](https://www.crewai.com/) 允许您构建自主的多代理系统，其中专门化的 AI agent 协作完成复杂任务。得益于 OpenAI 兼容性，Venice AI 可作为 LLM 提供商即插即用。

## 设置

```bash theme={"system"}
pip install crewai crewai-tools
```

## 基本配置

使用 OpenAI 兼容接口将 Venice 配置为 CrewAI 的 LLM 提供商：

```python theme={"system"}
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"
```

或通过 LLM 对象按 agent 配置：

```python theme={"system"}
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,
)

# For complex reasoning tasks
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,
)
```

## 您的第一个 Crew

创建一个包含两个 agent 的简单研究 crew：

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

# Agent 1: Researcher
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,
)

# Agent 2: Writer
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: Research
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: Write article
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],  # Uses output from research_task
)

# Create and run the 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

包含专门化 agent 的更复杂示例：

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

# Different models for different agent capabilities
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")

# Market Analyst - needs intelligence
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 - benefits from uncensored thinking
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,  # Uncensored for honest criticism
    verbose=True,
)

# Strategist - needs reasoning
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,
)

# Tasks
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)
```

## 使用工具

通过 web 搜索和其他工具增强 agent：

<Note>
  `SerperDevTool` 需要来自 [serper.dev](https://serper.dev) 的 `SERPER_API_KEY` 环境变量。作为替代方案，您可以通过 `model_kwargs` 传递 `venice_parameters: {"enable_web_search": "auto"}` 来使用 Venice 的内置 web 搜索 —— 不需要额外的 API 密钥。请参阅 LangChain 指南的 [Web 搜索集成](/guides/integrations/langchain#web-search-integration)中的示例。
</Note>

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

# Web search tool (requires SERPER_API_KEY env var)
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"})
```

## CrewAI 模型选择指南

为每个 agent 角色选择合适的 Venice 模型：

| Agent 角色   | 推荐模型                                          | 原因                                 |
| ---------- | --------------------------------------------- | ---------------------------------- |
| 复杂推理/战略    | `zai-org-glm-5-1`                             | 最佳私有推理模型                           |
| 无审查分析/红队   | `venice-uncensored-1-2`                       | 无内容过滤                              |
| 大流量/快速任务   | `qwen3-5-9b`                                  | 最便宜，输入 $0.10/1M 与输出 $0.15/1M token |
| 代码生成 agent | `qwen3-coder-480b-a35b-instruct`              | 针对代码优化                             |
| 视觉/多模态任务   | `qwen3-vl-235b-a22b`                          | 高级视觉理解                             |
| 预算敏感团队     | `qwen3-5-9b`（快速）+ `venice-uncensored-1-2`（主力） | 低成本组合                              |

## 成本优化建议

1. **为更简单的 agent 使用更便宜的模型**：不是每个 agent 都需要旗舰模型。可使用 `qwen3-4b` 进行格式化、摘要或简单提取。

2. **创意/批评角色使用 `venice-uncensored`**：它快速、便宜，且不会拒绝令人不适的分析。

3. **将旗舰模型留给推理任务**：仅在需要复杂推理或可靠函数调用的 agent 上使用 `zai-org-glm-5-1`。

4. **限制最大迭代次数**：在 agent 上设置 `max_iter` 以防止 token 用量失控：
   ```python theme={"system"}
   agent = Agent(role="...", goal="...", backstory="...", llm=venice_llm, max_iter=5)
   ```

## 隐私优势

Venice 的隐私保障使其特别适合以下 CrewAI 用例：

* **机密商业战略** —— 零数据保留意味着您的竞争分析保持私密
* **敏感数据处理** —— 私有模型从不记录或存储您的数据
* **红队演练** —— 无审查模型在没有内容过滤的情况下给出诚实反馈

<CardGroup cols={2}>
  <Card title="CrewAI 文档" icon="book" href="https://docs.crewai.com/">
    官方 CrewAI 文档
  </Card>

  <Card title="Venice 模型" icon="database" href="/models/overview">
    浏览所有 Venice 模型
  </Card>
</CardGroup>
