From f9288295e6093d4b565b8d3a5885482155172dba Mon Sep 17 00:00:00 2001
From: Eduardo Chiarotti <dudumelgaco@hotmail.com>
Date: Fri, 19 Jul 2024 13:15:33 -0300
Subject: [PATCH] fix: agent missing fix (#966)

---
 src/crewai/task.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/crewai/task.py b/src/crewai/task.py
index 9e98adb1a5..8b1a05ca0b 100644
--- a/src/crewai/task.py
+++ b/src/crewai/task.py
@@ -213,8 +213,8 @@ def _execute_core(
         tools: Optional[List[Any]],
     ) -> TaskOutput:
         """Run the core execution logic of the task."""
-        self.agent = agent
         agent = agent or self.agent
+        self.agent = agent
         if not agent:
             raise Exception(
                 f"The task '{self.description}' has no agent assigned, therefore it can't be executed directly and should be executed in a Crew using a specific process that support that, like hierarchical."