Planning

学习如何为你的 CrewAI Crew 添加规划能力,并提升其表现。

概览

CrewAI 中的 planning 功能允许你为 crew 添加规划能力。启用后,在每次 Crew 迭代之前, 所有 Crew 信息都会发送给一个 AgentPlanner,它会逐步规划任务,而这个计划会被附加到每个任务描述中。

使用 Planning 功能

开始使用 planning 功能非常简单,你唯一需要做的就是在 Crew 中添加 planning=True

```python 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, ) ````

从这一刻开始,你的 crew 就启用了 planning,任务会在每次迭代前先被规划。

当启用 planning 时,crewAI 会默认使用 gpt-4o-mini 作为规划所用的 LLM,这需要一个有效的 OpenAI API Key。由于你的 Agent 可能使用的是不同的 LLM,如果你没有配置 OpenAI API Key,或者在 LLM API 调用方面遇到意外行为,这可能会引起困惑。

Planning LLM

现在,你还可以定义用于规划任务的 LLM。

当你运行基础示例时,你会看到类似下面这样的输出,它表示由 AgentPlanner 生成的输出,该规划器负责创建逐步执行逻辑,并将其添加到 Agent 的任务中。

  1. from crewai import Crew, Agent, Task, Process
  2. # Assemble your crew with planning capabilities and custom LLM
  3. my_crew = Crew(
  4. agents=self.agents,
  5. tasks=self.tasks,
  6. process=Process.sequential,
  7. planning=True,
  8. planning_llm="gpt-4o"
  9. )
  10. # Run the crew
  11. my_crew.kickoff()
  12. `
  1. [2024-07-15 16:49:11][INFO]: Planning the crew execution
  2. **Step-by-Step Plan for Task Execution**
  3. **Task Number 1: Conduct a thorough research about AI LLMs**
  4. **Agent:** AI LLMs Senior Data Researcher
  5. **Agent Goal:** Uncover cutting-edge developments in AI LLMs
  6. **Task Expected Output:** A list with 10 bullet points of the most relevant information about AI LLMs
  7. **Task Tools:** None specified
  8. **Agent Tools:** None specified
  9. **Step-by-Step Plan:**
  10. 1. **Define Research Scope:**
  11. - Determine the specific areas of AI LLMs to focus on, such as advancements in architecture, use cases, ethical considerations, and performance metrics.
  12. 2. **Identify Reliable Sources:**
  13. - List reputable sources for AI research, including academic journals, industry reports, conferences (e.g., NeurIPS, ACL), AI research labs (e.g., OpenAI, Google AI), and online databases (e.g., IEEE Xplore, arXiv).
  14. 3. **Collect Data:**
  15. - Search for the latest papers, articles, and reports published in 2024 and early 2025.
  16. - Use keywords like "Large Language Models 2025", "AI LLM advancements", "AI ethics 2025", etc.
  17. 4. **Analyze Findings:**
  18. - Read and summarize the key points from each source.
  19. - Highlight new techniques, models, and applications introduced in the past year.
  20. 5. **Organize Information:**
  21. - Categorize the information into relevant topics (e.g., new architectures, ethical implications, real-world applications).
  22. - Ensure each bullet point is concise but informative.
  23. 6. **Create the List:**
  24. - Compile the 10 most relevant pieces of information into a bullet point list.
  25. - Review the list to ensure clarity and relevance.
  26. **Expected Output:**
  27. A list with 10 bullet points of the most relevant information about AI LLMs.
  28. ---
  29. **Task Number 2: Review the context you got and expand each topic into a full section for a report**
  30. **Agent:** AI LLMs Reporting Analyst
  31. **Agent Goal:** Create detailed reports based on AI LLMs data analysis and research findings
  32. **Task Expected Output:** A fully fledged report with the main topics, each with a full section of information. Formatted as markdown without '```'
  33. **Task Tools:** None specified
  34. **Agent Tools:** None specified
  35. **Step-by-Step Plan:**
  36. 1. **Review the Bullet Points:**
  37. - Carefully read through the list of 10 bullet points provided by the AI LLMs Senior Data Researcher.
  38. 2. **Outline the Report:**
  39. - Create an outline with each bullet point as a main section heading.
  40. - Plan sub-sections under each main heading to cover different aspects of the topic.
  41. 3. **Research Further Details:**
  42. - For each bullet point, conduct additional research if necessary to gather more detailed information.
  43. - Look for case studies, examples, and statistical data to support each section.
  44. 4. **Write Detailed Sections:**
  45. - Expand each bullet point into a comprehensive section.
  46. - Ensure each section includes an introduction, detailed explanation, examples, and a conclusion.
  47. - Use markdown formatting for headings, subheadings, lists, and emphasis.
  48. 5. **Review and Edit:**
  49. - Proofread the report for clarity, coherence, and correctness.
  50. - Make sure the report flows logically from one section to the next.
  51. - Format the report according to markdown standards.
  52. 6. **Finalize the Report:**
  53. - Ensure the report is complete with all sections expanded and detailed.
  54. - Double-check formatting and make any necessary adjustments.
  55. **Expected Output:**
  56. A fully fledged report with the main topics, each with a full section of information. Formatted as markdown without '```'.