fix: capture tool name/input before _handle_agent_action in ReAct loops

_handle_agent_action can convert AgentAction to AgentFinish (when
result_as_answer=True). Accessing .tool and .tool_input on AgentFinish
would raise AttributeError. Now we capture the values beforehand.

Co-Authored-By: João <joao@crewai.com>
This commit is contained in:
Devin AI
2026-03-03 03:36:08 +00:00
parent 52d36ccaf9
commit 420ed828b7

View File

@@ -416,6 +416,11 @@ class CrewAgentExecutor(CrewAgentExecutorMixin):
)
}
# Capture tool info before _handle_agent_action may
# convert the answer to AgentFinish (result_as_answer).
_tool_name = formatted_answer.tool
_tool_input = formatted_answer.tool_input
tool_result = execute_tool_and_check_finality(
agent_action=formatted_answer,
fingerprint_context=fingerprint_context,
@@ -435,7 +440,7 @@ class CrewAgentExecutor(CrewAgentExecutorMixin):
# Check for repetitive loop patterns
loop_result = self._record_and_check_loop(
formatted_answer.tool, formatted_answer.tool_input
_tool_name, _tool_input
)
if loop_result is not None:
formatted_answer = loop_result
@@ -1274,6 +1279,11 @@ class CrewAgentExecutor(CrewAgentExecutorMixin):
)
}
# Capture tool info before _handle_agent_action may
# convert the answer to AgentFinish (result_as_answer).
_tool_name = formatted_answer.tool
_tool_input = formatted_answer.tool_input
tool_result = await aexecute_tool_and_check_finality(
agent_action=formatted_answer,
fingerprint_context=fingerprint_context,
@@ -1293,7 +1303,7 @@ class CrewAgentExecutor(CrewAgentExecutorMixin):
# Check for repetitive loop patterns
loop_result = self._record_and_check_loop(
formatted_answer.tool, formatted_answer.tool_input
_tool_name, _tool_input
)
if loop_result is not None:
formatted_answer = loop_result