mirror of
https://github.com/crewAIInc/crewAI.git
synced 2026-01-11 09:08:31 +00:00
Revert "fix: Rely on validator for memory copy, update test assertions"
This reverts commit 8702bf1e34.
This commit is contained in:
@@ -4119,29 +4119,20 @@ def test_crew_kickoff_for_each_works_with_manager_agent_copy():
|
||||
assert crew_copy.manager_agent.role == crew.manager_agent.role
|
||||
assert crew_copy.manager_agent.goal == crew.manager_agent.goal
|
||||
|
||||
def test_crew_copy_with_memory():
|
||||
"""Test that copying a crew with memory enabled does not raise validation errors and copies memory correctly."""
|
||||
def test_crew_train_with_memory():
|
||||
"""Test that training a crew with memory enabled does not raise validation errors."""
|
||||
agent = Agent(role="Test Agent", goal="Test Goal", backstory="Test Backstory")
|
||||
task = Task(description="Test Task", expected_output="Test Output", agent=agent)
|
||||
crew = Crew(agents=[agent], tasks=[task], memory=True)
|
||||
|
||||
assert crew._short_term_memory is not None, "Private short term memory should be initialized"
|
||||
original_short_term_memory_id = id(crew._short_term_memory)
|
||||
|
||||
try:
|
||||
crew_copy = crew.copy()
|
||||
|
||||
assert hasattr(crew_copy, "_short_term_memory"), "Copied crew should have _short_term_memory attribute"
|
||||
assert crew_copy._short_term_memory is not None, "Private short term memory should be initialized in copy"
|
||||
assert id(crew_copy._short_term_memory) != original_short_term_memory_id, "Copied short term memory should be a new object instance"
|
||||
assert hasattr(crew_copy, "_long_term_memory") and crew_copy._long_term_memory is not None
|
||||
assert id(crew_copy._long_term_memory) != id(crew._long_term_memory)
|
||||
assert hasattr(crew_copy, "_entity_memory") and crew_copy._entity_memory is not None
|
||||
assert id(crew_copy._entity_memory) != id(crew._entity_memory)
|
||||
except pydantic_core.ValidationError as e:
|
||||
if "Input should be an instance of" in str(e) and ("Memory" in str(e)):
|
||||
pytest.fail(f"Copying with memory raised Pydantic ValidationError, likely due to incorrect memory copy: {e}")
|
||||
else:
|
||||
raise e
|
||||
except Exception as e:
|
||||
pytest.fail(f"Copying crew raised an unexpected exception: {e}")
|
||||
with tempfile.TemporaryDirectory() as tmpdir:
|
||||
filename = os.path.join(tmpdir, "training_data.pkl")
|
||||
try:
|
||||
crew.train(n_iterations=1, filename=filename)
|
||||
except pydantic_core.ValidationError as e:
|
||||
if "Input should be an instance of" in str(e) and ("Memory" in str(e)):
|
||||
pytest.fail(f"Training with memory raised Pydantic ValidationError, likely due to incorrect memory copy: {e}")
|
||||
else:
|
||||
raise e
|
||||
except Exception as e:
|
||||
print(f"Warning: Training raised an unexpected exception: {e}")
|
||||
|
||||
Reference in New Issue
Block a user