feat: add debug logging when OutputParserError triggers agent retry #4247
+280
−0
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.
feat: add debug logging when OutputParserError triggers agent retry
Summary
Addresses issue #4246 by adding debug-level logging when
OutputParserErrortriggers an agent retry. Previously, whenformat_answer()raisedOutputParserError, the agent would silently retry with no visibility into what the LLM returned or why parsing failed.The new debug logging captures:
Logging is controlled via Python's standard logging module at DEBUG level, allowing users to enable it via environment variables or log configuration without code changes.
Review & Testing Checklist for Human
handle_output_parser_exception()directly. The changes tocrew_agent_executor.py(both sync and async loops) andlite_agent.pythat passraw_outputandagent_roleare not covered by integration tests. Consider manually triggering a parse failure to verify the full flow.Parse failed for agent 'RoleName': <error>followed by truncated raw output. Verify this matches what was expected in issue [Enhancement] Add debug logging when OutputParserError triggers agent retry #4246.DEBUGlogging enabled to verify the logs appear correctly._ainvoke_loop()method increw_agent_executor.pyhas the same changes as the sync path but isn't explicitly tested.Recommended Test Plan
logging.getLogger("crewai.utilities.agent_utils").setLevel(logging.DEBUG)Notes