From 265b37316bf2ad19d9fab766153441616bbc565d Mon Sep 17 00:00:00 2001 From: Brandon Hancock Date: Thu, 13 Feb 2025 15:00:27 -0500 Subject: [PATCH] fix type issues --- src/crewai/agents/langchain_agent_adapter.py | 15 +++++++-------- src/crewai/tools/base_tool.py | 4 +++- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/crewai/agents/langchain_agent_adapter.py b/src/crewai/agents/langchain_agent_adapter.py index 9c831815d..14bc5d382 100644 --- a/src/crewai/agents/langchain_agent_adapter.py +++ b/src/crewai/agents/langchain_agent_adapter.py @@ -280,27 +280,26 @@ class LangChainAgentAdapter(BaseAgent): "LangGraph library not found. Please run `uv add langgraph` to add LangGraph support." ) from e - # Otherwise, create a new executor from the LLM. - raw_tools = tools or self.tools - - # Fallback: if raw_tools is empty, try to extract them from the wrapped langchain agent. + # Ensure raw_tools is always a list, even if tools and self.tools are None. + raw_tools = tools or self.tools or [] + # Fallback: if raw_tools is still empty, try to extract them from the wrapped langchain agent. if not raw_tools: if hasattr(self.langchain_agent, "agent") and hasattr( self.langchain_agent.agent, "tools" ): - raw_tools = self.langchain_agent.agent.tools + raw_tools = self.langchain_agent.agent.tools or [] else: - raw_tools = getattr(self.langchain_agent, "tools", []) + raw_tools = getattr(self.langchain_agent, "tools", []) or [] used_tools = [] try: # Import the CrewAI Tool class. from crewai.tools.base_tool import Tool as CrewTool except ImportError: - CrewTool = None + CrewTool: Optional[Type[BaseTool]] = None # Explicitly annotate as Optional for tool in raw_tools: - # Only attempt conversion if this is an instance of our CrewAI Tool. + # If the tool is a CrewAI Tool, convert it to a LangChain compatible tool. if CrewTool is not None and isinstance(tool, CrewTool): used_tools.append(tool.to_langchain()) else: diff --git a/src/crewai/tools/base_tool.py b/src/crewai/tools/base_tool.py index 01345d066..bbe21302b 100644 --- a/src/crewai/tools/base_tool.py +++ b/src/crewai/tools/base_tool.py @@ -36,7 +36,9 @@ class BaseTool(BaseModel, ABC): """The schema for the arguments that the tool accepts.""" description_updated: bool = False """Flag to check if the description has been updated.""" - cache_function: Callable = lambda _args=None, _result=None: True + cache_function: Callable[[Optional[Any], Optional[Any]], bool] = ( + lambda _args=None, _result=None: True + ) """Function that will be used to determine if the tool should be cached, should return a boolean. If None, the tool will be cached.""" result_as_answer: bool = False """Flag to check if the tool should be the final agent answer."""