mirror of
https://github.com/crewAIInc/crewAI.git
synced 2026-05-02 15:52:34 +00:00
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:
@@ -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)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user