From a3439b17444c7f88b0518825f670e9eadc7855cc Mon Sep 17 00:00:00 2001 From: Shahar Yair Date: Wed, 9 Oct 2024 10:11:45 +0300 Subject: [PATCH] deep copy works with fixed context --- src/crewai/crew.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/crewai/crew.py b/src/crewai/crew.py index 91b75c6cef..29e996623d 100644 --- a/src/crewai/crew.py +++ b/src/crewai/crew.py @@ -902,6 +902,15 @@ def copy(self): cloned_agents = [agent.copy() for agent in self.agents] cloned_tasks = [task.copy(cloned_agents) for task in self.tasks] + for cloned_task in cloned_tasks: + cloned_task.context = [ + next( + (reference for reference in cloned_tasks if reference.key == context_task.key), + None + ) + for context_task in cloned_task.context + ] if cloned_task.context else None + copied_data = self.model_dump(exclude=exclude) copied_data = {k: v for k, v in copied_data.items() if v is not None}