From c6d8c7586928a6580e143b0530a068b4ac9a61aa Mon Sep 17 00:00:00 2001 From: Lorenze Jay Date: Fri, 24 Jan 2025 14:43:49 -0800 Subject: [PATCH] fixed test --- tests/agent_test.py | 42 +++++++++++++++++++----------------------- 1 file changed, 19 insertions(+), 23 deletions(-) diff --git a/tests/agent_test.py b/tests/agent_test.py index bee4d44a0..69f91b899 100644 --- a/tests/agent_test.py +++ b/tests/agent_test.py @@ -1602,33 +1602,29 @@ def test_agent_with_knowledge_sources(): assert "red" in result.raw.lower() -def test_agent_with_knowledge_sources_works_with_test(): +@patch("crewai.knowledge.storage.knowledge_storage.KnowledgeStorage") +def test_agent_with_knowledge_sources_works_with_copy( + MockKnowledgeStorage, +): content = "Brandon's favorite color is red and he likes Mexican food." string_source = StringKnowledgeSource(content=content) + mock_knowledge_instance = MockKnowledgeStorage.return_value + mock_knowledge_instance.sources = [string_source] + mock_knowledge_instance.query.return_value = [{"content": content}] - with patch( - "crewai.knowledge.storage.knowledge_storage.KnowledgeStorage" - ) as MockKnowledge: - mock_knowledge_instance = MockKnowledge.return_value - mock_knowledge_instance.sources = [string_source] + agent = Agent( + role="Information Agent", + goal="Provide information based on knowledge sources", + backstory="You have access to specific knowledge sources.", + knowledge_sources=[string_source], + ) + agent_copy = agent.copy() - agent = Agent( - role="test role", - goal="test goal", - backstory="test backstory", - llm=LLM(model="gpt-4o-mini"), - knowledge_sources=[string_source], - ) - - agent.create_agent_executor() - agent_copy = agent.copy() - - # Test that all properties were copied correctly - assert agent_copy.role == agent.role - assert agent_copy.goal == agent.goal - assert agent_copy.backstory == agent.backstory - assert agent_copy.knowledge_sources == agent.knowledge_sources - assert isinstance(agent_copy.llm, LLM) + assert agent_copy.role == agent.role + assert agent_copy.goal == agent.goal + assert agent_copy.backstory == agent.backstory + assert agent_copy.knowledge_sources == agent.knowledge_sources + assert isinstance(agent_copy.llm, LLM) @pytest.mark.vcr(filter_headers=["authorization"])