1- from typing import Any , Dict , List , Optional
1+ from typing import Any
22
33from crewai .agents .parser import AgentAction
44from crewai .security import Fingerprint
55from crewai .tools .structured_tool import CrewStructuredTool
66from crewai .tools .tool_types import ToolResult
7- from crewai .tools .tool_usage import ToolUsage , ToolUsageErrorException
7+ from crewai .tools .tool_usage import ToolUsage , ToolUsageError
88from crewai .utilities .i18n import I18N
99
1010
1111def execute_tool_and_check_finality (
1212 agent_action : AgentAction ,
13- tools : List [CrewStructuredTool ],
13+ tools : list [CrewStructuredTool ],
1414 i18n : I18N ,
15- agent_key : Optional [ str ] = None ,
16- agent_role : Optional [ str ] = None ,
17- tools_handler : Optional [ Any ] = None ,
18- task : Optional [ Any ] = None ,
19- agent : Optional [ Any ] = None ,
20- function_calling_llm : Optional [ Any ] = None ,
21- fingerprint_context : Optional [ Dict [ str , str ]] = None ,
15+ agent_key : str | None = None ,
16+ agent_role : str | None = None ,
17+ tools_handler : Any | None = None ,
18+ task : Any | None = None ,
19+ agent : Any | None = None ,
20+ function_calling_llm : Any | None = None ,
21+ fingerprint_context : dict [ str , str ] | None = None ,
2222) -> ToolResult :
2323 """Execute a tool and check if the result should be treated as a final answer.
2424
@@ -50,7 +50,7 @@ def execute_tool_and_check_finality(
5050 fingerprint_obj = Fingerprint .from_dict (fingerprint_context )
5151 agent .set_fingerprint (fingerprint_obj )
5252 except Exception as e :
53- raise ValueError (f"Failed to set fingerprint: { e } " )
53+ raise ValueError (f"Failed to set fingerprint: { e } " ) from e
5454
5555 # Create tool usage instance
5656 tool_usage = ToolUsage (
@@ -65,7 +65,7 @@ def execute_tool_and_check_finality(
6565 # Parse tool calling
6666 tool_calling = tool_usage .parse_tool_calling (agent_action .text )
6767
68- if isinstance (tool_calling , ToolUsageErrorException ):
68+ if isinstance (tool_calling , ToolUsageError ):
6969 return ToolResult (tool_calling .message , False )
7070
7171 # Check if tool name matches
0 commit comments