diff --git a/src/crewai/agents/langchain_agent_adapter.py b/src/crewai/agents/langchain_agent_adapter.py index 6453b33ae..f33f989ce 100644 --- a/src/crewai/agents/langchain_agent_adapter.py +++ b/src/crewai/agents/langchain_agent_adapter.py @@ -286,7 +286,7 @@ class LangChainAgentAdapter(BaseAgent): if tools is not None else (self.tools if self.tools is not None else []) ) - # Fallback: if raw_tools is still empty, try to extract them from the wrapped langchain agent. + # 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" @@ -297,14 +297,14 @@ class LangChainAgentAdapter(BaseAgent): used_tools = [] try: - # Import the CrewAI Tool class and name it differently to avoid type assignment issues. - from crewai.tools.base_tool import Tool as CrewToolClass + # Import the CrewAI Tool class using a local variable name to avoid reassigning the imported type. + from crewai.tools.base_tool import Tool as CrewToolLocal except ImportError: - CrewToolClass = None # No type annotation here + CrewToolLocal = None # type: Optional[Type[BaseTool]] for tool in raw_tools: # If the tool is a CrewAI Tool, convert it to a LangChain compatible tool. - if CrewToolClass is not None and isinstance(tool, CrewToolClass): + if CrewToolLocal is not None and isinstance(tool, CrewToolLocal): used_tools.append(tool.to_langchain()) else: used_tools.append(tool) diff --git a/src/crewai/tools/base_tool.py b/src/crewai/tools/base_tool.py index 52cd0f382..5fea0c798 100644 --- a/src/crewai/tools/base_tool.py +++ b/src/crewai/tools/base_tool.py @@ -189,38 +189,13 @@ class BaseTool(BaseModel, ABC): return origin.__name__ - # def to_langchain(self) -> Any: - # """ - # Convert this CrewAI Tool instance into a LangChain-compatible tool. - # Returns a concrete subclass of LangChain's BaseTool. - # """ - # try: - # from langchain_core.tools import Tool as LC_Tool - # except ImportError as e: - # raise ImportError( - # "LangChain library not found. Please run `uv add langchain` to add LangChain support." - # ) from e - - # # Capture the function in a local variable to avoid referencing None. - # tool_func = self.func - - # class ConcreteLangChainTool(LC_Tool): - # def _run(self, *args, **kwargs): - # return tool_func(*args, **kwargs) - - # # Do not pass callback_manager; let LC_Tool use its default. - # print("Creating concrete langchain tool") - # return ConcreteLangChainTool( - # name=self.name, - # description=self.description, - # func=self._run, - # args_schema=self.args_schema, - # ) - @property def get(self) -> Callable[[str, Any], Any]: - # Returns a callable that looks up attributes on the instance. - return lambda key, default=None: getattr(self, key, default) + # Instead of an inline lambda, we define a helper function with explicit types. + def _getter(key: str, default: Any = None) -> Any: + return getattr(self, key, default) + + return _getter class Tool(BaseTool):