From 7272fd15acbc1b5fd580d9c857233dbe38aa462d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Moura?= Date: Fri, 3 Jan 2025 21:49:55 -0300 Subject: [PATCH] Preparing new version (#1845) * Preparing new version --- pyproject.toml | 2 +- src/crewai/__init__.py | 2 +- src/crewai/cli/templates/crew/pyproject.toml | 2 +- src/crewai/cli/templates/flow/pyproject.toml | 2 +- src/crewai/cli/templates/tool/pyproject.toml | 2 +- src/crewai/llm.py | 52 ++++++++++--------- src/crewai/tools/base_tool.py | 13 ++++- src/crewai/utilities/internal_instructor.py | 8 +-- tests/agents/agent_builder/base_agent_test.py | 4 +- tests/cli/deploy/test_deploy_main.py | 4 +- tests/project_test.py | 10 ++-- tests/test_manager_llm_delegation.py | 4 +- tests/tools/test_base_tool.py | 8 +-- tests/tools/test_structured_tool.py | 2 +- .../evaluators/test_crew_evaluator_handler.py | 2 +- tests/utilities/test_planning_handler.py | 12 ++--- tests/utilities/test_training_handler.py | 2 +- uv.lock | 2 +- 18 files changed, 74 insertions(+), 59 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 8a9f83732a..fd1798d36c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "crewai" -version = "0.86.0" +version = "0.95.0" description = "Cutting-edge framework for orchestrating role-playing, autonomous AI agents. By fostering collaborative intelligence, CrewAI empowers agents to work together seamlessly, tackling complex tasks." readme = "README.md" requires-python = ">=3.10,<3.13" diff --git a/src/crewai/__init__.py b/src/crewai/__init__.py index 0833afd58c..f0ba35a38d 100644 --- a/src/crewai/__init__.py +++ b/src/crewai/__init__.py @@ -14,7 +14,7 @@ category=UserWarning, module="pydantic.main", ) -__version__ = "0.86.0" +__version__ = "0.95.0" __all__ = [ "Agent", "Crew", diff --git a/src/crewai/cli/templates/crew/pyproject.toml b/src/crewai/cli/templates/crew/pyproject.toml index 5ea8194c85..bd2d871c52 100644 --- a/src/crewai/cli/templates/crew/pyproject.toml +++ b/src/crewai/cli/templates/crew/pyproject.toml @@ -5,7 +5,7 @@ description = "{{name}} using crewAI" authors = [{ name = "Your Name", email = "you@example.com" }] requires-python = ">=3.10,<3.13" dependencies = [ - "crewai[tools]>=0.86.0,<1.0.0" + "crewai[tools]>=0.95.0,<1.0.0" ] [project.scripts] diff --git a/src/crewai/cli/templates/flow/pyproject.toml b/src/crewai/cli/templates/flow/pyproject.toml index 8a523d2ede..6ca5894979 100644 --- a/src/crewai/cli/templates/flow/pyproject.toml +++ b/src/crewai/cli/templates/flow/pyproject.toml @@ -5,7 +5,7 @@ description = "{{name}} using crewAI" authors = [{ name = "Your Name", email = "you@example.com" }] requires-python = ">=3.10,<3.13" dependencies = [ - "crewai[tools]>=0.86.0,<1.0.0", + "crewai[tools]>=0.95.0,<1.0.0", ] [project.scripts] diff --git a/src/crewai/cli/templates/tool/pyproject.toml b/src/crewai/cli/templates/tool/pyproject.toml index 69b8d355fb..0c4b88e9ce 100644 --- a/src/crewai/cli/templates/tool/pyproject.toml +++ b/src/crewai/cli/templates/tool/pyproject.toml @@ -5,7 +5,7 @@ description = "Power up your crews with {{folder_name}}" readme = "README.md" requires-python = ">=3.10,<3.13" dependencies = [ - "crewai[tools]>=0.86.0" + "crewai[tools]>=0.95.0" ] [tool.crewai] diff --git a/src/crewai/llm.py b/src/crewai/llm.py index bdac7080a9..bb1167bd88 100644 --- a/src/crewai/llm.py +++ b/src/crewai/llm.py @@ -4,6 +4,7 @@ import threading import warnings from contextlib import contextmanager +from importlib import resources from typing import Any, Dict, List, Optional, Union with warnings.catch_warnings(): @@ -78,6 +79,7 @@ def flush(self): def suppress_warnings(): with warnings.catch_warnings(): warnings.filterwarnings("ignore") + warnings.filterwarnings("ignore", message="open_text is deprecated*", category=DeprecationWarning) # Redirect stdout and stderr old_stdout = sys.stdout @@ -216,16 +218,17 @@ def get_context_window_size(self) -> int: return self.context_window_size def set_callbacks(self, callbacks: List[Any]): - callback_types = [type(callback) for callback in callbacks] - for callback in litellm.success_callback[:]: - if type(callback) in callback_types: - litellm.success_callback.remove(callback) + with suppress_warnings(): + callback_types = [type(callback) for callback in callbacks] + for callback in litellm.success_callback[:]: + if type(callback) in callback_types: + litellm.success_callback.remove(callback) - for callback in litellm._async_success_callback[:]: - if type(callback) in callback_types: - litellm._async_success_callback.remove(callback) + for callback in litellm._async_success_callback[:]: + if type(callback) in callback_types: + litellm._async_success_callback.remove(callback) - litellm.callbacks = callbacks + litellm.callbacks = callbacks def set_env_callbacks(self): """ @@ -246,19 +249,20 @@ def set_env_callbacks(self): This will set `litellm.success_callback` to ["langfuse", "langsmith"] and `litellm.failure_callback` to ["langfuse"]. """ - success_callbacks_str = os.environ.get("LITELLM_SUCCESS_CALLBACKS", "") - success_callbacks = [] - if success_callbacks_str: - success_callbacks = [ - callback.strip() for callback in success_callbacks_str.split(",") - ] - - failure_callbacks_str = os.environ.get("LITELLM_FAILURE_CALLBACKS", "") - failure_callbacks = [] - if failure_callbacks_str: - failure_callbacks = [ - callback.strip() for callback in failure_callbacks_str.split(",") - ] - - litellm.success_callback = success_callbacks - litellm.failure_callback = failure_callbacks + with suppress_warnings(): + success_callbacks_str = os.environ.get("LITELLM_SUCCESS_CALLBACKS", "") + success_callbacks = [] + if success_callbacks_str: + success_callbacks = [ + callback.strip() for callback in success_callbacks_str.split(",") + ] + + failure_callbacks_str = os.environ.get("LITELLM_FAILURE_CALLBACKS", "") + failure_callbacks = [] + if failure_callbacks_str: + failure_callbacks = [ + callback.strip() for callback in failure_callbacks_str.split(",") + ] + + litellm.success_callback = success_callbacks + litellm.failure_callback = failure_callbacks diff --git a/src/crewai/tools/base_tool.py b/src/crewai/tools/base_tool.py index c3840d23cd..b3c0f997cb 100644 --- a/src/crewai/tools/base_tool.py +++ b/src/crewai/tools/base_tool.py @@ -1,12 +1,23 @@ +import warnings from abc import ABC, abstractmethod from inspect import signature from typing import Any, Callable, Type, get_args, get_origin -from pydantic import BaseModel, ConfigDict, Field, create_model, validator +from pydantic import ( + BaseModel, + ConfigDict, + Field, + PydanticDeprecatedSince20, + create_model, + validator, +) from pydantic import BaseModel as PydanticBaseModel from crewai.tools.structured_tool import CrewStructuredTool +# Ignore all "PydanticDeprecatedSince20" warnings globally +warnings.filterwarnings("ignore", category=PydanticDeprecatedSince20) + class BaseTool(BaseModel, ABC): class _ArgsSchemaPlaceholder(PydanticBaseModel): diff --git a/src/crewai/utilities/internal_instructor.py b/src/crewai/utilities/internal_instructor.py index a3206ba150..65a05a61f4 100644 --- a/src/crewai/utilities/internal_instructor.py +++ b/src/crewai/utilities/internal_instructor.py @@ -31,10 +31,10 @@ def set_instructor(self): import instructor from litellm import completion - self._client = instructor.from_litellm( - completion, - mode=instructor.Mode.TOOLS, - ) + self._client = instructor.from_litellm( + completion, + mode=instructor.Mode.TOOLS, + ) def to_json(self): model = self.to_pydantic() diff --git a/tests/agents/agent_builder/base_agent_test.py b/tests/agents/agent_builder/base_agent_test.py index 7c0c2f4722..99f66dcc43 100644 --- a/tests/agents/agent_builder/base_agent_test.py +++ b/tests/agents/agent_builder/base_agent_test.py @@ -7,7 +7,7 @@ from crewai.tools.base_tool import BaseTool -class TestAgent(BaseAgent): +class MockAgent(BaseAgent): def execute_task( self, task: Any, @@ -29,7 +29,7 @@ def get_output_converter( def test_key(): - agent = TestAgent( + agent = MockAgent( role="test role", goal="test goal", backstory="test backstory", diff --git a/tests/cli/deploy/test_deploy_main.py b/tests/cli/deploy/test_deploy_main.py index ca89b2aa2d..c9a1b884eb 100644 --- a/tests/cli/deploy/test_deploy_main.py +++ b/tests/cli/deploy/test_deploy_main.py @@ -177,12 +177,12 @@ def test_list_crews(self): def test_get_crew_status(self): mock_response = MagicMock() mock_response.status_code = 200 - mock_response.json.return_value = {"name": "TestCrew", "status": "active"} + mock_response.json.return_value = {"name": "InternalCrew", "status": "active"} self.mock_client.crew_status_by_name.return_value = mock_response with patch("sys.stdout", new=StringIO()) as fake_out: self.deploy_command.get_crew_status() - self.assertIn("TestCrew", fake_out.getvalue()) + self.assertIn("InternalCrew", fake_out.getvalue()) self.assertIn("active", fake_out.getvalue()) def test_get_crew_logs(self): diff --git a/tests/project_test.py b/tests/project_test.py index 6c68f49937..ed9d86f2f7 100644 --- a/tests/project_test.py +++ b/tests/project_test.py @@ -27,7 +27,7 @@ def custom_named_task(self): @CrewBase -class TestCrew: +class InternalCrew: agents_config = "config/agents.yaml" tasks_config = "config/tasks.yaml" @@ -84,7 +84,7 @@ def test_task_memoization(): def test_crew_memoization(): - crew = TestCrew() + crew = InternalCrew() first_call_result = crew.crew() second_call_result = crew.crew() @@ -107,7 +107,7 @@ def test_task_name(): @pytest.mark.vcr(filter_headers=["authorization"]) def test_before_kickoff_modification(): - crew = TestCrew() + crew = InternalCrew() inputs = {"topic": "LLMs"} result = crew.crew().kickoff(inputs=inputs) assert "bicycles" in result.raw, "Before kickoff function did not modify inputs" @@ -115,7 +115,7 @@ def test_before_kickoff_modification(): @pytest.mark.vcr(filter_headers=["authorization"]) def test_after_kickoff_modification(): - crew = TestCrew() + crew = InternalCrew() # Assuming the crew execution returns a dict result = crew.crew().kickoff({"topic": "LLMs"}) @@ -126,7 +126,7 @@ def test_after_kickoff_modification(): @pytest.mark.vcr(filter_headers=["authorization"]) def test_before_kickoff_with_none_input(): - crew = TestCrew() + crew = InternalCrew() crew.crew().kickoff(None) # Test should pass without raising exceptions diff --git a/tests/test_manager_llm_delegation.py b/tests/test_manager_llm_delegation.py index 6f8671255f..6b1b97b9aa 100644 --- a/tests/test_manager_llm_delegation.py +++ b/tests/test_manager_llm_delegation.py @@ -6,7 +6,7 @@ from crewai.tools.agent_tools.base_agent_tools import BaseAgentTool -class TestAgentTool(BaseAgentTool): +class InternalAgentTool(BaseAgentTool): """Concrete implementation of BaseAgentTool for testing.""" def _run(self, *args, **kwargs): @@ -39,7 +39,7 @@ def test_agent_tool_role_matching(role_name, should_match): ) # Create test agent tool - agent_tool = TestAgentTool( + agent_tool = InternalAgentTool( name="test_tool", description="Test tool", agents=[test_agent] ) diff --git a/tests/tools/test_base_tool.py b/tests/tools/test_base_tool.py index 9f46b13ba5..51eb05b75e 100644 --- a/tests/tools/test_base_tool.py +++ b/tests/tools/test_base_tool.py @@ -15,7 +15,7 @@ def my_tool(question: str) -> str: my_tool.description == "Tool Name: Name of my tool\nTool Arguments: {'question': {'description': None, 'type': 'str'}}\nTool Description: Clear description for what this tool is useful for, your agent will need this information to use it." ) - assert my_tool.args_schema.schema()["properties"] == { + assert my_tool.args_schema.model_json_schema()["properties"] == { "question": {"title": "Question", "type": "string"} } assert ( @@ -29,7 +29,7 @@ def my_tool(question: str) -> str: converted_tool.description == "Tool Name: Name of my tool\nTool Arguments: {'question': {'description': None, 'type': 'str'}}\nTool Description: Clear description for what this tool is useful for, your agent will need this information to use it." ) - assert converted_tool.args_schema.schema()["properties"] == { + assert converted_tool.args_schema.model_json_schema()["properties"] == { "question": {"title": "Question", "type": "string"} } assert ( @@ -54,7 +54,7 @@ def _run(self, question: str) -> str: my_tool.description == "Tool Name: Name of my tool\nTool Arguments: {'question': {'description': None, 'type': 'str'}}\nTool Description: Clear description for what this tool is useful for, your agent will need this information to use it." ) - assert my_tool.args_schema.schema()["properties"] == { + assert my_tool.args_schema.model_json_schema()["properties"] == { "question": {"title": "Question", "type": "string"} } assert my_tool.run("What is the meaning of life?") == "What is the meaning of life?" @@ -66,7 +66,7 @@ def _run(self, question: str) -> str: converted_tool.description == "Tool Name: Name of my tool\nTool Arguments: {'question': {'description': None, 'type': 'str'}}\nTool Description: Clear description for what this tool is useful for, your agent will need this information to use it." ) - assert converted_tool.args_schema.schema()["properties"] == { + assert converted_tool.args_schema.model_json_schema()["properties"] == { "question": {"title": "Question", "type": "string"} } assert ( diff --git a/tests/tools/test_structured_tool.py b/tests/tools/test_structured_tool.py index 32ebd805b5..333220486b 100644 --- a/tests/tools/test_structured_tool.py +++ b/tests/tools/test_structured_tool.py @@ -25,7 +25,7 @@ class TestSchema(BaseModel): return TestSchema -class TestCrewStructuredTool: +class InternalCrewStructuredTool: def test_initialization(self, basic_function, schema_class): """Test basic initialization of CrewStructuredTool""" tool = CrewStructuredTool( diff --git a/tests/utilities/evaluators/test_crew_evaluator_handler.py b/tests/utilities/evaluators/test_crew_evaluator_handler.py index 649c259982..4fbe2b2d42 100644 --- a/tests/utilities/evaluators/test_crew_evaluator_handler.py +++ b/tests/utilities/evaluators/test_crew_evaluator_handler.py @@ -12,7 +12,7 @@ ) -class TestCrewEvaluator: +class InternalCrewEvaluator: @pytest.fixture def crew_planner(self): agent = Agent(role="Agent 1", goal="Goal 1", backstory="Backstory 1") diff --git a/tests/utilities/test_planning_handler.py b/tests/utilities/test_planning_handler.py index e15877c9fd..e1c27c341b 100644 --- a/tests/utilities/test_planning_handler.py +++ b/tests/utilities/test_planning_handler.py @@ -16,7 +16,7 @@ ) -class TestCrewPlanner: +class InternalCrewPlanner: @pytest.fixture def crew_planner(self): tasks = [ @@ -115,13 +115,13 @@ class MockTool(BaseTool): def __init__(self, name: str, description: str): tool_data = {"name": name, "description": description} super().__init__(**tool_data) - + def __str__(self): return self.name - + def __repr__(self): return self.name - + def to_structured_tool(self): return self @@ -149,11 +149,11 @@ def _generate_description(self) -> str: ] ) ) - + # Create planner with the new task planner = CrewPlanner([task], None) tasks_summary = planner._create_tasks_summary() - + # Verify task summary content assert isinstance(tasks_summary, str) assert task.description in tasks_summary diff --git a/tests/utilities/test_training_handler.py b/tests/utilities/test_training_handler.py index a4da5a3dcb..17a1ceb548 100644 --- a/tests/utilities/test_training_handler.py +++ b/tests/utilities/test_training_handler.py @@ -4,7 +4,7 @@ from crewai.utilities.training_handler import CrewTrainingHandler -class TestCrewTrainingHandler(unittest.TestCase): +class InternalCrewTrainingHandler(unittest.TestCase): def setUp(self): self.handler = CrewTrainingHandler("trained_data.pkl") diff --git a/uv.lock b/uv.lock index 1ed8e9bcde..6c2387dd22 100644 --- a/uv.lock +++ b/uv.lock @@ -631,7 +631,7 @@ wheels = [ [[package]] name = "crewai" -version = "0.86.0" +version = "0.95.0" source = { editable = "." } dependencies = [ { name = "appdirs" },