Skip to content

Conversation

@harihran-del
Copy link

@harihran-del harihran-del commented Feb 2, 2026

Description: Currently, when an Agent is reused for multiple tasks within a Crew, the agent_executor.messages history is not cleared. This causes context leakage where instructions or data from Task 1 persist into Task 2, leading to potential hallucinations and unnecessary token usage.

Changes:

Modified src/crewai/agent/core.py in _update_executor_parameters to clear the agent_executor.messages list before a new task begins.

Testing:

Verified with a reproduction script that checks the length of agent_executor.messages after consecutive tasks.

Confirmed memory resets to 0 (or baseline) instead of accumulating.


Note

Low Risk
Low risk because it is a small, localized change that only clears per-executor message state between task runs; the main risk is unintentionally removing any desired cross-task conversational continuity.

Overview
Prevents cross-task context leakage when reusing an Agent by clearing agent_executor.messages at the start of _update_executor_parameters before updating task/tool/prompt settings.

This keeps executor message history from accumulating across tasks, reducing unintended prompt carryover and excess token usage.

Written by Cursor Bugbot for commit 7ca68fa. This will update automatically on new commits. Configure here.

Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Bugbot Autofix is OFF. To automatically fix reported issues with Cloud Agents, enable Autofix in the Cursor dashboard.

This PR is being reviewed by Cursor Bugbot

Details

Your team is on the Bugbot Free tier. On this plan, Bugbot will review limited PRs each billing cycle for each member of your team.

To receive Bugbot reviews on all of your PRs, visit the Cursor dashboard to activate Pro and start your 14-day free trial.

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.

1 participant