Fix more type issues

This commit is contained in:
Brandon Hancock
2025-02-13 15:03:17 -05:00
parent 265b37316b
commit fd0e1bdd1a
2 changed files with 19 additions and 8 deletions

View File

@@ -280,8 +280,12 @@ class LangChainAgentAdapter(BaseAgent):
"LangGraph library not found. Please run `uv add langgraph` to add LangGraph support."
) from e
# Ensure raw_tools is always a list, even if tools and self.tools are None.
raw_tools = tools or self.tools or []
# Ensure raw_tools is always a list.
raw_tools: List[Any] = (
tools
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.
if not raw_tools:
if hasattr(self.langchain_agent, "agent") and hasattr(
@@ -293,14 +297,14 @@ class LangChainAgentAdapter(BaseAgent):
used_tools = []
try:
# Import the CrewAI Tool class.
from crewai.tools.base_tool import Tool as CrewTool
# Import the CrewAI Tool class and name it differently to avoid type assignment issues.
from crewai.tools.base_tool import Tool as CrewToolClass
except ImportError:
CrewTool: Optional[Type[BaseTool]] = None # Explicitly annotate as Optional
CrewToolClass = None # No type annotation here
for tool in raw_tools:
# If the tool is a CrewAI Tool, convert it to a LangChain compatible tool.
if CrewTool is not None and isinstance(tool, CrewTool):
if CrewToolClass is not None and isinstance(tool, CrewToolClass):
used_tools.append(tool.to_langchain())
else:
used_tools.append(tool)

View File

@@ -19,6 +19,13 @@ from crewai.tools.structured_tool import CrewStructuredTool
warnings.filterwarnings("ignore", category=PydanticDeprecatedSince20)
# Define a helper function with an explicit signature
def default_cache_function(
_args: Optional[Any] = None, _result: Optional[Any] = None
) -> bool:
return True
class BaseTool(BaseModel, ABC):
class _ArgsSchemaPlaceholder(PydanticBaseModel):
pass
@@ -37,9 +44,9 @@ class BaseTool(BaseModel, ABC):
description_updated: bool = False
"""Flag to check if the description has been updated."""
cache_function: Callable[[Optional[Any], Optional[Any]], bool] = (
lambda _args=None, _result=None: True
default_cache_function
)
"""Function that will be used to determine if the tool should be cached, should return a boolean. If None, the tool will be cached."""
"""Function used to determine if the tool should be cached."""
result_as_answer: bool = False
"""Flag to check if the tool should be the final agent answer."""