CrewAI是一款创新的AI协作平台,专为实现智能代理的角色分配、目标共享和协同作业而设计。无论是构建智能助理平台、自动化客服团队,还是多代理研究团队,CrewAI为复杂的多代理互动提供了坚实的支持。
为何选择CrewAI?
- 🤖 多角色代理设计:为代理定制具体角色、目标和工具,优化协作效率。
- 自主代理任务委派:代理之间可以自主分配任务,提高解决问题的效率。
- 灵活的任务管理:自定义任务的工具和分配方式,动态管理代理任务。
- 过程驱动:目前支持顺序任务执行,同时正在开发更复杂的共识和层级过程。
- 兼容开源模型:既可以使用Open AI,也可接入其他开源模型,实现更广泛的应用。
快速开始
CrewAI的使用流程简单明了。从安装开始,只需几步即可设置您的团队,并开始AI协作。
1. 安装
pip install crewai
如果您还想安装crewai-tools,这是一个包含代理可以使用的工具的软件包,但有更多依赖项,您可以安装它,下面的示例使用它:
pip install 'crewai[tools]'
2. 组建你的团队
import os
from crewai import Agent, Task, Crew, Process
from crewai_tools import SerperDevTool
os.environ["OPENAI_API_KEY"] = "YOUR_API_KEY"
os.environ["SERPER_API_KEY"] = "Your Key" # serper.dev API key
# You can choose to use a local model through Ollama for example. See https://docs.crewai.com/how-to/LLM-Connections/ for more information.
# os.environ["OPENAI_API_BASE"] = 'http://localhost:11434/v1'
# os.environ["OPENAI_MODEL_NAME"] ='openhermes' # Adjust based on available model
# os.environ["OPENAI_API_KEY"] ='sk-111111111111111111111111111111111111111111111111'
search_tool = SerperDevTool()
# Define your agents with roles and goals
researcher = Agent(
role='Senior Research Analyst',
goal='Uncover cutting-edge developments in AI and data science',
backstory="""You work at a leading tech think tank. Your expertise lies in identifying emerging trends. You have a knack for dissecting complex data and presenting actionable insights.""",
verbose=True,
allow_delegation=False,
tools=[search_tool]
# You can pass an optional llm attribute specifying what mode you wanna use.
# It can be a local model through Ollama / LM Studio or a remote
# model like OpenAI, Mistral, Antrophic or others (https://docs.crewai.com/how-to/LLM-Connections/)
#
# import os
# os.environ['OPENAI_MODEL_NAME'] = 'gpt-3.5-turbo'
#
# OR
#
# from langchain_openai import ChatOpenAI
# llm=ChatOpenAI(model_name="gpt-3.5", temperature=0.7)
)
writer = Agent(
role='Tech Content Strategist',
goal='Craft compelling content on tech advancements',
backstory="""You are a renowned Content Strategist, known for your insightful and engaging articles. You transform complex concepts into compelling narratives.""",
verbose=True,
allow_delegation=True
)
# Create tasks for your agents
task1 = Task(
description="""Conduct a comprehensive analysis of the latest advancements in AI in 2024. Identify key trends, breakthrough technologies, and potential industry impacts.""",
expected_output="Full analysis report in bullet points",
agent=researcher
)
task2 = Task(
description="""Using the insights provided, develop an engaging blog post that highlights the most significant AI advancements. Your post should be informative yet accessible, catering to a tech-savvy audience. Make it sound cool, avoid complex words so it doesn't sound like AI.""",
expected_output="Full blog post of at least 4 paragraphs",
agent=writer
)
# Instantiate your crew with a sequential process
crew = Crew(
agents=[researcher, writer],
tasks=[task1, task2],
verbose=2, # You can set it to 1 or 2 to different logging levels
)
# Get your crew to work!
result = crew.kickoff()
print("######################")
print(result)
os.environ[“OPENAI_API_KEY”] = “YOUR_API_KEY”
os.environ[“SERPER_API_KEY”] = “Your Key” # serper.dev API key
# You can choose to use a local model through Ollama for example. See https://docs.crewai.com/how-to/LLM-Connections/ for more information.
# os.environ[“OPENAI_API_BASE”] = ‘http://localhost:11434/v1′
# os.environ[“OPENAI_MODEL_NAME”] =’openhermes’ # Adjust based on available model
# os.environ[“OPENAI_API_KEY”] =’sk-111111111111111111111111111111111111111111111111′
search_tool = SerperDevTool()
# Define your agents with roles and goals
researcher = Agent(
role=’Senior Research Analyst’,
goal=’Uncover cutting-edge developments in AI and data science’,
backstory=”””You work at a leading tech think tank.
Your expertise lies in identifying emerging trends.
You have a knack for dissecting complex data and presenting actionable insights.”””,
verbose=True,
allow_delegation=False,
tools=[search_tool]
# You can pass an optional llm attribute specifying what mode you wanna use.
# It can be a local model through Ollama / LM Studio or a remote
# model like OpenAI, Mistral, Antrophic or others (https://docs.crewai.com/how-to/LLM-Connections/)
#
# import os
# os.environ[‘OPENAI_MODEL_NAME’] = ‘gpt-3.5-turbo’
#
# OR
#
# from langchain_openai import ChatOpenAI
# llm=ChatOpenAI(model_name=”gpt-3.5″, temperature=0.7)
)
writer = Agent(
role=’Tech Content Strategist’,
goal=’Craft compelling content on tech advancements’,
backstory=”””You are a renowned Content Strategist, known for your insightful and engaging articles.
You transform complex concepts into compelling narratives.”””,
verbose=True,
allow_delegation=True
)
# Create tasks for your agents
task1 = Task(
description=”””Conduct a comprehensive analysis of the latest advancements in AI in 2024.
Identify key trends, breakthrough technologies, and potential industry impacts.”””,
expected_output=”Full analysis report in bullet points”,
agent=researcher
)
task2 = Task(
description=”””Using the insights provided, develop an engaging blog
post that highlights the most significant AI advancements.
Your post should be informative yet accessible, catering to a tech-savvy audience.
Make it sound cool, avoid complex words so it doesn’t sound like AI.”””,
expected_output=”Full blog post of at least 4 paragraphs”,
agent=writer
)
# Instantiate your crew with a sequential process
crew = Crew(
agents=[researcher, writer],
tasks=[task1, task2],
verbose=2, # You can set it to 1 or 2 to different logging levels
)
# Get your crew to work!
result = crew.kickoff()
print(“######################”)
print(result)
关键特性
- 基于角色的代理设计:为代理定制具体的角色、目标和工具。
- 自主代理间的任务委派:代理可以自主地委派任务,增强问题解决的效率。
- 灵活的任务管理:定义可定制工具的任务,并动态分配给代理。
- 过程驱动:目前仅支持顺序任务执行,但正在研发更复杂的共识和层级过程。
- 与开源模型兼容:可以运行使用Open AI或其他开源模型的团队。
CrewAI与其他平台比较
CrewAI结合了Autogen的灵活性和ChatDev的结构化过程方法,但避免了这些平台的局限性。其过程设计旨在动态适应,无缝融入开发和生产工作流。
CrewAI不仅是一个多代理AI协作平台,更是未来智能协作的领导者。通过创新的技术和灵活的设计,CrewAI为各种规模和类型的团队提供了一个强大的AI协作环境,使得任务执行更加高效、协调和灵活。