fix: keep only first line of parsed action so tool name matches#6176
fix: keep only first line of parsed action so tool name matches#6176Hiyaarora wants to merge 1 commit into
Conversation
The ReAct action regex uses re.DOTALL, so when a model emits explanatory text between 'Action:' and 'Action Input:', that text (including newlines) is captured into the action group. _clean_action only stripped outer whitespace, leaving a multi-line tool name like 'search\nI will look up...' that never matches a registered tool, so the tool call fails. Keep only the first line in _clean_action so the tool name still matches. Add regression tests for text between Action and Action Input.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthrough
ChangesMulti-line action text fix
Estimated code review effort🎯 2 (Simple) | ⏱️ ~5 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Summary
When a model emits explanatory text between
Action:andAction Input:, the parsed tool name ends up containing that extra text (and newlines), so it no longer matches any registered tool and the tool call fails.ACTION_INPUT_REGEXusesre.DOTALL, so the action group captures everything up toAction Input:— including newlines._clean_actiononly stripped outer whitespace, leaving a multi-line tool name.Reproduction
Expected:
'web_search'Actual:
"web_search\nI will search for information about France's population"→ never matches a registered tool.Fix
Keep only the first line in
_clean_action, so the tool name still matches even when the model adds stray text beforeAction Input:. One-line behavioral change; existing asterisk/whitespace cleaning is preserved.Tests
Added two regression tests in
test_crew_agent_parser.py:test_valid_action_parsing_with_text_between_action_and_action_input(through the publicparser.parse)test_clean_action_with_text_after_tool_nameI verified the fix against all existing parser cases plus the new one. Note: I was unable to run the full local suite in my environment (disk constraints during dependency install), so I'm relying on CI to run
lib/crewai/tests/— happy to adjust if anything there flags.Disclosure
This PR was prepared with AI assistance (Claude Code), reviewed by me. Please apply the
llm-generatedlabel per CONTRIBUTING.Summary by CodeRabbit