From b442fe20a2c035269760e2057c90e0c477fddead Mon Sep 17 00:00:00 2001 From: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Date: Sun, 9 Feb 2025 19:42:17 +0000 Subject: [PATCH] fix: Add to_structured_tool method to BaseTool Co-Authored-By: Joe Moura --- src/crewai/tools/base_tool.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/crewai/tools/base_tool.py b/src/crewai/tools/base_tool.py index bc6c19afd..88879a331 100644 --- a/src/crewai/tools/base_tool.py +++ b/src/crewai/tools/base_tool.py @@ -6,6 +6,8 @@ from pydantic import BaseModel, ConfigDict, Field, create_model, validator from pydantic.fields import FieldInfo from pydantic import BaseModel as PydanticBaseModel +from crewai.tools.structured_tool import CrewStructuredTool + def _create_model_fields(fields: Dict[str, Tuple[Any, FieldInfo]]) -> Dict[str, Any]: """Helper function to create model fields with proper type hints.""" return {name: (annotation, field) for name, (annotation, field) in fields.items()} @@ -69,6 +71,17 @@ class BaseTool(BaseModel, ABC): ) -> Any: """Here goes the actual implementation of the tool.""" + def to_structured_tool(self) -> CrewStructuredTool: + """Convert this tool to a CrewStructuredTool instance.""" + self._set_args_schema() + return CrewStructuredTool( + name=self.name, + description=self.description, + args_schema=self.args_schema, + func=self._run, + result_as_answer=self.result_as_answer, + ) + def _set_args_schema(self) -> None: if self.args_schema is None: class_name = f"{self.__class__.__name__}Schema"