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}