mirror of
https://github.com/crewAIInc/crewAI.git
synced 2026-01-28 09:38:17 +00:00
cleanup
This commit is contained in:
@@ -276,12 +276,8 @@ class BaseAgent(ABC, BaseModel):
|
||||
|
||||
# Copy llm
|
||||
existing_llm = shallow_copy(self.llm)
|
||||
print("self.knowledge", self.knowledge)
|
||||
copied_knowledge = shallow_copy(self.knowledge)
|
||||
copied_knowledge_storage = shallow_copy(self.knowledge_storage)
|
||||
print("existing_llm", existing_llm)
|
||||
print("copied_knowledge_storage", copied_knowledge_storage)
|
||||
print("copied_knowledge", copied_knowledge)
|
||||
# Properly copy knowledge sources if they exist
|
||||
existing_knowledge_sources = None
|
||||
if self.knowledge_sources:
|
||||
@@ -302,9 +298,7 @@ class BaseAgent(ABC, BaseModel):
|
||||
existing_knowledge_sources.append(copied_source)
|
||||
|
||||
copied_data = self.model_dump(exclude=exclude)
|
||||
print("copied_data", copied_data)
|
||||
copied_data = {k: v for k, v in copied_data.items() if v is not None}
|
||||
print("copied_data", copied_data)
|
||||
copied_agent = type(self)(
|
||||
**copied_data,
|
||||
llm=existing_llm,
|
||||
|
||||
@@ -41,8 +41,6 @@ class Knowledge(BaseModel):
|
||||
)
|
||||
self.sources = sources
|
||||
self.storage.initialize_knowledge_storage()
|
||||
print("self.storage", self.storage)
|
||||
|
||||
self._add_sources()
|
||||
|
||||
def query(self, query: List[str], limit: int = 3) -> List[Dict[str, Any]]:
|
||||
@@ -64,10 +62,8 @@ class Knowledge(BaseModel):
|
||||
|
||||
def _add_sources(self):
|
||||
try:
|
||||
print("adding sources", self.storage)
|
||||
for source in self.sources:
|
||||
source.storage = self.storage
|
||||
source.add()
|
||||
except Exception as e:
|
||||
print("Error adding sources", e)
|
||||
raise e
|
||||
|
||||
@@ -43,10 +43,6 @@ class EmbeddingConfigurator:
|
||||
raise Exception(
|
||||
f"Unsupported embedding provider: {provider}, supported providers: {list(self.embedding_functions.keys())}"
|
||||
)
|
||||
print(
|
||||
"self.embedding_functions[provider](config, model_name)",
|
||||
self.embedding_functions[provider](config, model_name),
|
||||
)
|
||||
return self.embedding_functions[provider](config, model_name)
|
||||
|
||||
@staticmethod
|
||||
|
||||
@@ -1608,29 +1608,22 @@ def test_agent_with_knowledge_sources_works_with_copy():
|
||||
content = "Brandon's favorite color is red and he likes Mexican food."
|
||||
string_source = StringKnowledgeSource(content=content)
|
||||
|
||||
# Create a real instance to use as spec
|
||||
|
||||
with patch(
|
||||
"crewai.knowledge.source.base_knowledge_source.BaseKnowledgeSource",
|
||||
autospec=True,
|
||||
) as MockKnowledgeSource:
|
||||
# Set up the mock instance using the real class as spec
|
||||
mock_knowledge_source_instance = MockKnowledgeSource.return_value
|
||||
mock_knowledge_source_instance.__class__ = BaseKnowledgeSource
|
||||
mock_knowledge_source_instance.sources = [string_source]
|
||||
# mock_knowledge_source_instance.query.return_value = [{"content": content}]
|
||||
|
||||
agent = Agent(
|
||||
role="Information Agent",
|
||||
goal="Provide information based on knowledge sources",
|
||||
backstory="You have access to specific knowledge sources.",
|
||||
llm=LLM(model="gpt-4o-mini"),
|
||||
knowledge_sources=[
|
||||
string_source
|
||||
], # Use the real string source instead of mock
|
||||
knowledge_sources=[string_source],
|
||||
)
|
||||
|
||||
# Mock the knowledge attribute to avoid validation issues during copy
|
||||
with patch(
|
||||
"crewai.knowledge.storage.knowledge_storage.KnowledgeStorage"
|
||||
) as MockKnowledgeStorage:
|
||||
@@ -1639,10 +1632,10 @@ def test_agent_with_knowledge_sources_works_with_copy():
|
||||
|
||||
agent_copy = agent.copy()
|
||||
|
||||
# Basic assertions
|
||||
assert agent_copy.role == agent.role
|
||||
assert agent_copy.goal == agent.goal
|
||||
assert agent_copy.backstory == agent.backstory
|
||||
assert agent_copy.knowledge_sources is not None
|
||||
assert len(agent_copy.knowledge_sources) == 1
|
||||
assert isinstance(agent_copy.knowledge_sources[0], StringKnowledgeSource)
|
||||
assert agent_copy.knowledge_sources[0].content == content
|
||||
|
||||
Reference in New Issue
Block a user