mirror of
https://github.com/crewAIInc/crewAI.git
synced 2026-01-10 00:28:31 +00:00
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:
@@ -254,6 +254,7 @@ class BaseAgent(ABC, BaseModel):
|
|||||||
task: Any,
|
task: Any,
|
||||||
context: Optional[str] = None,
|
context: Optional[str] = None,
|
||||||
tools: Optional[List[BaseTool]] = None,
|
tools: Optional[List[BaseTool]] = None,
|
||||||
|
recursion_depth: int = 0,
|
||||||
) -> str:
|
) -> str:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|||||||
@@ -24,14 +24,14 @@ class AgentTools:
|
|||||||
i18n=self.i18n,
|
i18n=self.i18n,
|
||||||
description=self.i18n.tools("delegate_work").format(coworkers=coworkers), # type: ignore
|
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(
|
ask_tool = AskQuestionTool(
|
||||||
agents=self.agents,
|
agents=self.agents,
|
||||||
i18n=self.i18n,
|
i18n=self.i18n,
|
||||||
description=self.i18n.tools("ask_question").format(coworkers=coworkers), # type: ignore
|
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]
|
return [delegate_tool, ask_tool]
|
||||||
|
|
||||||
|
|||||||
@@ -108,12 +108,12 @@ class BaseAgentTool(BaseTool):
|
|||||||
available_agents = [agent.role for agent in self.agents]
|
available_agents = [agent.role for agent in self.agents]
|
||||||
logger.debug(f"Available agents: {available_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
|
available_agent
|
||||||
for available_agent in self.agents
|
for available_agent in self.agents
|
||||||
if self.sanitize_agent_name(available_agent.role) == sanitized_name
|
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:
|
except (AttributeError, ValueError) as e:
|
||||||
# Handle specific exceptions that might occur during role name processing
|
# Handle specific exceptions that might occur during role name processing
|
||||||
return self.i18n.errors("agent_tool_unexisting_coworker").format(
|
return self.i18n.errors("agent_tool_unexisting_coworker").format(
|
||||||
@@ -123,7 +123,7 @@ class BaseAgentTool(BaseTool):
|
|||||||
error=str(e)
|
error=str(e)
|
||||||
)
|
)
|
||||||
|
|
||||||
if not agent:
|
if not matching_agents:
|
||||||
# No matching agent found after sanitization
|
# No matching agent found after sanitization
|
||||||
return self.i18n.errors("agent_tool_unexisting_coworker").format(
|
return self.i18n.errors("agent_tool_unexisting_coworker").format(
|
||||||
coworkers="\n".join(
|
coworkers="\n".join(
|
||||||
@@ -132,7 +132,7 @@ class BaseAgentTool(BaseTool):
|
|||||||
error=f"No agent found with role '{sanitized_name}'"
|
error=f"No agent found with role '{sanitized_name}'"
|
||||||
)
|
)
|
||||||
|
|
||||||
agent = agent[0]
|
agent = matching_agents[0]
|
||||||
try:
|
try:
|
||||||
logger.debug(f"Executing task with {len(tools) if tools else 0} tools at recursion depth {recursion_depth}")
|
logger.debug(f"Executing task with {len(tools) if tools else 0} tools at recursion depth {recursion_depth}")
|
||||||
task_with_assigned_agent = Task(
|
task_with_assigned_agent = Task(
|
||||||
|
|||||||
Reference in New Issue
Block a user