fix: Resolve remaining type-checker and lint issues

- Fix ToolUsage constructor to only accept executable tools
- Remove unused imports from langgraph adapter
- Filter tools correctly for mixed type handling

Co-Authored-By: João <joao@crewai.com>
This commit is contained in:
Devin AI
2025-08-18 14:07:07 +00:00
parent d8eaadca47
commit 5495cccf2f
2 changed files with 7 additions and 6 deletions

View File

@@ -1,4 +1,4 @@
from typing import Any, AsyncIterable, Dict, List, Optional, Union from typing import Any, Dict, List, Optional, Union
from pydantic import Field, PrivateAttr from pydantic import Field, PrivateAttr
@@ -22,7 +22,6 @@ from crewai.utilities.events.agent_events import (
) )
try: try:
from langchain_core.messages import ToolMessage
from langgraph.checkpoint.memory import MemorySaver from langgraph.checkpoint.memory import MemorySaver
from langgraph.prebuilt import create_react_agent from langgraph.prebuilt import create_react_agent
@@ -198,7 +197,7 @@ class LangGraphAgentAdapter(BaseAgentAdapter):
) )
raise raise
def create_agent_executor(self, tools: Optional[List[BaseTool]] = None) -> None: def create_agent_executor(self, tools: Optional[List[Union[BaseTool, dict]]] = None) -> None:
"""Configure the LangGraph agent for execution.""" """Configure the LangGraph agent for execution."""
self.configure_tools(tools) self.configure_tools(tools)
@@ -206,7 +205,8 @@ class LangGraphAgentAdapter(BaseAgentAdapter):
"""Configure tools for the LangGraph agent.""" """Configure tools for the LangGraph agent."""
if tools: if tools:
base_tools = [tool for tool in tools if isinstance(tool, BaseTool)] base_tools = [tool for tool in tools if isinstance(tool, BaseTool)]
all_tools = list(self.tools or []) + list(base_tools or []) existing_base_tools = [tool for tool in (self.tools or []) if isinstance(tool, BaseTool)]
all_tools = existing_base_tools + base_tools
if all_tools: if all_tools:
self._tool_adapter.configure_tools(all_tools) self._tool_adapter.configure_tools(all_tools)
available_tools = self._tool_adapter.tools() available_tools = self._tool_adapter.tools()

View File

@@ -53,10 +53,11 @@ def execute_tool_and_check_finality(
except Exception as e: except Exception as e:
raise ValueError(f"Failed to set fingerprint: {e}") raise ValueError(f"Failed to set fingerprint: {e}")
# Create tool usage instance # Create tool usage instance - filter to only executable tools for ToolUsage
executable_tools_for_usage = [tool for tool in tools if hasattr(tool, 'name') and hasattr(tool, 'result_as_answer')]
tool_usage = ToolUsage( tool_usage = ToolUsage(
tools_handler=tools_handler, tools_handler=tools_handler,
tools=tools, tools=executable_tools_for_usage,
function_calling_llm=function_calling_llm, function_calling_llm=function_calling_llm,
task=task, task=task,
agent=agent, agent=agent,