From 5495cccf2f006fb7974e1a00f77669d3ade19dd4 Mon Sep 17 00:00:00 2001 From: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Date: Mon, 18 Aug 2025 14:07:07 +0000 Subject: [PATCH] fix: Resolve remaining type-checker and lint issues MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 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 --- .../agents/agent_adapters/langgraph/langgraph_adapter.py | 8 ++++---- src/crewai/utilities/tool_utils.py | 5 +++-- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/crewai/agents/agent_adapters/langgraph/langgraph_adapter.py b/src/crewai/agents/agent_adapters/langgraph/langgraph_adapter.py index afc16cf2d..f60767f42 100644 --- a/src/crewai/agents/agent_adapters/langgraph/langgraph_adapter.py +++ b/src/crewai/agents/agent_adapters/langgraph/langgraph_adapter.py @@ -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 @@ -22,7 +22,6 @@ from crewai.utilities.events.agent_events import ( ) try: - from langchain_core.messages import ToolMessage from langgraph.checkpoint.memory import MemorySaver from langgraph.prebuilt import create_react_agent @@ -198,7 +197,7 @@ class LangGraphAgentAdapter(BaseAgentAdapter): ) 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.""" self.configure_tools(tools) @@ -206,7 +205,8 @@ class LangGraphAgentAdapter(BaseAgentAdapter): """Configure tools for the LangGraph agent.""" if tools: 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: self._tool_adapter.configure_tools(all_tools) available_tools = self._tool_adapter.tools() diff --git a/src/crewai/utilities/tool_utils.py b/src/crewai/utilities/tool_utils.py index 58418e346..00f22a7a5 100644 --- a/src/crewai/utilities/tool_utils.py +++ b/src/crewai/utilities/tool_utils.py @@ -53,10 +53,11 @@ def execute_tool_and_check_finality( except Exception as 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( tools_handler=tools_handler, - tools=tools, + tools=executable_tools_for_usage, function_calling_llm=function_calling_llm, task=task, agent=agent,