fix type issues

This commit is contained in:
Brandon Hancock
2025-02-13 15:00:27 -05:00
parent ff32880a54
commit 265b37316b
2 changed files with 10 additions and 9 deletions

View File

@@ -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:

View File

@@ -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."""