mirror of
https://github.com/crewAIInc/crewAI.git
synced 2026-01-09 08:08:32 +00:00
patch twice since
This commit is contained in:
@@ -1604,42 +1604,35 @@ def test_agent_with_knowledge_sources():
|
|||||||
|
|
||||||
|
|
||||||
@pytest.mark.vcr(filter_headers=["authorization"])
|
@pytest.mark.vcr(filter_headers=["authorization"])
|
||||||
@patch("crewai.knowledge.storage.knowledge_storage.KnowledgeStorage")
|
def test_agent_with_knowledge_sources_works_with_copy():
|
||||||
@patch.object(BaseAgent, "copy")
|
|
||||||
def test_agent_with_knowledge_sources_works_with_copy(
|
|
||||||
mock_agent_copy,
|
|
||||||
MockKnowledgeStorage,
|
|
||||||
):
|
|
||||||
content = "Brandon's favorite color is red and he likes Mexican food."
|
content = "Brandon's favorite color is red and he likes Mexican food."
|
||||||
string_source = StringKnowledgeSource(content=content)
|
string_source = StringKnowledgeSource(content=content)
|
||||||
mock_knowledge_instance = MockKnowledgeStorage.return_value
|
with patch(
|
||||||
mock_knowledge_instance.sources = [string_source]
|
"crewai.knowledge.storage.knowledge_storage.KnowledgeStorage"
|
||||||
mock_knowledge_instance.query.return_value = [{"content": content}]
|
) as MockKnowledge:
|
||||||
|
mock_knowledge_instance = MockKnowledge.return_value
|
||||||
|
mock_knowledge_instance.sources = [string_source]
|
||||||
|
mock_knowledge_instance.query.return_value = [{"content": content}]
|
||||||
|
|
||||||
agent = Agent(
|
agent = Agent(
|
||||||
role="Information Agent",
|
role="Information Agent",
|
||||||
goal="Provide information based on knowledge sources",
|
goal="Provide information based on knowledge sources",
|
||||||
backstory="You have access to specific knowledge sources.",
|
backstory="You have access to specific knowledge sources.",
|
||||||
knowledge_sources=[string_source],
|
llm=LLM(model="gpt-4o-mini"),
|
||||||
)
|
knowledge_sources=[string_source],
|
||||||
|
)
|
||||||
|
|
||||||
# Configure the mock to return a copy of the agent
|
agent_copy = agent.copy()
|
||||||
mock_agent_copy.return_value = Agent(
|
with patch(
|
||||||
role=agent.role,
|
"crewai.agents.agent_builder.base_agent.BaseAgent.copy",
|
||||||
goal=agent.goal,
|
) as mock_agent_copy:
|
||||||
backstory=agent.backstory,
|
mock_agent_copy.return_value = agent_copy
|
||||||
knowledge_sources=agent.knowledge_sources,
|
|
||||||
)
|
|
||||||
|
|
||||||
agent_copy = agent.copy()
|
assert agent_copy.role == agent.role
|
||||||
|
assert agent_copy.goal == agent.goal
|
||||||
# Add assertions to verify copy behavior
|
assert agent_copy.backstory == agent.backstory
|
||||||
assert mock_agent_copy.call_count == 1
|
assert agent_copy.knowledge_sources == agent.knowledge_sources
|
||||||
assert agent_copy.role == agent.role
|
assert isinstance(agent_copy.llm, LLM)
|
||||||
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"])
|
@pytest.mark.vcr(filter_headers=["authorization"])
|
||||||
|
|||||||
Reference in New Issue
Block a user