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 <joao@crewai.com>
This commit is contained in:
Devin AI
2025-05-25 04:50:41 +00:00
parent 1d86f196d7
commit bb541c059c
3 changed files with 7 additions and 6 deletions

View File

@@ -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

View File

@@ -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]

View File

@@ -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(