From 6f84a4981a7b2ff17922186731d18a20b7ced2f4 Mon Sep 17 00:00:00 2001 From: Robert Jambrecic Date: Fri, 3 Jan 2025 10:47:43 +0100 Subject: [PATCH 1/4] Fix CrewAI interoperability tests failing --- setup.py | 5 ++++- test/interop/crewai/test_crewai.py | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/setup.py b/setup.py index daebaba99a..aaca06ba63 100644 --- a/setup.py +++ b/setup.py @@ -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 diff --git a/test/interop/crewai/test_crewai.py b/test/interop/crewai/test_crewai.py index 0d39926638..ee845c6e85 100644 --- a/test/interop/crewai/test_crewai.py +++ b/test/interop/crewai/test_crewai.py @@ -52,7 +52,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) From c5e928d8216060530c5e36b777be3e0fa8c9f550 Mon Sep 17 00:00:00 2001 From: Robert Jambrecic Date: Fri, 3 Jan 2025 10:54:21 +0100 Subject: [PATCH 2/4] Fix failing test --- test/interop/test_interoperability.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/interop/test_interoperability.py b/test/interop/test_interoperability.py index 3925f056f1..a0900bd3c7 100644 --- a/test/interop/test_interoperability.py +++ b/test/interop/test_interoperability.py @@ -45,7 +45,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 From ba3cd6c86e1c155d4e364a526769921aada2c52f Mon Sep 17 00:00:00 2001 From: Robert Jambrecic Date: Fri, 3 Jan 2025 11:08:03 +0100 Subject: [PATCH 3/4] Fix failing test --- test/interop/crewai/test_crewai.py | 2 +- test/interop/test_interoperability.py | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/test/interop/crewai/test_crewai.py b/test/interop/crewai/test_crewai.py index ee845c6e85..266f0096d2 100644 --- a/test/interop/crewai/test_crewai.py +++ b/test/interop/crewai/test_crewai.py @@ -11,6 +11,7 @@ from conftest import reason, skip_openai if sys.version_info >= (3, 10) and sys.version_info < (3, 13): + os.environ["OPENAI_API_KEY"] = os.environ.get("OPENAI_API_KEY", "test") from crewai_tools import FileReadTool else: FileReadTool = MagicMock() @@ -31,7 +32,6 @@ class TestCrewAIInteroperability: @pytest.fixture(autouse=True) def setup(self) -> None: - crewai_tool = FileReadTool() self.model_type = crewai_tool.args_schema self.tool = CrewAIInteroperability.convert_tool(crewai_tool) diff --git a/test/interop/test_interoperability.py b/test/interop/test_interoperability.py index a0900bd3c7..00f816283f 100644 --- a/test/interop/test_interoperability.py +++ b/test/interop/test_interoperability.py @@ -2,6 +2,7 @@ # # SPDX-License-Identifier: Apache-2.0 +import os import sys from tempfile import TemporaryDirectory from typing import Any @@ -31,6 +32,7 @@ def test_supported_types(self) -> None: 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: + os.environ["OPENAI_API_KEY"] = os.environ.get("OPENAI_API_KEY", "test") from crewai_tools import FileReadTool crewai_tool = FileReadTool() From 01d29aa42ffb8d1355ba620b49dde5ef235ff1ea Mon Sep 17 00:00:00 2001 From: Robert Jambrecic Date: Fri, 3 Jan 2025 12:09:01 +0100 Subject: [PATCH 4/4] Mock OPENAI_API_KEY with monkeypatch --- test/interop/crewai/test_crewai.py | 23 +++++++++++++++-------- test/interop/test_interoperability.py | 6 +++--- 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/test/interop/crewai/test_crewai.py b/test/interop/crewai/test_crewai.py index 266f0096d2..32a7f48aeb 100644 --- a/test/interop/crewai/test_crewai.py +++ b/test/interop/crewai/test_crewai.py @@ -8,14 +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): - os.environ["OPENAI_API_KEY"] = os.environ.get("OPENAI_API_KEY", "test") - 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 @@ -31,7 +29,10 @@ ) 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 self.tool = CrewAIInteroperability.convert_tool(crewai_tool) @@ -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", diff --git a/test/interop/test_interoperability.py b/test/interop/test_interoperability.py index 00f816283f..a2e5e4051e 100644 --- a/test/interop/test_interoperability.py +++ b/test/interop/test_interoperability.py @@ -2,12 +2,12 @@ # # SPDX-License-Identifier: Apache-2.0 -import os import sys from tempfile import TemporaryDirectory from typing import Any import pytest +from conftest import MOCK_OPEN_AI_API_KEY from autogen.interop import Interoperability @@ -31,8 +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: - os.environ["OPENAI_API_KEY"] = os.environ.get("OPENAI_API_KEY", "test") + 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()