Files
crewAI/lib
Devin AI efb005afaf Fix agent output sanitization to prevent internal ReAct fields from leaking
Fixes #3873

This commit addresses a bug where internal ReAct-style fields like 'Thought:',
'Action:', 'Action Input:', and 'Observation:' were leaking into the final
agent output, particularly in hierarchical crews when delegated tasks failed
or when agents hit max iterations.

Changes:
- Added sanitize_react_output() utility function to strip internal ReAct fields
- Applied sanitization in handle_max_iterations_exceeded() when converting
  AgentAction to AgentFinish
- Applied sanitization in format_answer() exception handling to prevent leaks
  when LLM responses cannot be parsed
- Added comprehensive unit tests to verify the fix and prevent regressions
- Updated pyproject.toml to use pytest-vcr instead of pytest-recording to
  resolve plugin conflicts

The sanitization function removes lines starting with ReAct field markers
while preserving legitimate content, ensuring clean user-facing outputs.

Co-Authored-By: João <joao@crewai.com>
2025-11-10 11:32:48 +00:00
..