Fix result_as_answer=True surfacing tool errors as final answer#5290
Open
Christian-Sidak wants to merge 2 commits intocrewAIInc:mainfrom
Open
Fix result_as_answer=True surfacing tool errors as final answer#5290Christian-Sidak wants to merge 2 commits intocrewAIInc:mainfrom
Christian-Sidak wants to merge 2 commits intocrewAIInc:mainfrom
Conversation
When multiple agents share the same LLM instance, each CrewAgentExecutor.__init__ was mutating the shared LLM stop attribute, causing stop words to accumulate across agents. This led to premature generation termination and race conditions in async execution. Instead of permanently mutating the shared LLM object, we now: 1. Compute effective stop words (original + executor-specific) locally 2. Apply them to the LLM only during invoke/ainvoke execution 3. Restore the original stop words in a finally block Fixes crewAIInc#5141
When a tool with result_as_answer=True raises an exception, the error output was being returned as the agent final answer instead of letting the agent reflect on the failure. This fix suppresses result_as_answer when the tool execution errored, across all execution paths. Fixes crewAIInc#5156
5498c03 to
e304bef
Compare
Author
|
Friendly bump -- let me know if anything needs changing. |
1 similar comment
Author
|
Friendly bump -- let me know if anything needs changing. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #5156
When a tool with
result_as_answer=Trueraises an exception, the error output was being returned as the agent's final answer instead of allowing the agent to reflect on the failure and retry.This fix suppresses
result_as_answerwhen the tool execution errored, across all execution paths:utilities/agent_utils.py--execute_single_native_tool_callnow checkserror_event_emittedbefore settingresult_as_answer=Trueagents/crew_agent_executor.py--_execute_single_native_tool_callnow passes the error flag through, and_append_tool_result_and_check_finalitychecks itexperimental/agent_executor.py--execute_native_toolnow checks the error flag before treating the result as finalutilities/tool_utils.py-- both sync and asyncexecute_tool_and_check_finalitynow comparetask.tools_errorsbefore/after executionTest plan
test_result_as_answer_not_used_when_tool_errorsto verify that a failing tool withresult_as_answer=Truedoes not produce a final answerresult_as_answertests continue to pass