CrewAI 中的规划功能允许您为团队添加规划能力。启用此功能后,在每次团队迭代之前,所有团队信息都将发送给 AgentPlanner,后者将逐步规划任务,并将此计划添加到每个任务描述中。
使用规划功能
开始使用规划功能非常简单,唯一需要做的就是为您的 Crew 添加 planning=True
from crewai import Crew, Agent, Task, Process
# Assemble your crew with planning capabilities
my_crew = Crew(
agents=self.agents,
tasks=self.tasks,
process=Process.sequential,
planning=True,
)
从现在开始,您的团队将启用规划功能,任务将在每次迭代前进行规划。
启用规划功能后,CrewAI 将使用 gpt-4o-mini 作为规划的默认 LLM,这需要有效的 OpenAI API 密钥。由于您的代理可能使用不同的 LLM,如果您没有配置 OpenAI API 密钥或遇到与 LLM API 调用相关的意外行为,这可能会导致混淆。
规划 LLM
现在您可以定义用于规划任务的 LLM。 运行基本案例示例时,您将看到类似以下输出的内容,它代表负责创建逐步逻辑以添加到代理任务的 AgentPlanner 的输出。from crewai import Crew, Agent, Task, Process
# Assemble your crew with planning capabilities and custom LLM
my_crew = Crew(
agents=self.agents,
tasks=self.tasks,
process=Process.sequential,
planning=True,
planning_llm="gpt-4o"
)
# Run the crew
my_crew.kickoff()