From 77990b6293a779c26889de244a0d9940db2e5188 Mon Sep 17 00:00:00 2001 From: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Date: Thu, 20 Feb 2025 17:01:10 +0000 Subject: [PATCH] fix: resolve type checking errors and improve copy method Co-Authored-By: Joe Moura --- src/crewai/task.py | 43 ++++++++++++++++--------------------------- 1 file changed, 16 insertions(+), 27 deletions(-) diff --git a/src/crewai/task.py b/src/crewai/task.py index 67d4b6e28..25a72cb3c 100644 --- a/src/crewai/task.py +++ b/src/crewai/task.py @@ -10,11 +10,13 @@ from copy import copy from hashlib import md5 from pathlib import Path from typing import ( + AbstractSet, Any, Callable, ClassVar, Dict, List, + Mapping, Optional, Set, Tuple, @@ -677,34 +679,21 @@ class Task(BaseModel): deep: bool = False, ) -> "Task": """Create a deep copy of the Task.""" - exclude = { - "id", - "agent", - "context", - "tools", - } - - copied_data = self.model_dump(exclude=exclude) - copied_data = {k: v for k, v in copied_data.items() if v is not None} - - cloned_context = ( - [task_mapping[context_task.key] for context_task in self.context] - if self.context - else None - ) - - def get_agent_by_role(role: str) -> Union["BaseAgent", None]: - return next((agent for agent in agents if agent.role == role), None) - - cloned_agent = get_agent_by_role(self.agent.role) if self.agent else None - cloned_tools = copy(self.tools) if self.tools else [] - - copied_task = Task( - **copied_data, - context=cloned_context, - agent=cloned_agent, - tools=cloned_tools, + # Call parent's copy method + copied = super().copy( + include=include, + exclude=exclude, + update=update, + deep=deep, ) + + # Copy mutable fields + if self.tools: + copied.tools = copy(self.tools) + if self.context: + copied.context = copy(self.context) + + return copied return copied_task