From 7c0a55c158481e0d5dd7187afa52d0cb6ce9f6e0 Mon Sep 17 00:00:00 2001 From: Lorenze Jay Date: Tue, 2 Jul 2024 16:22:25 -0700 Subject: [PATCH] better test and fixed task.agent logic --- src/crewai/crew.py | 5 +++-- tests/crew_test.py | 16 ++++++---------- 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/src/crewai/crew.py b/src/crewai/crew.py index 359be4526..d75274f6a 100644 --- a/src/crewai/crew.py +++ b/src/crewai/crew.py @@ -229,7 +229,7 @@ class Crew(BaseModel): if task.agent is None: raise PydanticCustomError( "missing_agent_in_task", - "Agent is missing in the task with the following description: {task.description}", + "Sequential process error: Agent is missing in the task with the following description: {task.description}", {}, ) @@ -459,7 +459,8 @@ class Crew(BaseModel): self._file_handler.log( agent=manager.role, task=task.description, status="started" ) - if task.agent is not None: + # THIS MIGHT BREAK DURING ASYNC TASK RUN + if task.agent: manager.tools = task.agent.get_delegation_tools([task.agent]) else: manager.tools = manager.get_delegation_tools(self.agents) diff --git a/tests/crew_test.py b/tests/crew_test.py index 36ba0f359..041d7007e 100644 --- a/tests/crew_test.py +++ b/tests/crew_test.py @@ -761,19 +761,15 @@ def test_hierarchical_crew_creation_tasks_with_agents(): crew = Crew( tasks=[task], - agents=[writer], + agents=[writer, researcher], process=Process.hierarchical, manager_llm=ChatOpenAI(model="gpt-4o"), ) - - assert crew.process == Process.hierarchical - assert crew.manager_llm is not None - assert crew.tasks[0].agent == writer - result = crew.kickoff() - - assert ( - result - == "Artificial Intelligence (AI) is revolutionizing the way we live and work, driving advancements across numerous industries from healthcare to finance and beyond. By harnessing the power of complex algorithms and vast datasets, AI systems can perform tasks with unprecedented speed, accuracy, and efficiency, often surpassing human capabilities. From predictive analytics and personalized recommendations to autonomous vehicles and intelligent virtual assistants, AI's applications are both diverse and transformative. As we continue to innovate and integrate AI into our daily lives, its potential to shape a smarter, more efficient, and interconnected future is boundless." + crew.kickoff() + assert crew.manager_agent is not None + assert crew.manager_agent.tools is not None + assert crew.manager_agent.tools[0].description.startswith( + "Delegate a specific task to one of the following coworkers: [Senior Writer]" )