mirror of
https://github.com/crewAIInc/crewAI.git
synced 2026-01-11 00:58:30 +00:00
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
This commit is contained in:
@@ -91,6 +91,12 @@ class CrewAgentParser:
|
|||||||
includes_answer = FINAL_ANSWER_ACTION in text
|
includes_answer = FINAL_ANSWER_ACTION in text
|
||||||
action_match = self._find_last_action_input_pair(cleaned_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()
|
final_answer = cleaned_text.split(FINAL_ANSWER_ACTION)[-1].strip()
|
||||||
# Check whether the final answer ends with triple backticks.
|
# Check whether the final answer ends with triple backticks.
|
||||||
if final_answer.endswith("```"):
|
if final_answer.endswith("```"):
|
||||||
|
|||||||
Reference in New Issue
Block a user