Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix breakage when cloning agent/crew using knowledge_sources and enable custom knowledge_storage #1927

Merged
merged 40 commits into from
Jan 29, 2025
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
f3004ff
fix breakage when cloning agent/crew using knowledge_sources
lorenzejay Jan 19, 2025
dc9d1d6
fixed typo
lorenzejay Jan 20, 2025
c67f75d
better
lorenzejay Jan 24, 2025
591c4a5
ensure use of other knowledge storage works
lorenzejay Jan 24, 2025
71246e9
fix copy and custom storage
lorenzejay Jan 24, 2025
f34f53f
added tests
lorenzejay Jan 24, 2025
e3e62c1
normalized name
lorenzejay Jan 24, 2025
65d3837
Merge branch 'main' of github.com:crewAIInc/crewAI into fix/clone_whe…
lorenzejay Jan 24, 2025
79aaab9
updated cassette
lorenzejay Jan 24, 2025
ab8d56d
fix test
lorenzejay Jan 24, 2025
849908c
remove fixture
lorenzejay Jan 24, 2025
c6d8c75
fixed test
lorenzejay Jan 24, 2025
b87c908
fix
lorenzejay Jan 24, 2025
27e4930
add fixture to this
lorenzejay Jan 24, 2025
e4b97e3
add fixture to this
lorenzejay Jan 24, 2025
24dbdd5
Merge branch 'main' of github.com:crewAIInc/crewAI into fix/clone_whe…
lorenzejay Jan 24, 2025
4008ba7
patch twice since
lorenzejay Jan 24, 2025
65b6ff1
fix again
lorenzejay Jan 24, 2025
079692d
with fixtures
lorenzejay Jan 24, 2025
4ff9d49
better mocks
lorenzejay Jan 24, 2025
d438f5a
fix
lorenzejay Jan 24, 2025
0675a2f
simple
lorenzejay Jan 24, 2025
6fb654c
try
lorenzejay Jan 25, 2025
319128c
another
lorenzejay Jan 27, 2025
d506bdb
hopefully fixes test
lorenzejay Jan 27, 2025
cb3865a
hopefully fixes test
lorenzejay Jan 27, 2025
adec089
this should fix it !
lorenzejay Jan 27, 2025
1cc9c98
WIP: test check with prints
lorenzejay Jan 27, 2025
f4b7cff
try this
lorenzejay Jan 27, 2025
1de204e
exclude knowledge
lorenzejay Jan 27, 2025
9b88bcd
fixes
lorenzejay Jan 27, 2025
ac28f7f
just drop clone for now
lorenzejay Jan 27, 2025
42769e8
rm print statements
lorenzejay Jan 27, 2025
b92253b
printing agent_copy
lorenzejay Jan 27, 2025
8570461
checker
lorenzejay Jan 27, 2025
b183aaf
linted
lorenzejay Jan 27, 2025
fd89c3b
cleanup
lorenzejay Jan 27, 2025
6617db7
better docs
lorenzejay Jan 27, 2025
c4da244
Merge branch 'main' of github.com:crewAIInc/crewAI into fix/clone_whe…
lorenzejay Jan 27, 2025
2816e97
Merge branch 'main' into fix/clone_when_using_knowledge
bhancockio Jan 28, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion src/crewai/agents/agent_builder/base_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from crewai.agents.agent_builder.utilities.base_token_process import TokenProcess
from crewai.agents.cache.cache_handler import CacheHandler
from crewai.agents.tools_handler import ToolsHandler
from crewai.knowledge.source.base_knowledge_source import BaseKnowledgeSource
from crewai.tools import BaseTool
from crewai.tools.base_tool import Tool
from crewai.utilities import I18N, Logger, RPMController
Expand Down Expand Up @@ -130,6 +131,10 @@ class BaseAgent(ABC, BaseModel):
max_tokens: Optional[int] = Field(
default=None, description="Maximum number of tokens for the agent's execution."
)
knowledge_sources: Optional[List[BaseKnowledgeSource]] = Field(
bhancockio marked this conversation as resolved.
Show resolved Hide resolved
default=None,
description="Knowledge sources for the agent.",
)

@model_validator(mode="before")
@classmethod
Expand Down Expand Up @@ -256,13 +261,21 @@ def copy(self: T) -> T: # type: ignore # Signature of "copy" incompatible with
"tools_handler",
"cache_handler",
"llm",
"knowledge_sources",
lorenzejay marked this conversation as resolved.
Show resolved Hide resolved
}

# Copy llm and clear callbacks
existing_llm = shallow_copy(self.llm)
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)
copied_agent = type(self)(
**copied_data,
llm=existing_llm,
tools=self.tools,
knowledge_sources=self.knowledge_sources
if hasattr(self, "knowledge_sources")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

knowledge_sources=getattr(self, "knowledge_sources", None)

This is a little cleaner ^

else None,
)

return copied_agent

Expand Down
10 changes: 9 additions & 1 deletion src/crewai/crew.py
Original file line number Diff line number Diff line change
Expand Up @@ -1036,6 +1036,7 @@ def copy(self):
"_telemetry",
"agents",
"tasks",
"knowledge_sources",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please add a test showing that we can successfully clone a crew with knowledge sources?

}

cloned_agents = [agent.copy() for agent in self.agents]
Expand All @@ -1062,7 +1063,14 @@ def copy(self):
copied_data.pop("agents", None)
copied_data.pop("tasks", None)

copied_crew = Crew(**copied_data, agents=cloned_agents, tasks=cloned_tasks)
copied_crew = Crew(
**copied_data,
agents=cloned_agents,
tasks=cloned_tasks,
knowledge_sources=self.knowledge_sources
if hasattr(self, "knowledge_sources")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

knowledge_sources=getattr(self, "knowledge_sources", None)

Same here please.

else None,
)

return copied_crew

Expand Down
Loading