mirror of
https://github.com/crewAIInc/crewAI.git
synced 2026-01-09 08:08:32 +00:00
fix task cloning error (#1416)
This commit is contained in:
committed by
GitHub
parent
384288e7b1
commit
8119b7239d
@@ -900,7 +900,22 @@ class Crew(BaseModel):
|
|||||||
}
|
}
|
||||||
|
|
||||||
cloned_agents = [agent.copy() for agent in self.agents]
|
cloned_agents = [agent.copy() for agent in self.agents]
|
||||||
cloned_tasks = [task.copy(cloned_agents) for task in self.tasks]
|
|
||||||
|
task_mapping = {}
|
||||||
|
|
||||||
|
cloned_tasks = []
|
||||||
|
for task in self.tasks:
|
||||||
|
cloned_task = task.copy(cloned_agents, task_mapping)
|
||||||
|
cloned_tasks.append(cloned_task)
|
||||||
|
task_mapping[task.key] = cloned_task
|
||||||
|
|
||||||
|
for cloned_task, original_task in zip(cloned_tasks, self.tasks):
|
||||||
|
if original_task.context:
|
||||||
|
cloned_context = [
|
||||||
|
task_mapping[context_task.key]
|
||||||
|
for context_task in original_task.context
|
||||||
|
]
|
||||||
|
cloned_task.context = cloned_context
|
||||||
|
|
||||||
copied_data = self.model_dump(exclude=exclude)
|
copied_data = self.model_dump(exclude=exclude)
|
||||||
copied_data = {k: v for k, v in copied_data.items() if v is not None}
|
copied_data = {k: v for k, v in copied_data.items() if v is not None}
|
||||||
|
|||||||
@@ -276,9 +276,7 @@ class Task(BaseModel):
|
|||||||
content = (
|
content = (
|
||||||
json_output
|
json_output
|
||||||
if json_output
|
if json_output
|
||||||
else pydantic_output.model_dump_json()
|
else pydantic_output.model_dump_json() if pydantic_output else result
|
||||||
if pydantic_output
|
|
||||||
else result
|
|
||||||
)
|
)
|
||||||
self._save_file(content)
|
self._save_file(content)
|
||||||
|
|
||||||
@@ -319,7 +317,9 @@ class Task(BaseModel):
|
|||||||
self.processed_by_agents.add(agent_name)
|
self.processed_by_agents.add(agent_name)
|
||||||
self.delegations += 1
|
self.delegations += 1
|
||||||
|
|
||||||
def copy(self, agents: List["BaseAgent"]) -> "Task":
|
def copy(
|
||||||
|
self, agents: List["BaseAgent"], task_mapping: Dict[str, "Task"]
|
||||||
|
) -> "Task":
|
||||||
"""Create a deep copy of the Task."""
|
"""Create a deep copy of the Task."""
|
||||||
exclude = {
|
exclude = {
|
||||||
"id",
|
"id",
|
||||||
@@ -332,7 +332,9 @@ class Task(BaseModel):
|
|||||||
copied_data = {k: v for k, v in copied_data.items() if v is not None}
|
copied_data = {k: v for k, v in copied_data.items() if v is not None}
|
||||||
|
|
||||||
cloned_context = (
|
cloned_context = (
|
||||||
[task.copy(agents) for task in self.context] if self.context else None
|
[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]:
|
def get_agent_by_role(role: str) -> Union["BaseAgent", None]:
|
||||||
|
|||||||
Reference in New Issue
Block a user