From 35b47cb6625c81c9daa8216cb2c6af494353258a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Moura?= Date: Tue, 14 May 2024 15:01:29 -0300 Subject: [PATCH] internal crew --- .../internal/agents/hierarchical_manager.py | 15 ++++++ .../internal/agents/planning_manager.py | 12 +++++ .../crew/planning_crew/config/agents.yaml | 21 ++++++++ .../crew/planning_crew/config/tasks.yaml | 36 +++++++++++++ .../internal/crew/planning_crew/crew.py | 51 +++++++++++++++++++ .../crew/planning_crew/crew_config.py | 17 +++++++ 6 files changed, 152 insertions(+) create mode 100644 src/crewai/internal/agents/hierarchical_manager.py create mode 100644 src/crewai/internal/agents/planning_manager.py create mode 100644 src/crewai/internal/crew/planning_crew/config/agents.yaml create mode 100644 src/crewai/internal/crew/planning_crew/config/tasks.yaml create mode 100644 src/crewai/internal/crew/planning_crew/crew.py create mode 100644 src/crewai/internal/crew/planning_crew/crew_config.py diff --git a/src/crewai/internal/agents/hierarchical_manager.py b/src/crewai/internal/agents/hierarchical_manager.py new file mode 100644 index 000000000..09d3b7532 --- /dev/null +++ b/src/crewai/internal/agents/hierarchical_manager.py @@ -0,0 +1,15 @@ +from crewai.agent import Agent +from crewai.tools.agent_tools import AgentTools +from crewai.utilities import I18N + +class HierarchicalManagerAgent: + def __init__(self, llm, agents, verbose): + i18n = I18N() + self.agent = Agent( + role=i18n.retrieve("hierarchical_manager_agent", "role"), + goal=i18n.retrieve("hierarchical_manager_agent", "goal"), + backstory=i18n.retrieve("hierarchical_manager_agent", "backstory"), + tools=AgentTools(agents=agents).tools(), + llm=llm, + verbose=verbose, + ) \ No newline at end of file diff --git a/src/crewai/internal/agents/planning_manager.py b/src/crewai/internal/agents/planning_manager.py new file mode 100644 index 000000000..81c686d43 --- /dev/null +++ b/src/crewai/internal/agents/planning_manager.py @@ -0,0 +1,12 @@ +from crewai.agent import Agent +from crewai.utilities import i18n + +class PlanningManagerAgent: + def __init__(self, llm, verbose): + self.agent = Agent( + role=i18n.retrieve("planning_manager_agent", "role"), + goal=i18n.retrieve("planning_manager_agent", "goal"), + backstory=i18n.retrieve("planning_manager_agent", "backstory"), + verbose=verbose, + llm=llm, + ) \ No newline at end of file diff --git a/src/crewai/internal/crew/planning_crew/config/agents.yaml b/src/crewai/internal/crew/planning_crew/config/agents.yaml new file mode 100644 index 000000000..451665216 --- /dev/null +++ b/src/crewai/internal/crew/planning_crew/config/agents.yaml @@ -0,0 +1,21 @@ +project_manager: + role: > + High-Level Task Decomposer + goal: > + Efficiently break down high-level tasks into actionable subtasks. + backstory: > + As a visionary leader and strategist, you excel at dissecting complex + projects into manageable parts. Your expertise lies in identifying key + components and stages of a project, ensuring that each piece is addressed + with precision and aligned with overarching objectives. + +resource_manager: + role: > + Resource Allocation Specialist + goal: > + Assign the right resources (agents and tools) to the generated subtasks. + backstory: > + With a strategic mind and a masterful grasp of logistics, you specialize + in allocating the best-suited agents and tools for specific tasks. Your + ability to match project needs with available resources ensures optimal + efficiency and effectiveness in project execution. diff --git a/src/crewai/internal/crew/planning_crew/config/tasks.yaml b/src/crewai/internal/crew/planning_crew/config/tasks.yaml new file mode 100644 index 000000000..c14f1eb11 --- /dev/null +++ b/src/crewai/internal/crew/planning_crew/config/tasks.yaml @@ -0,0 +1,36 @@ +task_decomposition: + description: > + Analyze the high-level task, "{task}", provided and break it down into + distinct, manageable subtasks that are specific and actionable. + Consider all aspects of the task and ensure that each subtask is + aligned with the final goal. Additionally, outline the roles, goals, + and backstories for the agents you plan to recruit for performing + each subtask. Make sure to clearly define their responsibilities in + the context of this project. + expected_output: > + A detailed list of subtasks, each with defined objectives and + scopes, ensuring they collectively address all components of the + original task, "{task}". Each subtask should be assigned to a + specific agent you will recruit, complete with their role, goal, and + backstory. The main goal is to ensure systematic progression and + effective task management. + +resource_allocation: + description: > + Evaluate the list of subtasks generated from the high-level task + "{task}" and determine the most appropriate agents and tools needed + for each. Assign resources based on the complexity, required skills, + and the tools needed to effectively complete each subtask. This + evaluation should consider the unique requirements of each subtask + and align resources to optimize task completion. Available tools to + choose from include: + {tools_list}. + expected_output: > + An allocation plan that lists each subtask along with the assigned + agent and the tools they will use, explaining the rationale for each + resource assignment to ensure transparency and optimal task + alignment. The expected outcome is to have a fully resourced plan + that facilitates efficient task execution and achievement of the + main goal: "{goal}". + Ensure each tool selected is from the provided list of available tools: + {tools_list}. diff --git a/src/crewai/internal/crew/planning_crew/crew.py b/src/crewai/internal/crew/planning_crew/crew.py new file mode 100644 index 000000000..d2928db1f --- /dev/null +++ b/src/crewai/internal/crew/planning_crew/crew.py @@ -0,0 +1,51 @@ +from .... import Agent, Crew, Process, Task +from ....project import CrewBase, agent, crew, task + +from .crew_config import CrewConfig + +@CrewBase +class PlanningCrewCrew(): + """PlanningCrew crew""" + agents_config = '../internal/crew/planning_crew/config/agents.yaml' + tasks_config = '../internal/crew/planning_crew/config/tasks.yaml' + + @agent + def project_manager(self) -> Agent: + return Agent( + config=self.agents_config['project_manager'], + allow_delegation=False, + verbose=True + ) + + @agent + def resource_manager(self) -> Agent: + return Agent( + config=self.agents_config['resource_manager'], + allow_delegation=False, + verbose=True + ) + + @task + def task_decomposition(self) -> Task: + return Task( + config=self.tasks_config['task_decomposition'], + agent=self.project_manager(), + output_pydantic=CrewConfig + ) + + @task + def resource_allocation(self) -> Task: + return Task( + config=self.tasks_config['resource_allocation'], + agent=self.resource_manager(), + output_pydantic=CrewConfig + ) + + @crew + def crew(self) -> Crew: + """Creates the PlanningCrew crew""" + return Crew( + agents=[self.project_manager(), self.resource_manager()], + tasks=[self.task_decomposition(), self.resource_allocation()], + process=Process.sequential + ) \ No newline at end of file diff --git a/src/crewai/internal/crew/planning_crew/crew_config.py b/src/crewai/internal/crew/planning_crew/crew_config.py new file mode 100644 index 000000000..6a9bb9a6f --- /dev/null +++ b/src/crewai/internal/crew/planning_crew/crew_config.py @@ -0,0 +1,17 @@ +from typing import List +from pydantic import BaseModel, Field + + +class AgentConfig(BaseModel): + role: str = Field(..., description="The role of the agent") + goal: str = Field(..., description="The goal of the agent") + backstory: str = Field(..., description="The backstory of the agent") + tools: List[str] = Field(..., description="The tools used by the agent") + +class TaskConfig(BaseModel): + description: str = Field(..., description="The description of the task") + expected_output: str = Field(..., description="The expected output of the task") + agent: AgentConfig = Field(..., description="The agent responsible for the task") + +class CrewConfig(BaseModel): + tasks: List[TaskConfig] = Field(..., description="The tasks to be performed by the crew") \ No newline at end of file