mirror of
https://github.com/crewAIInc/crewAI.git
synced 2026-01-08 15:48:29 +00:00
fix copy and custom storage
This commit is contained in:
@@ -165,7 +165,7 @@ class Agent(BaseAgent):
|
||||
sources=self.knowledge_sources,
|
||||
embedder_config=self.embedder_config,
|
||||
collection_name=knowledge_agent_name,
|
||||
storage=self.custom_knowledge_storage or None,
|
||||
storage=self.knowledge_storage or None,
|
||||
)
|
||||
except (TypeError, ValueError) as e:
|
||||
raise ValueError(f"Invalid Knowledge Configuration: {str(e)}")
|
||||
|
||||
@@ -135,7 +135,7 @@ class BaseAgent(ABC, BaseModel):
|
||||
default=None,
|
||||
description="Knowledge sources for the agent.",
|
||||
)
|
||||
custom_knowledge_storage: Optional[Any] = Field(
|
||||
knowledge_storage: Optional[Any] = Field(
|
||||
default=None,
|
||||
description="Custom knowledge storage for the agent.",
|
||||
)
|
||||
@@ -270,13 +270,14 @@ class BaseAgent(ABC, BaseModel):
|
||||
|
||||
# Copy llm and clear callbacks
|
||||
existing_llm = shallow_copy(self.llm)
|
||||
existing_knowledge_sources = shallow_copy(self.knowledge_sources)
|
||||
copied_data = self.model_dump(exclude=exclude)
|
||||
copied_data = {k: v for k, v in copied_data.items() if v is not None}
|
||||
copied_agent = type(self)(
|
||||
**copied_data,
|
||||
llm=existing_llm,
|
||||
tools=self.tools,
|
||||
knowledge_sources=getattr(self, "knowledge_sources", None),
|
||||
knowledge_sources=existing_knowledge_sources,
|
||||
)
|
||||
|
||||
return copied_agent
|
||||
|
||||
@@ -4,6 +4,7 @@ import re
|
||||
import uuid
|
||||
import warnings
|
||||
from concurrent.futures import Future
|
||||
from copy import copy as shallow_copy
|
||||
from hashlib import md5
|
||||
from typing import Any, Callable, Dict, List, Optional, Set, Tuple, Union
|
||||
|
||||
@@ -1044,6 +1045,8 @@ class Crew(BaseModel):
|
||||
task_mapping = {}
|
||||
|
||||
cloned_tasks = []
|
||||
knowledge_sources_copied = shallow_copy(self.knowledge_sources)
|
||||
|
||||
for task in self.tasks:
|
||||
cloned_task = task.copy(cloned_agents, task_mapping)
|
||||
cloned_tasks.append(cloned_task)
|
||||
@@ -1067,9 +1070,7 @@ class Crew(BaseModel):
|
||||
**copied_data,
|
||||
agents=cloned_agents,
|
||||
tasks=cloned_tasks,
|
||||
knowledge_sources=self.knowledge_sources
|
||||
if hasattr(self, "knowledge_sources")
|
||||
else None,
|
||||
knowledge_sources=knowledge_sources_copied,
|
||||
)
|
||||
|
||||
return copied_crew
|
||||
|
||||
Reference in New Issue
Block a user