Skip to content

Commit

Permalink
fix copy and custom storage
Browse files Browse the repository at this point in the history
  • Loading branch information
lorenzejay committed Jan 24, 2025
1 parent 591c4a5 commit 71246e9
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/crewai/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ def _set_knowledge(self):
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)}")
Expand Down
5 changes: 3 additions & 2 deletions src/crewai/agents/agent_builder/base_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
)
Expand Down Expand Up @@ -270,13 +270,14 @@ def copy(self: T) -> T: # type: ignore # Signature of "copy" incompatible with

# 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
Expand Down
7 changes: 4 additions & 3 deletions src/crewai/crew.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
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

Expand Down Expand Up @@ -1044,6 +1045,8 @@ def copy(self):
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)
Expand All @@ -1067,9 +1070,7 @@ def copy(self):
**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
Expand Down

0 comments on commit 71246e9

Please sign in to comment.