mirror of
https://github.com/crewAIInc/crewAI.git
synced 2026-01-09 08:08:32 +00:00
Update to Pydantic v2: Transitioned all references from pydantic.v1 to pydantic (v2), ensuring compatibility with the latest Pydantic features and improvements. Affected components include agent tools, prompts, crew, and task modules. Refactoring & Alignment with Pydantic Standards: Refactored the agent module away from traditional __init__ to align more closely with Pydantic best practices. Updated the crew module to Pydantic v2 and enhanced configurations, allowing JSON and dictionary inputs. Additionally, some (not all) exceptions have been migrated to leverage Pydantic's error-handling capabilities. Enhancements to Validators and Typings: Improved validators and type annotations across multiple modules, enhancing code readability and maintainability. Streamlined the validation process in line with Pydantic v2's methodologies. Import and Configuration Adjustments: Updated to test-related absolute imports due to issues with Pytest finding packages through relative imports.
75 lines
2.7 KiB
Python
75 lines
2.7 KiB
Python
"""Test Agent creation and execution basic functionality."""
|
|
|
|
import pytest
|
|
|
|
from crewai.agent import Agent
|
|
from crewai.tools.agent_tools import AgentTools
|
|
|
|
researcher = Agent(
|
|
role="researcher",
|
|
goal="make the best research and analysis on content about AI and AI agents",
|
|
backstory="You're an expert researcher, specialized in technology",
|
|
allow_delegation=False,
|
|
)
|
|
tools = AgentTools(agents=[researcher])
|
|
|
|
|
|
@pytest.mark.vcr(filter_headers=["authorization"])
|
|
def test_delegate_work():
|
|
result = tools.delegate_work(
|
|
command="researcher|share your take on AI Agents|I heard you hate them"
|
|
)
|
|
|
|
assert (
|
|
result
|
|
== "I apologize if my previous statements have given you the impression that I hate AI agents. As a technology researcher, I don't hold personal sentiments towards AI or any other technology. Rather, I analyze them objectively based on their capabilities, applications, and implications. AI agents, in particular, are a fascinating domain of research. They hold tremendous potential in automating and optimizing various tasks across industries. However, like any other technology, they come with their own set of challenges, such as ethical considerations around privacy and decision-making. My objective is to understand these technologies in depth and provide a balanced view."
|
|
)
|
|
|
|
|
|
@pytest.mark.vcr(filter_headers=["authorization"])
|
|
def test_ask_question():
|
|
result = tools.ask_question(
|
|
command="researcher|do you hate AI Agents?|I heard you LOVE them"
|
|
)
|
|
|
|
assert (
|
|
result
|
|
== "As an AI, I don't possess feelings or emotions, so I don't love or hate anything. However, I can provide detailed analysis and research on AI agents. They are a fascinating field of study with the potential to revolutionize many industries, although they also present certain challenges and ethical considerations."
|
|
)
|
|
|
|
|
|
def test_can_not_self_delegate():
|
|
# TODO: Add test for self delegation
|
|
pass
|
|
|
|
|
|
def test_delegate_work_with_wrong_input():
|
|
result = tools.ask_question(command="writer|share your take on AI Agents")
|
|
|
|
assert (
|
|
result
|
|
== "Error executing tool. Missing exact 3 pipe (|) separated values. For example, `coworker|task|information`."
|
|
)
|
|
|
|
|
|
def test_delegate_work_to_wrong_agent():
|
|
result = tools.ask_question(
|
|
command="writer|share your take on AI Agents|I heard you hate them"
|
|
)
|
|
|
|
assert (
|
|
result
|
|
== "Error executing tool. Co-worker not found, double check the co-worker."
|
|
)
|
|
|
|
|
|
def test_ask_question_to_wrong_agent():
|
|
result = tools.ask_question(
|
|
command="writer|do you hate AI Agents?|I heard you LOVE them"
|
|
)
|
|
|
|
assert (
|
|
result
|
|
== "Error executing tool. Co-worker not found, double check the co-worker."
|
|
)
|