跳转到主要内容
CrewAI 允许您构建自主的多代理系统,其中专门化的 AI agent 协作完成复杂任务。得益于 OpenAI 兼容性,Venice AI 可作为 LLM 提供商即插即用。

设置

pip install crewai crewai-tools

基本配置

使用 OpenAI 兼容接口将 Venice 配置为 CrewAI 的 LLM 提供商:
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 配置:
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:
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 的更复杂示例:
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:
SerperDevTool 需要来自 serper.devSERPER_API_KEY 环境变量。作为替代方案,您可以通过 model_kwargs 传递 venice_parameters: {"enable_web_search": "auto"} 来使用 Venice 的内置 web 搜索 —— 不需要额外的 API 密钥。请参阅 LangChain 指南的 Web 搜索集成中的示例。
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.10/1M 与输出 0.15/1M token
代码生成 agentqwen3-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 用量失控:
    agent = Agent(role="...", goal="...", backstory="...", llm=venice_llm, max_iter=5)
    

隐私优势

Venice 的隐私保障使其特别适合以下 CrewAI 用例:
  • 机密商业战略 —— 零数据保留意味着您的竞争分析保持私密
  • 敏感数据处理 —— 私有模型从不记录或存储您的数据
  • 红队演练 —— 无审查模型在没有内容过滤的情况下给出诚实反馈

CrewAI 文档

官方 CrewAI 文档

Venice 模型

浏览所有 Venice 模型