Skip to content

fix: reset executor state between sequential task executions#4621

Open
Anandesh-Sharma wants to merge 1 commit intocrewAIInc:mainfrom
Anandesh-Sharma:fix/4389-executor-state-reset
Open

fix: reset executor state between sequential task executions#4621
Anandesh-Sharma wants to merge 1 commit intocrewAIInc:mainfrom
Anandesh-Sharma:fix/4389-executor-state-reset

Conversation

@Anandesh-Sharma
Copy link

Summary

  • Resets self.messages and self.iterations at the start of invoke() and ainvoke() in CrewAgentExecutor
  • When one agent handles multiple sequential tasks, the executor is reused, causing messages from Task 1 to leak into Task 2's LLM context
  • This also prevents premature max iterations limits from carrying over
  • Matches the behavior already implemented in the experimental AgentExecutor

Fixes #4389

Test plan

  • Create a Crew with one agent assigned to two sequential tasks
  • Verify Task 2's LLM context only contains messages relevant to Task 2
  • Verify iterations reset to 0 for each new task
  • Verify single-task execution still works correctly

🤖 Generated with Claude Code

When a CrewAgentExecutor is reused across sequential tasks, messages
and iterations from previous tasks leak into subsequent executions.
This causes Task 2 to see messages from Task 1 and may trigger the
max iterations limit prematurely.

Reset both `self.messages` and `self.iterations` at the beginning of
`invoke()` and `ainvoke()` to ensure clean state per execution, matching
the behavior of the experimental AgentExecutor.

Fixes crewAIInc#4389

Co-Authored-By: Claude Opus 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] CrewAgentExecutor does not reset messages and iterations between task executions

1 participant