Framework for orchestrating role-playing, autonomous AI agents. By fostering collaborative intelligence, CrewAI empowers agents to work together seamlessly, tackling complex tasks.
feat: cleanup Pydantic warning (#2507)
Lucas Gomide63ef3918dd4c
diff --git a/src/crewai/tools/base_tool.py b/src/crewai/tools/base_tool.pyindex b3c0f997c..dc69b02a2 100644--- a/src/crewai/tools/base_tool.py+++ b/src/crewai/tools/base_tool.py@@ -7,29 +7,27 @@ from pydantic import (BaseModel,ConfigDict,Field,- PydanticDeprecatedSince20,create_model,- validator,+ field_validator,)from pydantic import BaseModel as PydanticBaseModelfrom crewai.tools.structured_tool import CrewStructuredTool-# Ignore all "PydanticDeprecatedSince20" warnings globally-warnings.filterwarnings("ignore", category=PydanticDeprecatedSince20)-class BaseTool(BaseModel, ABC):class _ArgsSchemaPlaceholder(PydanticBaseModel):pass- model_config = ConfigDict()+ model_config = ConfigDict(arbitrary_types_allowed=True)name: str"""The unique name of the tool that clearly communicates its purpose."""description: str"""Used to tell the model how/when/why to use the tool."""- args_schema: Type[PydanticBaseModel] = Field(default_factory=_ArgsSchemaPlaceholder)+ args_schema: Type[PydanticBaseModel] = Field(+ default_factory=_ArgsSchemaPlaceholder, validate_default=True+ )"""The schema for the arguments that the tool accepts."""description_updated: bool = False"""Flag to check if the description has been updated."""@@ -38,7 +36,8 @@ class BaseTool(BaseModel, ABC):result_as_answer: bool = False"""Flag to check if the tool should be the final agent answer."""- @validator("args_schema", always=True, pre=True)+ @field_validator("args_schema", mode="before")+ @classmethoddef _default_args_schema(cls, v: Type[PydanticBaseModel]) -> Type[PydanticBaseModel]:diff --git a/src/crewai/utilities/converter.py b/src/crewai/utilities/converter.pyindex 991185f4a..b16677ace 100644--- a/src/crewai/utilities/converter.py+++ b/src/crewai/utilities/converter.py@@ -287,8 +287,9 @@ def generate_model_description(model: Type[BaseModel]) -> str:else:return str(field_type)- fields = model.__annotations__+ fields = model.model_fieldsfield_descriptions = [- f'"{name}": {describe_field(type_)}' for name, type_ in fields.items()+ f'"{name}": {describe_field(field.annotation)}'+ for name, field in fields.items()]return "{\n " + ",\n ".join(field_descriptions) + "\n}"