Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor Codebase to Use Pydantic v2 and Enhance Type Hints, Documentation #24

Merged
merged 8 commits into from
Dec 30, 2023
Prev Previous commit
Update to absolute imports
Pytest is bugging out when trying to find packages through relative imports
  • Loading branch information
greysonlalonde committed Dec 29, 2023
commit 68fd28ebc73a46d7f33e3178bc73b078cb1e830b
2 changes: 1 addition & 1 deletion tests/agent_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import pytest
from langchain.chat_models import ChatOpenAI as OpenAI

from ..crewai import Agent
from crewai.agent import Agent


def test_agent_creation():
Expand Down
78 changes: 48 additions & 30 deletions tests/agent_tools/agent_tools_test.py
Original file line number Diff line number Diff line change
@@ -1,56 +1,74 @@
"""Test Agent creation and execution basic functionality."""

import pytest
from ...crewai import Agent
from ...crewai.tools.agent_tools import AgentTools

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
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"
)
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."
)

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"
)
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."
)

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
# 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"
)
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`."
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_delegate_work_to_wrong_agent():
result = tools.ask_question(
command="writer|share your take on AI Agents|I heard you hate them"
)

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."
)

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."
)
5 changes: 4 additions & 1 deletion tests/crew_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@

import pytest

from ..crewai import Agent, Crew, Process, Task
from crewai.agent import Agent
from crewai.crew import Crew
from crewai.process import Process
from crewai.task import Task

ceo = Agent(
role="CEO",
Expand Down
3 changes: 2 additions & 1 deletion tests/task_test.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
"""Test Agent creation and execution basic functionality."""


from ..crewai import Agent, Task
from crewai.agent import Agent
from crewai.task import Task


def test_task_tool_reflect_agent_tools():
Expand Down