mirror of
https://github.com/crewAIInc/crewAI.git
synced 2026-01-11 00:58:30 +00:00
Fix more type issues
This commit is contained in:
@@ -280,8 +280,12 @@ class LangChainAgentAdapter(BaseAgent):
|
|||||||
"LangGraph library not found. Please run `uv add langgraph` to add LangGraph support."
|
"LangGraph library not found. Please run `uv add langgraph` to add LangGraph support."
|
||||||
) from e
|
) from e
|
||||||
|
|
||||||
# Ensure raw_tools is always a list, even if tools and self.tools are None.
|
# Ensure raw_tools is always a list.
|
||||||
raw_tools = tools or self.tools or []
|
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.
|
# Fallback: if raw_tools is still empty, try to extract them from the wrapped langchain agent.
|
||||||
if not raw_tools:
|
if not raw_tools:
|
||||||
if hasattr(self.langchain_agent, "agent") and hasattr(
|
if hasattr(self.langchain_agent, "agent") and hasattr(
|
||||||
@@ -293,14 +297,14 @@ class LangChainAgentAdapter(BaseAgent):
|
|||||||
|
|
||||||
used_tools = []
|
used_tools = []
|
||||||
try:
|
try:
|
||||||
# Import the CrewAI Tool class.
|
# Import the CrewAI Tool class and name it differently to avoid type assignment issues.
|
||||||
from crewai.tools.base_tool import Tool as CrewTool
|
from crewai.tools.base_tool import Tool as CrewToolClass
|
||||||
except ImportError:
|
except ImportError:
|
||||||
CrewTool: Optional[Type[BaseTool]] = None # Explicitly annotate as Optional
|
CrewToolClass = None # No type annotation here
|
||||||
|
|
||||||
for tool in raw_tools:
|
for tool in raw_tools:
|
||||||
# If the tool is a CrewAI Tool, convert it to a LangChain compatible tool.
|
# 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())
|
used_tools.append(tool.to_langchain())
|
||||||
else:
|
else:
|
||||||
used_tools.append(tool)
|
used_tools.append(tool)
|
||||||
|
|||||||
@@ -19,6 +19,13 @@ from crewai.tools.structured_tool import CrewStructuredTool
|
|||||||
warnings.filterwarnings("ignore", category=PydanticDeprecatedSince20)
|
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 BaseTool(BaseModel, ABC):
|
||||||
class _ArgsSchemaPlaceholder(PydanticBaseModel):
|
class _ArgsSchemaPlaceholder(PydanticBaseModel):
|
||||||
pass
|
pass
|
||||||
@@ -37,9 +44,9 @@ class BaseTool(BaseModel, ABC):
|
|||||||
description_updated: bool = False
|
description_updated: bool = False
|
||||||
"""Flag to check if the description has been updated."""
|
"""Flag to check if the description has been updated."""
|
||||||
cache_function: Callable[[Optional[Any], Optional[Any]], bool] = (
|
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
|
result_as_answer: bool = False
|
||||||
"""Flag to check if the tool should be the final agent answer."""
|
"""Flag to check if the tool should be the final agent answer."""
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user