Files
crewAI/lib
Devin AI 4e0ee7d570 Fix task planner matching plans to wrong tasks (issue #3953)
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>
2025-11-19 16:03:03 +00:00
..