From ef424d3dae92c52d05547c4eda62c896aa6201bf Mon Sep 17 00:00:00 2001 From: lorenzejay Date: Wed, 16 Apr 2025 15:51:58 -0700 Subject: [PATCH] refactor: Improve tool processing logic in BaseAgent - Added a check to return an empty list if no tools are provided. - Simplified the tool attribute validation by using a list of required attributes. - Removed commented-out abstract method definition for clarity. --- src/crewai/agents/agent_builder/base_agent.py | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/src/crewai/agents/agent_builder/base_agent.py b/src/crewai/agents/agent_builder/base_agent.py index 559812387..a82cd12d7 100644 --- a/src/crewai/agents/agent_builder/base_agent.py +++ b/src/crewai/agents/agent_builder/base_agent.py @@ -171,15 +171,15 @@ class BaseAgent(ABC, BaseModel): tool meets these criteria, it is processed and added to the list of tools. Otherwise, a ValueError is raised. """ + if not tools: + return [] + processed_tools = [] + required_attrs = ["name", "func", "description"] for tool in tools: if isinstance(tool, BaseTool): processed_tools.append(tool) - elif ( - hasattr(tool, "name") - and hasattr(tool, "func") - and hasattr(tool, "description") - ): + elif all(hasattr(tool, attr) for attr in required_attrs): # Tool has the required attributes, create a Tool instance processed_tools.append(Tool.from_langchain(tool)) else: @@ -261,13 +261,6 @@ class BaseAgent(ABC, BaseModel): """Set the task tools that init BaseAgenTools class.""" pass - # @abstractmethod - # def get_output_converter( - # self, llm: Any, text: str, model: type[BaseModel] | None, instructions: str - # ) -> Converter: - # """Get the converter class for the agent to create json/pydantic outputs.""" - # pass - def copy(self: T) -> T: # type: ignore # Signature of "copy" incompatible with supertype "BaseModel" """Create a deep copy of the Agent.""" exclude = {