fix: Resolve type-checker errors for mixed tool types

- Add Union types to handle both BaseTool and dict in tool parameters
- Update tool utility functions to handle mixed types safely
- Filter raw tool definitions in agent adapters
- Fix experimental evaluation metrics to handle mixed tool types
- Maintain backward compatibility while adding hosted tools support

Co-Authored-By: João <joao@crewai.com>
This commit is contained in:
Devin AI
2025-08-18 14:03:40 +00:00
parent 95d3b5dbc3
commit be09b519c4
5 changed files with 22 additions and 15 deletions

View File

@@ -1,4 +1,4 @@
from typing import Any, Dict, List, Optional
from typing import Any, Dict, List, Optional, Union
from crewai.agents.parser import AgentAction
from crewai.security import Fingerprint
@@ -10,7 +10,7 @@ from crewai.utilities.i18n import I18N
def execute_tool_and_check_finality(
agent_action: AgentAction,
tools: List[CrewStructuredTool],
tools: List[Union[CrewStructuredTool, dict]],
i18n: I18N,
agent_key: Optional[str] = None,
agent_role: Optional[str] = None,
@@ -37,7 +37,8 @@ def execute_tool_and_check_finality(
ToolResult containing the execution result and whether it should be treated as a final answer
"""
try:
tool_name_to_tool_map = {tool.name: tool for tool in tools}
executable_tools = [tool for tool in tools if hasattr(tool, 'name') and hasattr(tool, 'result_as_answer')]
tool_name_to_tool_map = {tool.name: tool for tool in executable_tools}
if agent_key and agent_role and agent:
fingerprint_context = fingerprint_context or {}
@@ -82,7 +83,7 @@ def execute_tool_and_check_finality(
# Handle invalid tool name
tool_result = i18n.errors("wrong_tool_name").format(
tool=tool_calling.tool_name,
tools=", ".join([tool.name.casefold() for tool in tools]),
tools=", ".join([tool.name.casefold() for tool in executable_tools]),
)
return ToolResult(tool_result, False)