Fix task planner matching plans to wrong tasks (issue #3953)#3954
Closed
devin-ai-integration[bot] wants to merge 2 commits into
Closed
Fix task planner matching plans to wrong tasks (issue #3953)#3954devin-ai-integration[bot] wants to merge 2 commits into
devin-ai-integration[bot] wants to merge 2 commits into
Conversation
The task planner was blindly zipping tasks with plans returned by the LLM, assuming they were in the same order. However, the LLM sometimes returns plans in the wrong order (e.g., starting with Task 21 instead of Task 1), causing plans to be attached to the wrong tasks. This fix: - Extracts the task number from each plan's task field using regex - Creates a mapping of task number to plan - Applies plans to tasks based on the correct task number match - Adds warning logs when task numbers can't be extracted or plans are missing Added comprehensive test that reproduces the bug by mocking an LLM response with plans in the wrong order and verifies the fix correctly matches plans to their corresponding tasks. Co-Authored-By: João <joao@crewai.com>
Contributor
Author
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
Contributor
Author
|
Closing due to inactivity for more than 7 days. Configure here. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Fixes issue #3953 where the task planner was attaching plans to the wrong tasks when the LLM returned them out of order.
The Problem: The original implementation used
zip()to blindly pair tasks with plans, assuming they were in the same order. However, LLMs sometimes return plans in unexpected order (e.g., starting with "Task Number 21" instead of "Task Number 1"), causing plan mismatches.The Solution:
taskfieldChanges:
Crew._handle_crew_planning()to use task number extraction instead of positional matchingReview & Testing Checklist for Human
planning=Trueand 5-10 tasks to verify the regex patternr"Task Number (\d+)"correctly matches actual LLM outputs from the planning agentTest Plan
planning=Truecrew.kickoff()and verify each task receives the correct plan in its description_handle_crew_planning()to log the plan_map and verify task numbers are extracted correctlyNotes
CrewPlanner._create_tasks_summary()Link to Devin run: https://app.devin.ai/sessions/c96705b2147b411682a3b3d6339b4a13
Requested by: João (joao@crewai.com)
Note
Maps LLM-generated plans to the correct tasks by extracting task numbers (regex) instead of relying on order; adds warnings and a unit test for out-of-order plans.
zip()pairing with task-number mapping inCrew._handle_crew_planning().r"Task Number (\d+)"from each plan’staskfield and buildplan_map.test_crew_planning_with_mismatched_task_orderverifying correct plan-task matching when the planner returns plans out of order and ensuring wrong plans aren’t attached to wrong tasks.Written by Cursor Bugbot for commit 9311689. This will update automatically on new commits. Configure here.