From ae9907c8e73bbe37bf3be9c11d38975d9ed3d2ab Mon Sep 17 00:00:00 2001 From: Lucas Gomide Date: Thu, 17 Jul 2025 15:51:14 -0300 Subject: [PATCH] fix: prioritize Action over Final Answer to prevent tool bypassing - Force Action execution when both Action and Final Answer are present - Prevent agents from bypassing tool execution with premature answers --- src/crewai/agents/parser.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/crewai/agents/parser.py b/src/crewai/agents/parser.py index 33216b606..70342ddf4 100644 --- a/src/crewai/agents/parser.py +++ b/src/crewai/agents/parser.py @@ -91,6 +91,12 @@ class CrewAgentParser: includes_answer = FINAL_ANSWER_ACTION in text action_match = self._find_last_action_input_pair(cleaned_text) + # Prevent tool bypassing when both Action and Final Answer are present + # If the model returns both, we PRIORITIZE the action to force tool execution + if includes_answer and action_match: + return self._create_agent_action(thought, action_match, cleaned_text) + + elif includes_answer: final_answer = cleaned_text.split(FINAL_ANSWER_ACTION)[-1].strip() # Check whether the final answer ends with triple backticks. if final_answer.endswith("```"):