incorporate small improvements / changes

This commit is contained in:
Brandon Hancock
2025-03-11 11:55:20 -04:00
parent 9ee4e45948
commit 8c704f4e5d
5 changed files with 84 additions and 48 deletions

View File

@@ -10,9 +10,7 @@ def test_basic_usage_examples():
"""Test the basic usage examples from the documentation."""
# Creating components with automatic fingerprinting
agent = Agent(
role="Data Scientist",
goal="Analyze data",
backstory="Expert in data analysis"
role="Data Scientist", goal="Analyze data", backstory="Expert in data analysis"
)
# Verify the agent has a fingerprint
@@ -21,10 +19,7 @@ def test_basic_usage_examples():
assert agent.fingerprint.uuid_str is not None
# Create a crew and verify it has a fingerprint
crew = Crew(
agents=[agent],
tasks=[]
)
crew = Crew(agents=[agent], tasks=[])
assert crew.fingerprint is not None
assert isinstance(crew.fingerprint, Fingerprint)
assert crew.fingerprint.uuid_str is not None
@@ -33,7 +28,7 @@ def test_basic_usage_examples():
task = Task(
description="Analyze customer data",
expected_output="Insights from data analysis",
agent=agent
agent=agent,
)
assert task.fingerprint is not None
assert isinstance(task.fingerprint, Fingerprint)
@@ -44,20 +39,15 @@ def test_accessing_fingerprints_example():
"""Test the accessing fingerprints example from the documentation."""
# Create components
agent = Agent(
role="Data Scientist",
goal="Analyze data",
backstory="Expert in data analysis"
role="Data Scientist", goal="Analyze data", backstory="Expert in data analysis"
)
crew = Crew(
agents=[agent],
tasks=[]
)
crew = Crew(agents=[agent], tasks=[])
task = Task(
description="Analyze customer data",
expected_output="Insights from data analysis",
agent=agent
agent=agent,
)
# Get and verify the agent's fingerprint
@@ -82,9 +72,11 @@ def test_accessing_fingerprints_example():
fingerprints = [
agent_fingerprint.uuid_str,
crew_fingerprint.uuid_str,
task_fingerprint.uuid_str
task_fingerprint.uuid_str,
]
assert len(fingerprints) == len(set(fingerprints)), "All fingerprints should be unique"
assert len(fingerprints) == len(
set(fingerprints)
), "All fingerprints should be unique"
def test_fingerprint_metadata_example():
@@ -98,7 +90,7 @@ def test_fingerprint_metadata_example():
role="Data Scientist",
goal="Analyze data",
backstory="Expert in data analysis",
security_config=security_config
security_config=security_config,
)
# Verify the metadata is attached to the fingerprint
@@ -115,7 +107,7 @@ def test_fingerprint_with_security_config():
role="Data Scientist",
goal="Analyze data",
backstory="Expert in data analysis",
security_config=security_config
security_config=security_config,
)
# Verify the agent uses the same instance of SecurityConfig
@@ -126,7 +118,7 @@ def test_fingerprint_with_security_config():
description="Analyze customer data",
expected_output="Insights from data analysis",
agent=agent,
security_config=security_config
security_config=security_config,
)
# Verify the task uses the same instance of SecurityConfig
@@ -137,34 +129,29 @@ def test_complete_workflow_example():
"""Test the complete workflow example from the documentation."""
# Create agents with auto-generated fingerprints
researcher = Agent(
role="Researcher",
goal="Find information",
backstory="Expert researcher"
role="Researcher", goal="Find information", backstory="Expert researcher"
)
writer = Agent(
role="Writer",
goal="Create content",
backstory="Professional writer"
role="Writer", goal="Create content", backstory="Professional writer"
)
# Create tasks with auto-generated fingerprints
research_task = Task(
description="Research the topic",
expected_output="Research findings",
agent=researcher
agent=researcher,
)
writing_task = Task(
description="Write an article",
expected_output="Completed article",
agent=writer
agent=writer,
)
# Create a crew with auto-generated fingerprint
content_crew = Crew(
agents=[researcher, writer],
tasks=[research_task, writing_task]
agents=[researcher, writer], tasks=[research_task, writing_task]
)
# Verify everything has auto-generated fingerprints
@@ -180,6 +167,67 @@ def test_complete_workflow_example():
writer.fingerprint.uuid_str,
research_task.fingerprint.uuid_str,
writing_task.fingerprint.uuid_str,
content_crew.fingerprint.uuid_str
content_crew.fingerprint.uuid_str,
]
assert len(fingerprints) == len(set(fingerprints)), "All fingerprints should be unique"
assert len(fingerprints) == len(
set(fingerprints)
), "All fingerprints should be unique"
def test_security_preservation_during_copy():
"""Test that security configurations are preserved when copying Crew and Agent objects."""
# Create a SecurityConfig with custom metadata
security_config = SecurityConfig()
security_config.fingerprint.metadata = {"version": "1.0", "environment": "testing"}
# Create an agent with the custom SecurityConfig
original_agent = Agent(
role="Security Tester",
goal="Verify security preservation",
backstory="Security expert",
security_config=security_config,
)
# Create a task with the agent
task = Task(
description="Test security preservation",
expected_output="Security verification",
agent=original_agent,
)
# Create a crew with the agent and task
original_crew = Crew(
agents=[original_agent], tasks=[task], security_config=security_config
)
# Copy the agent and crew
copied_agent = original_agent.copy()
copied_crew = original_crew.copy()
# Verify the agent's security config is preserved during copy
assert copied_agent.security_config is not None
assert isinstance(copied_agent.security_config, SecurityConfig)
assert copied_agent.fingerprint is not None
assert isinstance(copied_agent.fingerprint, Fingerprint)
# Verify the fingerprint metadata is preserved
assert copied_agent.fingerprint.metadata == {
"version": "1.0",
"environment": "testing",
}
# Verify the crew's security config is preserved during copy
assert copied_crew.security_config is not None
assert isinstance(copied_crew.security_config, SecurityConfig)
assert copied_crew.fingerprint is not None
assert isinstance(copied_crew.fingerprint, Fingerprint)
# Verify the fingerprint metadata is preserved
assert copied_crew.fingerprint.metadata == {
"version": "1.0",
"environment": "testing",
}
# Verify that the fingerprints are the same between original and copied objects
assert original_agent.fingerprint.uuid_str == copied_agent.fingerprint.uuid_str
assert original_crew.fingerprint.uuid_str == copied_crew.fingerprint.uuid_str