mirror of
https://github.com/crewAIInc/crewAI.git
synced 2026-01-23 15:18:14 +00:00
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>
This commit is contained in:
@@ -15,8 +15,8 @@ dev = [
|
||||
"pytest>=8.4.2",
|
||||
"pytest-asyncio>=1.2.0",
|
||||
"pytest-subprocess>=1.5.3",
|
||||
"vcrpy==7.0.0", # pinned, less versions break pytest-recording
|
||||
"pytest-recording>=0.13.4",
|
||||
"vcrpy==7.0.0",
|
||||
"pytest-vcr>=1.0.2",
|
||||
"pytest-randomly>=4.0.1",
|
||||
"pytest-timeout>=2.4.0",
|
||||
"pytest-xdist>=3.8.0",
|
||||
|
||||
Reference in New Issue
Block a user