From bb541c059c9e36589a3459933b44802f2b629991 Mon Sep 17 00:00:00 2001 From: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Date: Sun, 25 May 2025 04:50:41 +0000 Subject: [PATCH] Fix type-checker issues in A2A protocol implementation - Update BaseAgent.execute_task signature to include recursion_depth parameter - Fix variable reference in base_agent_tools.py (agent -> matching_agents) - Remove type annotations in assignment to non-self attributes in agent_tools.py Co-Authored-By: Joe Moura --- src/crewai/agents/agent_builder/base_agent.py | 1 + src/crewai/tools/agent_tools/agent_tools.py | 4 ++-- src/crewai/tools/agent_tools/base_agent_tools.py | 8 ++++---- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/crewai/agents/agent_builder/base_agent.py b/src/crewai/agents/agent_builder/base_agent.py index ba2596f63..fba0662ad 100644 --- a/src/crewai/agents/agent_builder/base_agent.py +++ b/src/crewai/agents/agent_builder/base_agent.py @@ -254,6 +254,7 @@ class BaseAgent(ABC, BaseModel): task: Any, context: Optional[str] = None, tools: Optional[List[BaseTool]] = None, + recursion_depth: int = 0, ) -> str: pass diff --git a/src/crewai/tools/agent_tools/agent_tools.py b/src/crewai/tools/agent_tools/agent_tools.py index adef0fa6a..570a6b57b 100644 --- a/src/crewai/tools/agent_tools/agent_tools.py +++ b/src/crewai/tools/agent_tools/agent_tools.py @@ -24,14 +24,14 @@ class AgentTools: i18n=self.i18n, description=self.i18n.tools("delegate_work").format(coworkers=coworkers), # type: ignore ) - delegate_tool._agent_tools: List[BaseTool] = self._get_all_agent_tools() + delegate_tool._agent_tools = self._get_all_agent_tools() ask_tool = AskQuestionTool( agents=self.agents, i18n=self.i18n, description=self.i18n.tools("ask_question").format(coworkers=coworkers), # type: ignore ) - ask_tool._agent_tools: List[BaseTool] = self._get_all_agent_tools() + ask_tool._agent_tools = self._get_all_agent_tools() return [delegate_tool, ask_tool] diff --git a/src/crewai/tools/agent_tools/base_agent_tools.py b/src/crewai/tools/agent_tools/base_agent_tools.py index 78c09e7f4..d712c3a7b 100644 --- a/src/crewai/tools/agent_tools/base_agent_tools.py +++ b/src/crewai/tools/agent_tools/base_agent_tools.py @@ -108,12 +108,12 @@ class BaseAgentTool(BaseTool): available_agents = [agent.role for agent in self.agents] logger.debug(f"Available agents: {available_agents}") - agent = [ # type: ignore # Incompatible types in assignment (expression has type "list[BaseAgent]", variable has type "str | None") + matching_agents = [ available_agent for available_agent in self.agents if self.sanitize_agent_name(available_agent.role) == sanitized_name ] - logger.debug(f"Found {len(agent)} matching agents for role '{sanitized_name}'") + logger.debug(f"Found {len(matching_agents)} matching agents for role '{sanitized_name}'") except (AttributeError, ValueError) as e: # Handle specific exceptions that might occur during role name processing return self.i18n.errors("agent_tool_unexisting_coworker").format( @@ -123,7 +123,7 @@ class BaseAgentTool(BaseTool): error=str(e) ) - if not agent: + if not matching_agents: # No matching agent found after sanitization return self.i18n.errors("agent_tool_unexisting_coworker").format( coworkers="\n".join( @@ -132,7 +132,7 @@ class BaseAgentTool(BaseTool): error=f"No agent found with role '{sanitized_name}'" ) - agent = agent[0] + agent = matching_agents[0] try: logger.debug(f"Executing task with {len(tools) if tools else 0} tools at recursion depth {recursion_depth}") task_with_assigned_agent = Task(