Skip to content

Commit

Permalink
Merge pull request #340 from ag2ai/fix-crewai-tests-failing
Browse files Browse the repository at this point in the history
Fix CrewAI interoperability failing tests
  • Loading branch information
davorrunje authored Jan 3, 2025
2 parents 952885b + 01d29aa commit 12e9665
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 11 deletions.
5 changes: 4 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,10 @@
# used for agentchat_realtime_swarm notebook and realtime agent twilio demo
twilio = ["fastapi>=0.115.0,<1", "uvicorn>=0.30.6,<1", "twilio>=9.3.2"]

interop_crewai = ["crewai[tools]>=0.86,<1; python_version>='3.10' and python_version<'3.13'"]
interop_crewai = [
"crewai[tools]>=0.86,<1; python_version>='3.10' and python_version<'3.13'",
"weaviate-client==4.10.2; python_version>='3.10' and python_version<'3.13'",
]
interop_langchain = ["langchain-community>=0.3.12,<1"]
interop_pydantic_ai = ["pydantic-ai==0.0.13"]
interop = interop_crewai + interop_langchain + interop_pydantic_ai
Expand Down
23 changes: 15 additions & 8 deletions test/interop/crewai/test_crewai.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,12 @@
from unittest.mock import MagicMock

import pytest
from conftest import reason, skip_openai

if sys.version_info >= (3, 10) and sys.version_info < (3, 13):
from crewai_tools import FileReadTool
else:
FileReadTool = MagicMock()
sys.path.append(os.path.join(os.path.dirname(__file__), "../../agentchat"))
from conftest import MOCK_OPEN_AI_API_KEY, reason, skip_openai
from test_assistant_agent import KEY_LOC, OAI_CONFIG_LIST

import autogen
from autogen import AssistantAgent, UserProxyAgent
from autogen.interop import Interoperable

Expand All @@ -30,7 +29,9 @@
)
class TestCrewAIInteroperability:
@pytest.fixture(autouse=True)
def setup(self) -> None:
def setup(self, monkeypatch: pytest.MonkeyPatch) -> None:
monkeypatch.setenv("OPENAI_API_KEY", MOCK_OPEN_AI_API_KEY)
from crewai_tools import FileReadTool

crewai_tool = FileReadTool()
self.model_type = crewai_tool.args_schema
Expand All @@ -52,7 +53,7 @@ def test_convert_tool(self) -> None:
assert self.tool.name == "Read_a_file_s_content"
assert (
self.tool.description
== "A tool that can be used to read a file's content. (IMPORTANT: When using arguments, put them all in an `args` dictionary)"
== "A tool that can be used to read None's content. (IMPORTANT: When using arguments, put them all in an `args` dictionary)"
)

args = self.model_type(file_path=file_path)
Expand All @@ -61,7 +62,13 @@ def test_convert_tool(self) -> None:

@pytest.mark.skipif(skip_openai, reason=reason)
def test_with_llm(self) -> None:
config_list = [{"model": "gpt-4o", "api_key": os.environ["OPENAI_API_KEY"]}]
config_list = autogen.config_list_from_json(
OAI_CONFIG_LIST,
filter_dict={
"tags": ["gpt-4o-mini"],
},
file_location=KEY_LOC,
)
user_proxy = UserProxyAgent(
name="User",
human_input_mode="NEVER",
Expand Down
6 changes: 4 additions & 2 deletions test/interop/test_interoperability.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from typing import Any

import pytest
from conftest import MOCK_OPEN_AI_API_KEY

from autogen.interop import Interoperability

Expand All @@ -30,7 +31,8 @@ def test_supported_types(self) -> None:
@pytest.mark.skipif(
sys.version_info < (3, 10) or sys.version_info >= (3, 13), reason="Only Python 3.10, 3.11, 3.12 are supported"
)
def test_crewai(self) -> None:
def test_crewai(self, monkeypatch: pytest.MonkeyPatch) -> None:
monkeypatch.setenv("OPENAI_API_KEY", MOCK_OPEN_AI_API_KEY)
from crewai_tools import FileReadTool

crewai_tool = FileReadTool()
Expand All @@ -45,7 +47,7 @@ def test_crewai(self) -> None:
assert tool.name == "Read_a_file_s_content"
assert (
tool.description
== "A tool that can be used to read a file's content. (IMPORTANT: When using arguments, put them all in an `args` dictionary)"
== "A tool that can be used to read None's content. (IMPORTANT: When using arguments, put them all in an `args` dictionary)"
)

model_type = crewai_tool.args_schema
Expand Down

0 comments on commit 12e9665

Please sign in to comment.