ARTICLE DETAIL

资讯详情

深耕郑州网站建设与运营推广的一线实战洞察。

CrewAI 如何启用 planning 让 Crew 每轮迭代前生成任务计划

CrewAI 如何启用 planning 让 Crew 每轮迭代前生成任务计划 CrewAI 如何启用 planning 让 Crew 每轮迭代前生成任务计划【免费下载链接】crewAIFramework for orchestrating role-playing, autonomous AI agents. By fostering collaborative intelligence, CrewAI empowers agents to work together seamlessly, tackling complex tasks.项目地址: https://gitcode.com/GitHub_Trending/cr/crewAI在 CrewAI 中如果你的 Crew 任务较多、执行顺序复杂可以让框架在每轮迭代开始前先生成一份逐步任务计划启用 planning 后每次 Crew 迭代前所有 Crew 信息都会发送给AgentPlanner由它规划任务执行的步骤并将这份计划追加到每个任务的描述中供 Agent 执行时参考。本文基于官方概念文档 Planning 和 Crews 说明如何开启该功能、指定计划所用的 LLM以及如何确认计划已生成。前置条件启用 planning 前你需要有一个可以运行的 Crew即已经定义好 agents、tasks 并组装了Crew对象代码定义或 JSONC/YAML 配置均可。另一个硬性前提涉及默认计划模型开启 planning 后CrewAI 默认使用gpt-4o-mini作为计划 LLM因此需要配置有效的 OpenAI API key。如果你的 Agent 使用的是其他 LLM 供应商而环境中没有 OpenAI API key或者出现了与 LLM API 调用相关的意外行为官方文档提示这可能是 planning 默认模型导致的——此时应通过planning_llm显式指定计划所用的模型。这两个参数在 Crews 属性表中的定义planningoptional为 Crew 增加规划能力激活后每轮迭代前所有 Crew 数据会发送给 AgentPlannerplanning_llmoptional是 AgentPlanner 在规划过程中使用的语言模型。在代码中启用 planning在组装Crew时加上planningTrue即可这是文档给出的唯一必需步骤from crewai import Crew, Agent, Task, Process # Assemble your crew with planning capabilities my_crew Crew( agentsself.agents, tasksself.tasks, processProcess.sequential, planningTrue, )示例中的self.agents、self.tasks指代你当前 Crew 的 agent 列表和 task 列表需要替换为你项目中实际定义的对象例如经典项目模板中的agent、task方法或agents/、config/tasks.yaml加载出的列表其余字段保持原样即可。从这一步开始Crew 即处于 planning 开启状态每轮迭代前任务都会被规划一次。指定计划所用的 LLM可选分支如果不想使用默认的gpt-4o-mini或者环境里没有 OpenAI key可以在创建 Crew 时传入planning_llm并调用kickoff()运行from crewai import Crew, Agent, Task, Process # Assemble your crew with planning capabilities and custom LLM my_crew Crew( agentsself.agents, tasksself.tasks, processProcess.sequential, planningTrue, planning_llmgpt-4o ) # Run the crew my_crew.kickoff()其中planning_llmgpt-4o是文档示例值你可以换成自己环境中可用的模型名。使用 JSONC 配置的 Crew可选分支如果你的项目是crewai create crew name生成的新式项目通过crew.jsonc管理 Crew 级别设置JSON crew 定义同样支持planning、planning_llm这些 crew 级字段与process、verbose、memory等并列。crewai run会自动检测crew.jsonc、加载引用 agents 并发起 kickoff。如何确认 planning 已生效运行my_crew.kickoff()后文档展示的运行输出以一行 INFO 日志开头随后打印AgentPlanner生成的逐步计划。以下是文档示例实际计划内容会随你的任务而变化[2024-07-15 16:49:11][INFO]: Planning the crew execution **Step-by-Step Plan for Task Execution** **Task Number 1: Conduct a thorough research about AI LLMs** **Agent:** AI LLMs Senior Data Researcher **Agent Goal:** Uncover cutting-edge developments in AI LLMs **Task Expected Output:** A list with 10 bullet points of the most relevant information about AI LLMs ... **Step-by-Step Plan:** 1. **Define Research Scope:** ...判断方式在执行日志中看到Planning the crew execution及按任务编号组织、包含每个任务的Step-by-Step Plan的计划文本说明规划已执行且该计划会被追加到各任务描述中。上面的输出是文档示例不代表固定日志格式或固定计划内容。限制与注意点默认计划 LLM 固定为gpt-4o-mini依赖 OpenAI API keyAgent 使用其他模型时不配置 key 会造成困惑或异常文档明确提醒用planning_llm覆盖。planning 是可选能力不开启时 Crew 按原流程执行不产生计划步骤。规划发生在每轮 Crew 迭代之前计划内容本身会进入任务描述Agent 执行时的行为取决于任务描述与所选模型的输出质量。相关文档Planning 概念页、Crews 概念页Crew 属性表。【免费下载链接】crewAIFramework for orchestrating role-playing, autonomous AI agents. By fostering collaborative intelligence, CrewAI empowers agents to work together seamlessly, tackling complex tasks.项目地址: https://gitcode.com/GitHub_Trending/cr/crewAI创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考
返回列表