Skip to content

fix(reasoning): accept short-form READY keyword from model responses#6261

Open
s3ak6i-dev wants to merge 2 commits into
crewAIInc:mainfrom
s3ak6i-dev:fix/reasoning-plan-ready-detection
Open

fix(reasoning): accept short-form READY keyword from model responses#6261
s3ak6i-dev wants to merge 2 commits into
crewAIInc:mainfrom
s3ak6i-dev:fix/reasoning-plan-ready-detection

Conversation

@s3ak6i-dev

@s3ak6i-dev s3ak6i-dev commented Jun 20, 2026

Copy link
Copy Markdown

Prompt templates instruct models to conclude with "READY" or "NOT READY", but the detection logic only matched the legacy phrase "READY: I am ready to execute the task." -- so models following the current prompts always triggered a NOT READY result and looped indefinitely.

Adds AgentReasoning._is_ready() which accepts both the short keyword form and the legacy phrase, while correctly rejecting "NOT READY". Updates _parse_planning_response and both fallback branches in _call_with_function to use the new helper.

Note: pre-commit hooks were skipped locally due to a Windows path
incompatibility (.venv/bin/activate). ruff and mypy were run manually
and passed. CI will confirm on Linux.

Fixes #6204

Summary by CodeRabbit

  • New Features

    • Improved agent readiness detection to recognize multiple “READY” formats, including simplified markers and case-insensitive variants.
  • Bug Fixes

    • Prevents false positives by correctly treating responses containing “NOT READY” as not ready.
  • Tests

    • Added regression tests covering readiness detection (legacy and new formats, edge cases) and planning-response parsing outcomes.

Prompt templates instruct models to conclude with "READY" or "NOT READY",
but the detection logic only matched the legacy phrase
"READY: I am ready to execute the task." -- so models following the
current prompts always triggered a NOT READY result and looped indefinitely.

Adds AgentReasoning._is_ready() which accepts both the short keyword form
and the legacy phrase, while correctly rejecting "NOT READY". Updates
_parse_planning_response and both fallback branches in _call_with_function
to use the new helper.

Fixes crewAIInc#6204

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

@corridor-security corridor-security Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Summary: This PR updates agent reasoning readiness parsing to accept both short-form and legacy READY indicators in model responses, with tests covering READY and NOT READY cases. No exploitable security vulnerabilities were identified.

Risk: Low risk. The change affects internal model-response parsing and does not introduce a new public endpoint, authentication/authorization change, external integration, file/network access, or dependency/workflow supply-chain risk.

@coderabbitai

coderabbitai Bot commented Jun 20, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 5a31abe3-2e91-4e87-ae84-65ef93454507

📥 Commits

Reviewing files that changed from the base of the PR and between 4b74fa9 and ec8cf3a.

📒 Files selected for processing (2)
  • lib/crewai/src/crewai/utilities/reasoning_handler.py
  • lib/crewai/tests/agents/test_agent_reasoning.py
🚧 Files skipped from review as they are similar to previous changes (2)
  • lib/crewai/src/crewai/utilities/reasoning_handler.py
  • lib/crewai/tests/agents/test_agent_reasoning.py

📝 Walkthrough

Walkthrough

AgentReasoning readiness detection is centralized into a new _is_ready(response: str) -> bool static method that matches either the legacy full phrase or a bare "READY" marker while excluding "NOT READY". Both planning paths in _call_with_function and _parse_planning_response are updated to use this helper. Regression tests are added for _is_ready and _parse_planning_response.

Changes

AgentReasoning readiness detection

Layer / File(s) Summary
_is_ready helper and call-site wiring
lib/crewai/src/crewai/utilities/reasoning_handler.py
Adds re import for regex support. Introduces AgentReasoning._is_ready static method that upper-cases the response, returns False if "NOT READY" is present, and otherwise returns True if either the legacy "READY: I AM READY TO EXECUTE THE TASK." phrase or a standalone "READY" token is found. Updates both the function-calling return path and the fallback text-parsing return path in _call_with_function to call self._is_ready(...) instead of hard-coded legacy substring checks. Replaces the phrase check in _parse_planning_response with AgentReasoning._is_ready(response).
Unit tests for _is_ready and _parse_planning_response
lib/crewai/tests/agents/test_agent_reasoning.py
Adds TestIsReady with cases covering legacy full-phrase (case-insensitive), short-form uppercase and mixed-case "READY", standalone and inline "NOT READY", empty string, missing keyword, and substring-only matches. Adds TestParsePlanningResponse with cases verifying the default plan text and ready=False for empty input, correct ready boolean for short-form "READY"/"NOT READY", and ready=True for the legacy phrase.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 22.22% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: accepting the short-form READY keyword from model responses.
Linked Issues check ✅ Passed The PR directly addresses issue #6204 by implementing detection for the short-form READY keyword using regex word boundaries, fixing the indefinite loop problem.
Out of Scope Changes check ✅ Passed All changes are scoped to fixing the READY detection logic in reasoning handler and adding corresponding regression tests.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@s3ak6i-dev

Copy link
Copy Markdown
Author

Note: this PR was authored with AI assistance (Claude Code).

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
lib/crewai/tests/agents/test_agent_reasoning.py (1)

41-43: ⚡ Quick win

Add a regression test for READY-as-substring false positives.

Please add a case like assert not AgentReasoning._is_ready("I already need more info.") so marker detection stays boundary-based and doesn’t regress.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@lib/crewai/tests/agents/test_agent_reasoning.py` around lines 41 - 43, Add an
additional assertion to the test_no_keyword_returns_false method in the
AgentReasoning test class to check for a boundary-based false positive case.
Include a new assertion that verifies AgentReasoning._is_ready returns False
when the string contains "READY" as a substring within another word, such as in
"I already need more info", to ensure the marker detection stays boundary-based
and prevents substring matches from being incorrectly identified as the READY
keyword.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@lib/crewai/src/crewai/utilities/reasoning_handler.py`:
- Around line 592-594: The substring matching for "READY" in the return
statement is causing false positives by matching unrelated words like "ALREADY".
Replace the simple substring check `"READY" in upper` with marker-aware matching
that treats "READY" as a complete word boundary (such as using word boundary
markers like space or punctuation around it) to ensure it only matches the
standalone word "READY" and not as part of other words, while maintaining the
"NOT READY" exclusion logic.

---

Nitpick comments:
In `@lib/crewai/tests/agents/test_agent_reasoning.py`:
- Around line 41-43: Add an additional assertion to the
test_no_keyword_returns_false method in the AgentReasoning test class to check
for a boundary-based false positive case. Include a new assertion that verifies
AgentReasoning._is_ready returns False when the string contains "READY" as a
substring within another word, such as in "I already need more info", to ensure
the marker detection stays boundary-based and prevents substring matches from
being incorrectly identified as the READY keyword.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 1d30298e-0293-497e-929d-87fca88ba11b

📥 Commits

Reviewing files that changed from the base of the PR and between 9db2d44 and 4b74fa9.

📒 Files selected for processing (2)
  • lib/crewai/src/crewai/utilities/reasoning_handler.py
  • lib/crewai/tests/agents/test_agent_reasoning.py

Comment thread lib/crewai/src/crewai/utilities/reasoning_handler.py Outdated
Substring check "READY" in upper also matched words like "ALREADY" and
"UNREADY", causing agents to prematurely exit planning loops. Switch to
re.search(r"\bREADY\b") and short-circuit on NOT READY first.

Add two regression tests covering the substring false-positive cases.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Reasoning plan always detects "NOT READY" even though the model indicates "READY"

2 participants